Skip to content

Commit

Permalink
Merge branch 'master' of github.com:miyagawa/Starman
Browse files Browse the repository at this point in the history
  • Loading branch information
miyagawa committed Mar 15, 2012
2 parents 652eca1 + f0ac5bd commit 7a795a1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Starman.pm
Expand Up @@ -141,6 +141,6 @@ it under the same terms as Perl itself.
=head1 SEE ALSO
L<Plack> L<Catalyst::Engine::HTTP::Prefork> L<Net::Server::Prefork>
L<Plack> L<Catalyst::Engine::HTTP::Prefork> L<Net::Server::PreFork>
=cut
2 changes: 1 addition & 1 deletion lib/Starman/Server.pm
Expand Up @@ -406,7 +406,7 @@ sub _prepare_env {

if ($chunk_len == 0) {
last DECHUNK;
} elsif (length $chunk_buffer < $chunk_len) {
} elsif (length $chunk_buffer < $chunk_len + 2) {
$chunk_buffer = $trailer . $chunk_buffer;
last;
}
Expand Down
52 changes: 52 additions & 0 deletions t/chunked_termination.t
@@ -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 7a795a1

Please sign in to comment.