slloyd has asked for the wisdom of the Perl Monks concerning the following question:

Is there a simle lightweight way to analyze the header of a cgi request? I understand how if I were a server listening on a socket but I cannot think of a way to see the full header from a cgi script. Is there a way?

-------------------------------
Need a good Perl friendly Host Provider?
http://www.dreamhost.com

  • Comment on How can I capture the full header of a cgi script?

Replies are listed 'Best First'.
Re: How can I capture the full header of a cgi script?
by moritz (Cardinal) on Nov 29, 2007 at 13:31 UTC
    My favorite methods is wget -S $url on the command line.
Re: How can I capture the full header of a cgi script?
by Cubes (Pilgrim) on Nov 29, 2007 at 13:27 UTC
    There are a lot of ways to do this, but a couple of simple ones are:

    - Use the Web Developer add-on / toolbar in Firefox. Under "Information" is a menu option that will display the http response headers.

    - Put a print "Content-Type: text/plain\n\n" at the top of your script, before you send any headers. This will display the headers in your web browser (which now thinks they're part of the page content). Of course, you'll need to remove the print statement once you're done debugging.

Re: How can I capture the full header of a cgi script?
by Corion (Patriarch) on Nov 29, 2007 at 14:11 UTC

    If you have LWP installed, it comes with the GET utility, which is incredibly useful for just that:

    GET -USe http://google.com
Re: How can I capture the full header of a cgi script?
by sh1tn (Priest) on Nov 29, 2007 at 13:58 UTC
    You may want to try WWW::Mechanize

    #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); $mech->get("http://perlmonks.net"); my $headers = $mech->response->headers->as_string;


Re: How can I capture the full header of a cgi script?
by zentara (Cardinal) on Nov 29, 2007 at 14:51 UTC
    #!/usr/bin/perl use warnings; use strict; use LWP::UserAgent; use Data::Dumper; my $url = 'http://youtube.com/watch?v=2cBVpTRoMjI'; my $ua = LWP::UserAgent->new(); my $result = $ua->head($url); my $remote_headers = $result->headers; print Dumper(\$remote_headers);

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum