-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test case for chunked transfer decoding
- Loading branch information
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |