Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Mason upload limit size

by Fletch (Bishop)
on Feb 13, 2004 at 03:24 UTC ( #328719=note: print w/replies, xml ) Need Help??

in reply to Mason upload limit size

Glancing through the XS source, it returns HTTP_REQUEST_ENTITY_TOO_LARGE which has a value of 413 (and thus is true for perl). What you want to do is make sure it's returning OK instead.

<%perl> my $apr = Apache::Request->instance( $r, POST_MAX => 1 ); my $status = $apr->parse(); if( $status != Apache::Constants::OK ) { print "Too big"; } else { print "Just right."; } </%perl>

Update: As a somewhat related aside, if you're using HTML::Mason::ApacheHandler the $r global should already be upgraded to an Apache::Request instance for you by default (or you can explicitly request this by passing args_method => "mod_perl", but that's the default setting; the other option is to set it to CGI to get a instance).

Another Update: Looking into what HTML::Mason::ApacheHandler does, it appears it already calls Apache::Request->instance() with no extra arguments. This might explain your problem (i.e. the instance is created and possibly already parsed before your size limitation is seen). If that's the case you might need to subclass HTML::Mason::ApacheHandler to override the prepare_request() method yourself.

package My::ApacheHandler; use base 'HTML::Mason::ApacheHandler'; sub prepare_request { my $self = shift; my $r = shift; Apache::Request->instance( $r, POST_MAX => 1 ); return $self->SUPER::prepare_request( $r, @_ ); } 1;

Replies are listed 'Best First'.
Re: Re: Mason upload limit size
by physi (Friar) on Feb 13, 2004 at 10:06 UTC
    Thanks Fletch for your explanation.
    Yes I use mod_perl and so I should might be use the last way you mentioned. But that will mean, I can't limit different upload forms to different upload size. Or I have to put each upload form into an own directory and use different My::ApacheHandler for each of them.
    Sounds to be to complicated :-)

    Maybe I use CGI for the upload stuff. This will also save me for memory problems, which mod_perl maybe will cause by uploading big files ...


    --the good, the bad and the physi--

      No, you can vary the limit but you just have to make your My::ApacheHandler a little bit fancier.

      package My::ApacheHandler; use base 'HTML::Mason::ApacheHandler'; sub prepare_request { my $self = shift; my $r = shift; my @args; ## <Location /foo> ## PerlSetVar MAH_POST_MAX 1024 ## </Location> ## <Location /bar> ## PerlSetVar MAH_POST_MAX none ## </Location> my $post_max = $r->dir_config( 'MAH_POST_MAX' ); unless( $post_max =~ /^none/ ) { push @args, POST_MAX => $post_max; } Apache::Request->instance( $r, @args ); return $self->SUPER::prepare_request( $r, @_ ); } 1;
        Just checked this out...

        works perfect!

        Thanks ++

        btw: maybe it's worth to implement this in Mason's src!?

        --the good, the bad and the physi--

        How can be this code adopted for Apache2? I'm using Apache2 together with Mason and session (MasonX::Apache2Handler as response handler and MasonX::Request::WithApache2Session as request class) and need to limit uploads too.

        Trying to use described solution I get in most cases 500 response (Internal server error). It seems $m to be undefined :-(

        When I tried to implement your code to do this, I get the following error: Can't locate object method "pnotes" via package "POST_MAX" (perhaps you forgot to load "POST_MAX"?)
        package MyApacheHandler; use base 'HTML::Mason::ApacheHandler'; sub prepare_request { my $self = shift; my $r = shift; my $post_max = 100; Apache::Request->instance( $r, POST_MAX => $post_max ); return $self->SUPER::prepare_request( $r, @_ ); } 1;
        In the autohandler
        <%init> use MyApacheHandler; my $apr = MyApacheHandler::prepare_request($r,POST_MAX => 1); </%init>
        Any idea why I get this error?

        Update: This is a newbie error and I solved it myself :)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://328719]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2023-12-10 10:20 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (39 votes). Check out past polls.