perl6-http-client icon indicating copy to clipboard operation
perl6-http-client copied to clipboard

Problem with chunked content

Open cognominal opened this issue 10 years ago • 1 comments

The following program called mine returns the following error :

Type check failed in binding $str; expected 'Str' but got 'Array' in sub unbase at src/gen/m-CORE.setting:6857 in block at lib/HTTP/Client/Response.pm6:113 in method dechunk at lib/HTTP/Client/Response.pm6:106 in method contents at lib/HTTP/Client/Response.pm6:140 in method content at lib/HTTP/Client/Response.pm6:146 in sub slurp at mine:9 in block at mine:15

use HTTP::Client; proto sub slurp(|) { * }

multi sub slurp($filename, :$bin = False, :$enc = 'utf8') { if $filename.index: '://' -> $i {

require HTTP::Client;

   my $client = HTTP::Client.new;
   my $response = $client.get($filename);
   return  $response.content if $response.success ;
   fail;
} 
$filename.IO.slurp(:$bin, :$enc);

} say slurp("http://paris.mongueurs.net");

For info, the page acceded with wget with the header printed

wget -S mongueurs.net --2014-06-16 11:48:03-- http://mongueurs.net/ Resolving mongueurs.net... 91.216.186.189 Connecting to mongueurs.net|91.216.186.189|:80... connected. HTTP request sent, awaiting response... HTTP/1.1 200 OK Server: Apache/1.3.42 (Unix) Last-Modified: Mon, 16 Jun 2014 09:45:05 GMT ETag: "1bc3f8b-3e95-539ebca1" Content-Type: text/html; charset=UTF-8 Transfer-Encoding: chunked Date: Mon, 16 Jun 2014 09:48:01 GMT X-Varnish: 768907453 Age: 0 Via: 1.1 varnish Connection: keep-alive Length: unspecified [text/html] Saving to: ‘index.html.2’

[  <=>                                  ] 16,021      70.7KB/s   in 0.2s   

2014-06-16 11:48:04 (70.7 KB/s) - ‘index.html.’ saved [16021]

cognominal avatar Jun 16 '14 09:06 cognominal

There is several problems with "Transfer-Encoding: chunked" management with this library:

  • method content() insert erroneous CRLF in result of chunked encoding
  • method dechunk() erase @!content impeding to get content a second time
  • if there is CRLF in the chunked content itself we're screwed
  • working with Str and chars() method is a recipe for more subtle and complex error in certain cases

My opinion is that as chunked Transfer-Encoding is a MUST in RFC7230 (A recipient MUST be able to parse the chunked transfer coding) and is really used in the Internet, HTTP::Client not suitable for use anymore.

I would like to modify the README to add a message prescribing use of HTTP::UserAgent instead.

avalenn avatar Mar 27 '18 11:03 avalenn