Skip to content

Commit

Permalink
add a Trailer header exception, add a big header test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdoe committed Jul 7, 2014
1 parent 5b9d203 commit 2c0715b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/Hijk.pm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ sub read_http_message {
my ($key, $value) = split /: /, $_, 2;
$header->{$key} = $value;
}

if ($header->{'Trailer'}) {
# http://tools.ietf.org/html/rfc2616#section-14.40
# for now just die, so we dont leave something in the cached socket
die 'Hijk does not support Trailer header at the moment';
}
if ($header->{'Transfer-Encoding'} && $header->{'Transfer-Encoding'} eq 'chunked') {
# if there is chunked encoding we have to ignore content lenght even if we have it
return ($proto, $status_code, read_chunked_body($body, $fd, $read_timeout), $header);
Expand Down
40 changes: 40 additions & 0 deletions t/chunked-trailer.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env perl
use strict;
use Test::More;
use File::Temp ();
use File::Temp qw/ :seekable /;
use Hijk;
use Test::Exception;

my $fh = File::Temp->new();
my $fd = do {
local $/ = undef;
my $data = "4\r\nWiki\r\n5\r\npedia\r\ne\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n";

my $msg = join(
"\x0d\x0a",
'HTTP/1.1 200 OK',
'Date: Sat, 23 Nov 2013 23:10:28 GMT',
'Last-Modified: Sat, 26 Oct 2013 19:41:47 GMT',
'ETag: "4b9d0211dd8a2819866bccff777af225"',
'Content-Type: text/html',
'Server: Example',
'Transfer-Encoding: chunked',
'Trailer: Date',
'non-sence: ' . 'a' x 20000,
'',
$data,
'Date: Sat, 23 Nov 2013 23:10:28 GMT',
''
);
print $fh $msg;
$fh->flush;
$fh->seek(0, 0);
fileno($fh);
};

throws_ok {
my ($proto, $status, $body, $head) = Hijk::read_http_message($fd);
} qr /trailer/i;

done_testing;
4 changes: 3 additions & 1 deletion t/chunked.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ my $fd = do {
'Content-Type: text/html',
'Server: Example',
'Transfer-Encoding: chunked',
'non-sence: ' . 'a' x 20000,
'',
$data
);
Expand All @@ -41,6 +42,7 @@ is_deeply $head, {
"ETag" => '"4b9d0211dd8a2819866bccff777af225"',
"Content-Type" => "text/html",
"Server" => "Example",
'non-sence' => 'a' x 20000,
"Transfer-Encoding" => "chunked",
};

Expand All @@ -52,4 +54,4 @@ throws_ok {
my ($proto, $status, $body, $head) = Hijk::read_http_message($fd);
} qr /0 bytes/i;

done_testing;
done_testing;

0 comments on commit 2c0715b

Please sign in to comment.