Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added test case for chunked transfer decoding

  • Loading branch information...
commit c65b3844a0e46054038df9c17acb8f58ae6fa345 1 parent be21c6e
@cosimo authored
Showing with 72 additions and 0 deletions.
  1. +72 −0 t/chunked-transfers.t
View
72 t/chunked-transfers.t
@@ -0,0 +1,72 @@
+use v6;
+use Test;
+use LWP::Simple;
+
+my $lwp = LWP::Simple.new;
+ok($lwp, 'Object create');
+
+#
+# Test that not chunked pages are interpreted correctly
+#
+
+my $testcase-no-chunked =
+q<HTTP/1.1 200 OK
+Server: random/3.14
+Content-type: text/plain
+
+3c
+This response shouldn't be interpreted as chunked,
+since there is no "Transfer-Encoding: chunked" header
+>;
+
+my ($status, $headers, $content) = $lwp.parse_response($testcase-no-chunked);
+is($status, q<HTTP/1.1 200 OK>, 'Status parsed correctly');
+
+# Only way to dereference I have found
+my %headers = $headers;
+is(%headers<Server>, 'random/3.14', 'Server header parsed correctly');
+is(%headers<Content-type>, 'text/plain', 'Content-type header parsed correctly');
+ok(! %headers.exists('Transfer-Encoding'), 'Transfer-Encoding header not found');
+
+my $content_str = $content.join('\n');
+ok(
+ $content_str && $content_str.match('3c'),
+ 'Content contains fake chunked transfer markers'
+);
+
+#
+# Test that chunked pages are interpreted correctly
+#
+
+my $testcase-chunked =
+q<HTTP/1.0 200 OK
+Server: Apache/2.2.9
+Transfer-Encoding: Chunked
+Content-type: text/plain
+
+0f
+15 characters
+10
+another 16 here
+0
+
+>;
+
+($status, $headers, $content) = $lwp.parse_response($testcase-chunked);
+is($status, q<HTTP/1.0 200 OK>, 'Status parsed correctly');
+
+# Only way to dereference I have found
+%headers = $headers;
+is(%headers<Server>, 'Apache/2.2.9', 'Server header parsed correctly');
+is(%headers<Content-type>, 'text/plain', 'Content-type header parsed correctly');
+
+# rakudo: $str ~~ m:i// NIY
+ok(%headers<Transfer-Encoding> ~~ m/:i chunked/, 'Transfer-Encoding found');
+
+$content_str = $content.join('\n');
+ok(
+ $content_str && ! $content_str.match('0f'),
+ 'Content should not contain chunked transfer markers'
+);
+
+done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.