[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [mp2] aborting a file upload


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;
} 


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.