You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Issac Goldstand <ma...@beamartyr.net> on 2007/03/09 08:53:23 UTC

Re: [mp2] aborting a file upload

I'm not positive, but I think it's dangerous as it can screw up
pipelined requests - that's why discard_request_body exists.  I've cc-ed
dev@httpd as all the smart HTTP people hang out there :-)  and maybe one
of them can either confirm or correct that statement.

  Issac

Matt Williamson wrote:
> I wrote a filter which I think does the trick. It seems to work. In the
> filter I send end of stream (eos) if the content length is too large,
> otherwise just pass the data along. The filter is registered as a
> PerlInputFilterHandler, which according to the docs only gets called on
> the body, not the headers.
> 
> Since I am new to mod_perl, could anyone comment on whether this is a
> dangerous thing to do?
> 
> Code below 
> 
> Matt
> 
> use base qw(Apache2::Filter);
> 
> use Apache2::Const -compile => qw(OK :log);
> use APR::Const    -compile => qw(SUCCESS);
> use Apache2::RequestRec ();
> use Apache2::Log ();
> 
> use constant BUFF_LEN => 4092;
> 
> use constant CONTENT_LIMIT => 104857600;
> 
> sub handler : FilterRequestHandler {
>     my $f = shift;
>     # get the request.
>     my $r = $f->r;
>     my $contentLength = $r->headers_in->{'Content-Length'};
>     if ($contentLength > CONTENT_LIMIT) {
> 	# send an end of stream
> 	$f->seen_eos(1);
>     } else {
> 	while ($f->read(my $buffer, BUFF_LEN)) {
> 	    $f->print($buffer);
> 	}
>     }
> 
>     Apache2::Const::OK;
> } 
>