Skip to content

Instantly share code, notes, and snippets.

@miyagawa
Created May 5, 2011 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miyagawa/957749 to your computer and use it in GitHub Desktop.
Save miyagawa/957749 to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojo/Server/PSGI.pm b/lib/Mojo/Server/PSGI.pm
index aa9b09c..1740d6c 100644
--- a/lib/Mojo/Server/PSGI.pm
+++ b/lib/Mojo/Server/PSGI.pm
@@ -21,10 +21,14 @@ sub run {
$tx->local_port($env->{SERVER_PORT});
# Request body
+ my $cl = $env->{CONTENT_LENGTH};
while (!$req->is_done) {
- my $read = $env->{'psgi.input'}->read(my $buffer, CHUNK_SIZE, 0);
+ my $chunk = ($cl && $cl < CHUNK_SIZE) ? $cl : CHUNK_SIZE;
+ my $read = $env->{'psgi.input'}->read(my $buffer, $chunk, 0);
last unless $read;
$req->parse($buffer);
+ $cl -= $read;
+ last if $cl <= 0;
}
# Handle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment