Skip to content

Commit

Permalink
Unit test to verify dechunking with hand crafted package borders
Browse files Browse the repository at this point in the history
  • Loading branch information
pmakholm committed Mar 9, 2012
1 parent d2a5d15 commit d678aba
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions t/chunked_termination.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use strict;

use Test::More;

{
package Starman::Server;

# Override the sysread method enabling it to read a stream of packages
# from an arrayref instead of an file handle:
use subs 'sysread';

*Starman::Server::sysread = sub {
if (ref $_[0] eq "ARRAY") {
die "EWOULDBLOCK\n" unless @{ $_[0] };

$_[1] = shift @{ $_[0] };
return length $_[1];
}

return CORE::sysread($_[0], $_[1], $_[2]);
};

}

use Starman::Server;

my $server = {
server => {
client => [
"3\015\012foo\015\012", # Full chunk
"3\015\012bar", # Chunk missing terminating HTTP newline
"\015\012", # ... and then the termination
"0\015\012", # Empty chunk to mark end of stream
],
}
};

my $env = {
HTTP_TRANSFER_ENCODING => 'chunked',
};

my $blocked;
eval {
Starman::Server::_prepare_env( $server, $env );
1;
} or do {
$blocked = 1 if $@ =~ /^EWOULDBLOCK$/;
};

ok( !$blocked, "Reading chunked encoding does not block on well-placed package borders" );

done_testing;

0 comments on commit d678aba

Please sign in to comment.