Permalink
Browse files

Added more test cases for the trailing '0's

  • Loading branch information...
1 parent ea70ca9 commit e60e4573ea5326a59db8295321a719fec99c8c9d @cosimo committed Jul 11, 2010
Showing with 57 additions and 7 deletions.
  1. +57 −7 t/chunked-transfers.t
View
64 t/chunked-transfers.t
@@ -44,10 +44,12 @@ Server: Apache/2.2.9
Transfer-Encoding: Chunked
Content-type: text/plain
+0d
+13 characters
0f
-15 characters
-10
-another 16 here
+another 15 here
+0
+
0
>;
@@ -64,9 +66,57 @@ is(%headers<Content-type>, 'text/plain', 'Content-type header parsed correctly')
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'
-);
+#diag('Content: ' ~ $content_str);
+
+ok($content_str, 'Content actually contains something');
+is($content_str.chars, 30, 'Content length (+CRLF) decoded correctly');
+ok(! $content_str.match('0d'), 'No chunked transfer markers');
+ok(! $content_str.match('0f'), 'No chunked transfer markers');
+ok(! $content_str.match('0'), 'No remaining chunked transfer markers at the end');
+ok($content_str.match('13 characters'), 'Actual content is there');
+ok($content_str.match('another 15 here'), 'Actual content is there');
+
+
+# Slightly different, with trailing garbage,
+# like 'www.rakudo.org' is sending
+$testcase-chunked =
+q<HTTP/1.0 200 OK
+Server: Apache/2.2.9
+Transfer-Encoding: Chunked
+Content-type: text/plain
+
+0d
+13 characters
+0f
+another 15 here
+0
+
+
+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');
+diag('Content (0 0): ' ~ $content_str);
+
+ok($content_str, 'Content actually contains something');
+is($content_str.chars, 30, 'Content length (+CRLF) decoded correctly');
+ok(! $content_str.match('0d'), 'No chunked transfer markers');
+ok(! $content_str.match('0f'), 'No chunked transfer markers');
+ok(! $content_str.match('0'), 'No remaining chunked transfer markers at the end');
+ok($content_str.match('13 characters'), 'Actual content is there');
+ok($content_str.match('another 15 here'), 'Actual content is there');
done_testing;

0 comments on commit e60e457

Please sign in to comment.