jacques has asked for the wisdom of the Perl Monks concerning the following question:
I can easily show the request headers from printing the server environment variables in the HTML, but it is the response headers that ellude me.
I looked at HTTP::Response. But to use HTTP::Response, I would have to initiate a new request. If I make a fresh request in the module and capture the response, then that response would be different from the one involving the HTML page.
Note: any code would be in my module and not in the CGI script. Don't try to solve this in the CGI script (the caller's namespace). For example:
I hope the code makes my question clearer.Package My::Module; require Exporter; @My::Module::ISA = qw(Exporter); @My::Module::EXPORT = qw(the-function); sub the-function { print "Content-type: text/html\n\n"; print <<HTML; Here are the HTTP REQUEST headers: <p> HTTP Request: $ENV{'REQUEST_METHOD'} $0 $ENV{'SERVER_PROTOCOL'} <br> Host: $ENV{'HTTP_HOST'} <br> User-Agent: $ENV{'HTTP_USER_AGENT'} <br> Accept: $ENV{'HTTP_ACCEPT_ENCODING'} <br> Accept-Language: $ENV{'HTTP_ACCEPT_LANGUAGE'} <br> Accept-Charset: $ENV{'HTTP_ACCEPT_CHARSET'} <br> Keep-Alive: $ENV{'HTTP_KEEP_ALIVE'} <br> Connection: $ENV{'HTTP_CONNECTION'} <p> SORRY -- I don't know how to show you the HTTP --RESPONSE-- Headers . +. . HTML } 1; Package Main; #!/usr/bin/perl use My::Module; the-function(); __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Showing HTTP response headers
by borisz (Canon) on Jan 08, 2005 at 19:08 UTC | |
|
Re: Showing HTTP response headers
by BUU (Prior) on Jan 08, 2005 at 19:03 UTC | |
by Joost (Canon) on Jan 08, 2005 at 19:44 UTC | |
by jacques (Priest) on Jan 08, 2005 at 20:10 UTC |