From: Tomas Doran Date: Tue, 1 Dec 2009 02:16:08 +0000 (+0000) Subject: Fix bug in Catalyst::Engine which could cause it to all go wrong if read returned... X-Git-Tag: 5.80015~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=ea72fece19fee2a788a7e9cab6076392fdd674a0 Fix bug in Catalyst::Engine which could cause it to all go wrong if read returned '0' as per thread on mailing list re 'Wrong Content-Length value' and clarify docs about read and read_chunk methods in Catalyst::Engine --- diff --git a/Changes b/Changes index a2ff652..aa1c453 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,13 @@ # This file documents the revision history for Perl extension Catalyst. + Bug fixes: + - Fix bug in Catalyst::Engine which would cause a request parsing to end + prematurely in the hypothetical case where calling $engine->read returned + the single character '0'. + + Documentation: + - Improved documentation on read and read_chunk methods in Catalyst::Engine. + 5.80014_02 2009-12-01 00:55:23 Bug fixes: - Fix reporting the wrong Content-Length if the response body is an diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 443975e..8936fab 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -327,7 +327,8 @@ sub prepare_body { if exists $appclass->config->{uploadtmp}; } - while ( my $buffer = $self->read($c) ) { + # Check for definedness as you could read '0' + while ( defined ( my $buffer = $self->read($c) ) ) { $c->prepare_body_chunk($buffer); } @@ -566,6 +567,10 @@ sub prepare_write { } =head2 $self->read($c, [$maxlength]) +Reads from the input stream by calling C<< $self->read_chunk >>. + +Maintains the read_length and read_position counters as data is read. + =cut sub read { @@ -583,6 +588,11 @@ sub read { my $readlen = ( $remaining > $maxlength ) ? $maxlength : $remaining; my $rc = $self->read_chunk( $c, my $buffer, $readlen ); if ( defined $rc ) { + if (0 == $rc) { # Nothing more to read even though Content-Length + # said there should be. FIXME - Warn in the log here? + $self->finalize_read; + return; + } $self->read_position( $self->read_position + $rc ); return $buffer; } @@ -595,7 +605,8 @@ sub read { =head2 $self->read_chunk($c, $buffer, $length) Each engine implements read_chunk as its preferred way of reading a chunk -of data. +of data. Returns the number of bytes read. A return of 0 indicates that +there is no more data to be read. =cut