Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Custom error handling for oversized CGI request entities

by rob_au (Abbot)
on Jan 19, 2002 at 19:40 UTC ( #140078=snippet: print w/replies, xml ) Need Help??
Description: As discussed by Ovid at Preventing DOS attacks with, one of the key elements of all code employing CGI is the definition of $CGI::POST_MAX, thereby limiting the maximum accepted size of the submitted request entity. If this value, defined in bytes, is exceeded by the HTTP request, the result is the generation of a request entity too large error upon initiation of the CGI object that is returned to the HTTP client.

In a reply to my post here, Hero Zzyzzx asked how a more custom error handling response for over-sized requests could be incorporated into code - The result, with some liberties taken from the CGI module, is the code below:

#!/usr/bin/perl -Tw

use CGI;
use strict;

    my $POST_MAX = 512 * 1024;

    my $content_length = defined $ENV{'CONTENT_LENGTH'} ? $ENV{'CONTEN
+T_LENGTH'} : 0;
    if ( ($POST_MAX > 0) && ($content_length > $POST_MAX) ) {
        #   custom request entity too large error handling

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://140078]
[Lady_Aleena]: Discipulus, then that is a problem. I wanted to find total seconds of my entire .mp3 collection to do some math on it to see how many days of continuous music i have.
[LanX]: darn. .. I wanted to see Marine and Melonchon go to next round, just for fun xD
[Discipulus]: LA use Perl: traversing a dir tree is simple; foreach file mp3 $sec+= use Mp3::Info
[Lady_Aleena]: Discipulus, I was able to get the sum of the seconds on the command line using awk. Then I ran the result through a perl script and got the result. It came bach with 4 days, 9 hours, 56 minutes, 43 seconds.
[Lady_Aleena]: s/bach/back/;
[Discipulus]: gired anyway is the intermediate state between hired and fired (and vice versa;)
[Lady_Aleena]: Discipuluis, I don't know if I want to fight with File::Find. File::Find and I are not friends.
[Discipulus]: 4 day Bach is too muche even for me
[Discipulus]: LA you know who is paco?
[Lady_Aleena]: Disc, nope.

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2017-04-23 20:32 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (432 votes). Check out past polls.