Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: CGI upload limit

by valdez (Monsignor)
on Sep 14, 2002 at 11:19 UTC ( [id://197844]=note: print w/replies, xml ) Need Help??


in reply to CGI upload limit

Nice question, Ryszard.

I would subclass CGI::Application and reimplement the query method:

sub query { my $self = shift; my ($query) = @_; # We're only allowed to set a new query object if one does not yet e +xist! unless (exists($self->{__QUERY_OBJ})) { my $new_query_obj; # If data is provided, set it! Otherwise, create a new one. if (defined($query) && $query->isa('CGI')) { $new_query_obj = $query; } else { $CGI::POST_MAX=1024 * 100; # max 100K posts $new_query_obj = CGI->new(); } $self->{__QUERY_OBJ} = $new_query_obj; } return $self->{__QUERY_OBJ}; }

Beware, the code isn't tested. The new method could also use a parameter passed during start up:

my $webapp = App->new( TMPL_PATH => 'App/', PARAMS => { 'max_upload_size' => 100 } );

Then you could check this parameter and act accordingly inside your reimplemented method. Another solution could be creating a new CGI object (with POST_MAX set properly) and passing it to application init; C::A will recognize the object and use it; here is an excerpt from the man page:

QUERY - This optional parameter allows you to specify an already-created CGI.pm query object. Under normal use, CGI::Application will instantiate its own CGI.pm query object. Under certain conditions, it might be useful to be able to use one which has already been created.

Hope this helps. Ciao, Valerio

Replies are listed 'Best First'.
Re: Re: CGI upload limit
by samtregar (Abbot) on Sep 15, 2002 at 07:28 UTC
    That's not really a good way to do it. What happens when a new version of CGI::Application comes out that makes a change in query()? The code above will break. Instead, call the real query() to do the work using SUPER:

    package CGI::Application::POST_MAX; use base 'CGI::Application'; sub query { my $self = shift; if (not exists $self->{__POST_MAX_SET__}) { $CGI::POST_MAX=1024 * 100; # max 100K posts $self->{__POST_MAX_SET__} = 1; } return $self->SUPER::query(@_); } 1;

    Of course, this still isn't 100% future-proof since it will break if a future version of CGI::Application uses the hash key "__POST_MAX_SET__" but I'd consider that an acceptable risk.

    But is this even necessary? Can't you just put this at the top of your CGI::Application class:

    BEGIN { $CGI::POST_MAX = 1020 * 100; }

    -sam

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-19 02:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found