X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FRequest.pm;h=1f7465c40cb997e293d073ca8ae4af2498959f43;hp=b712e479ad4cf00c658d90618f14384da5650d5a;hb=f083854e255c33d3e82befa09152284127d426c1;hpb=87f504360777193d96945014faa1d058224fcb0e diff --git a/lib/Catalyst/Request.pm b/lib/Catalyst/Request.pm index b712e47..1f7465c 100644 --- a/lib/Catalyst/Request.pm +++ b/lib/Catalyst/Request.pm @@ -50,10 +50,38 @@ has headers => ( has _context => ( is => 'rw', weak_ref => 1, - handles => ['read'], # XXX FIXME! clearer => '_clear_context', ); +# Amount of data to read from input on each pass +our $CHUNKSIZE = 64 * 1024; + +sub read { + my ($self, $maxlength) = @_; + my $remaining = $self->_read_length - $self->_read_position; + $maxlength ||= $CHUNKSIZE; + + # Are we done reading? + if ( $remaining <= 0 ) { + return; + } + + my $readlen = ( $remaining > $maxlength ) ? $maxlength : $remaining; + my $rc = $self->read_chunk( my $buffer, $readlen ); + if ( defined $rc ) { + if (0 == $rc) { # Nothing more to read even though Content-Length + # said there should be. + return; + } + $self->_read_position( $self->_read_position + $rc ); + return $buffer; + } + else { + Catalyst::Exception->throw( + message => "Unknown error reading input: $!" ); + } +} + sub read_chunk { my $self = shift; return $self->env->{'psgi.input'}->read(@_);