views:

117

answers:

2

In an attempt to resolve the issue I posted in this question:

Is it possible to send POST parameters to a CGI script using a system() call?

So far the only successful resolution to the problem is to trick the environment to think the request was a GET. I do this by converting the POST parameters to a query string, saving that string in the default environment variable, then changing the environment variable that tells the server what method this request is using to GET.

$ENV{'QUERY_STRING'} = $long_parameter_string . '&' . $ENV{'QUERY_STRING'};
$ENV{'REQUEST_METHOD'} = 'GET';

system {$perl_exec} $cgi_script;

I'm essentially tricking the CGI module to read from the QUERY_STRING environment variable instead of from STDIN, which it would attempt to read POST requests from.

This method seems to work so far, but I'm worried about unintended repercussions.

My question is, do you see any potential problems with this?

+1  A: 

You'll hit problems with larger submissions and file-uploads as the size limit for a GET is much smaller than a POST. If you're talking about predictably small amounts of data, you should be alright.

Sohnee
Well, the original problem centers around fairly large requests. However, I assumed that the limitations to the size of GET were mostly a product of the limit of a URL in most browsers. I don't figure Perl's CGI module nor the Linux environment variable offers any serious size limitations seeing it's running on a 64-bit machine.As far as file uploads go, the CGI module has already had a chance to handle the file and the temporary location should be all that left in the parameters. Please correct me if I'm wrong. I'm in the process of testing this now.
James van Dyke
Quite right - the limit is a URL length limit.
Sohnee
Chosen for best answer so far since it's the only one that defines a possible problem, which was the point of the question.
James van Dyke
+2  A: 

POST and GET mean entirely different things, and you shouldn't be "testing" anything that way.

Instead, you should do a real POST to the intended URL by using Perl's LWP.

use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = LWP::UserAgent->new;

my $req = POST 'http://www.perl.com/cgi-bin/BugGlimpse',
              [ param1 => 'arbitrarily long blob', param2 => 'whatever' ];

print $ua->request($req)->as_string;
Jonathan Feinberg
Please see my original problem there's a link for above. There are two reasons I'm not doing this, though. One, I'm using mod_rewrite to redirect all requests to the file that ultimately executes the intended CGI script. Two, I could put a special parameter or something in the request you suggested to make sure mod_rewrite is bypassed, but that would ultimately lead to more request time than I'm comfortable with.
James van Dyke
Your comment is a non sequitur. mod_rewrite has nothing to do with anything that pertains to HTTP method.
Jonathan Feinberg
No, but it pertains to my original problem and the reason I'm handling the request this way in the first place.
James van Dyke
Thanks for the input Jonathan. This is probably the correct way of handling this situation for most people.
James van Dyke