# 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_* naming 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 think 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); }