Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #18 from ronaldxs/master

Two small fixes.
  • Loading branch information...
commit 40da36d3c768593e101e7e8933e8d4d7e0ba3dff 2 parents 79944c6 + 9bfeb2d
@cosimo authored
View
2  README
@@ -22,5 +22,3 @@ Current status
As of 2011-04-22, runs with all recent rakudo builds.
It correctly follows redirects, but no infinite redirects
detection yet.
-
-A known problem is that it corrupts binary files downloads.
View
24 lib/LWP/Simple.pm
@@ -17,6 +17,7 @@ our $.class_default_encoding = 'utf-8';
# these were intended to be constant but that hit pre-compilation issue
my Buf $crlf = Buf.new(13, 10);
my Buf $http_header_end_marker = Buf.new(13, 10, 13, 10);
+my Int constant $default_stream_read_len = 2 * 1024;
method base64encode ($user, $pass) {
my MIME::Base64 $mime .= new();
@@ -194,19 +195,11 @@ method make_request (
$sock.send($req_str);
- my Buf $resp = $sock.read(2 * 1024);
+ my Buf $resp = $sock.read($default_stream_read_len);
my ($status, $resp_headers, $resp_content) = self.parse_response($resp);
- if ( $resp_headers<Content-Length> &&
- $resp_content.bytes < $resp_headers<Content-Length>
- ) {
- $resp_content ~= $sock.read(
- $resp_headers<Content-Length> - $resp_content.bytes
- );
- }
-
if (($resp_headers<Transfer-Encoding> || '') eq 'chunked') {
my Bool $is_last_chunk;
my Buf $resp_content_chunk;
@@ -222,6 +215,19 @@ method make_request (
$resp_content ~= $resp_content_chunk;
}
}
+ elsif ( $resp_headers<Content-Length> &&
+ $resp_content.bytes < $resp_headers<Content-Length>
+ ) {
+ $resp_content ~= $sock.read(
+ $resp_headers<Content-Length> - $resp_content.bytes
+ );
+ }
+ else { # a bit hacky for now but should be ok
+ while ($resp.bytes > 0) {
+ $resp = $sock.read($default_stream_read_len);
+ $resp_content ~= $resp;
+ }
+ }
$sock.close();
View
16 t/get-unsized.t
@@ -0,0 +1,16 @@
+use v6;
+use Test;
+
+use LWP::Simple;
+
+# this page is, for now, delivered by a server that does not provide
+# a content length or do chunking
+my $html = LWP::Simple.get('http://www.rosettacode.org/wiki/Rosetta_Code');
+
+ok(
+ $html.match('About Rosetta Code') &&
+ $html.match('</html>') && $html.chars > 12_000,
+ 'make sure we pulled whole document without, we believe, sizing from server'
+);
+
+done;
View
3  t/get-w3-latin1-utf8.t
@@ -5,14 +5,13 @@ use LWP::Simple;
my $html = LWP::Simple.get('http://www.w3.org/2006/11/mwbp-tests/test-encoding-8.html');
-my $find_char = Buf.new(0xE9).decode('iso-8859-1');
+my $find_char = chr(233); # small e with acute
ok(
$html.match('</html>') && $html.match($find_char),
'Got latin-1 page'
);
$html = LWP::Simple.get('http://www.w3.org/2006/11/mwbp-tests/test-encoding-3.html');
-$find_char = Buf.new(0xC3, 0xA9).decode('utf-8');
ok(
$html.match('</html>') && $html.match($find_char),
'Got utf-8 page'

0 comments on commit 40da36d

Please sign in to comment.
Something went wrong with that request. Please try again.