Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^4: Does CGI::Application expose a HTTP::Request object?

by isync (Hermit)
on Aug 11, 2010 at 11:34 UTC ( #854331=note: print w/replies, xml ) Need Help??

in reply to Re^3: Does CGI::Application expose a HTTP::Request object?
in thread Does CGI::Application expose a HTTP::Request object?

1. Error on a first pass: "Can't call method "clone" on unblessed reference at /usr/share/perl5/HTTP/ line 32."

2. Shouldn't the %ENV variable names be mapped to the a-bit-different HTTP Header names?

3. And we are passing a hashref to the HTTP::Request constructor, but it expects an arrayref (solved via this node).

Changed code:
my %env_to_httpheader = ( 'HTTP_USER_AGENT' => 'User-Agent', 'HTTP_HOST' => 'Host', 'HTTP_TE' => 'Accept-Encoding', 'CONTENT_LENGTH' => 'Content-Length', # from here on blurry from memory: (and probably more to inclu +de as well..) 'CONTENT_ENCODING' => 'Content-Encoding', 'CONTENT_TYPE' => 'Content-Type', ); my $headers; foreach my $key (keys %env_to_httpheader) { if (exists $ENV{$key}) { # $headers->{ $env_to_httpheader{$key} } = $ENV{$key}; # "The optional $header argument should be a reference + to an HTTP::Headers object or a plain array reference of key/value p +airs." push(@{ $headers }, $env_to_httpheader{$key}); push(@{ $headers }, $ENV{$key}); } }

Result: After changing this, it works!

Any leftovers, hints, tweaks for this piece of code before I move it to production code? For example, a module for the ENV to HTTP Header translation, or similar improvements?

2c: A lengthy hack, isn't it? Just to get a HTTP::Response out of Once more, I dislike this

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://854331]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2017-11-18 02:57 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (277 votes). Check out past polls.