in reply to Does CGI::Application expose a HTTP::Request object?
Update: The PUTDATA param being available might depend on your version of CGI.pm, or use a recent CGI::Simple, which worked for me.# build a HTTP::Request Object from what CGI.pm provides us with # see http://www.perlmonks.org/?node_id=854073 sub request_from_cgi { my $self = shift; my $q = $self->query; my $uri = $q->url; my $method = uc $q->request_method; my %env_to_httpheader = ( # hash of ENV keys which do not follow the HTTP_* nami +ng convention 'HTTP_TE' => 'Accept-Encoding', 'CONTENT_LENGTH' => 'Content-Length', # from here on blurry from memory: (and probably more +to include as well..), now commented out, see why below: # 'CONTENT_ENCODING' => 'Content-Encoding', + # I think there is only Accept-Encoding on requests # 'CONTENT_TYPE' => 'Content-Type', # I th +ink the content-type equivalent on the req side is Accept ); my $headers; foreach my $key (keys %ENV) { if($key =~ /^HTTP_(.*)$/ && !exists($env_to_httpheader +{$key})){ push(@{ $headers }, lc($1)); push(@{ $headers }, $ENV{$key}); }elsif(exists($env_to_httpheader{$key})){ push(@{ $headers }, $env_to_httpheader{$key}); push(@{ $headers }, $ENV{$key}); } } my $content = undef; if($method eq 'POST'){ $content = $q->param('POSTDATA'); }elsif($method eq 'PUT'){ $content = $q->param('PUTDATA'); } if(!defined $content){ my $len = $ENV{CONTENT_LENGTH} || 0; read STDIN, $content, $len; } return HTTP::Request->new( $method,$uri,$headers,$content); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Does CGI::Application expose a HTTP::Request object?
by isync (Hermit) on Aug 11, 2010 at 21:26 UTC | |
by isync (Hermit) on Aug 12, 2010 at 11:36 UTC |