I've reworked the code again, now making it a bit more clever on the mapping %ENV to HTTP::Headers: (comments welcome)
# 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); }
Update: The PUTDATA param being available might depend on your version of CGI.pm, or use a recent CGI::Simple, which worked for me.

In reply to Re: Does CGI::Application expose a HTTP::Request object? by isync
in thread Does CGI::Application expose a HTTP::Request object? by isync

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.