Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Getting all Headers

by naikonta (Curate)
on Feb 05, 2008 at 06:59 UTC ( #666228=note: print w/ replies, xml ) Need Help??


in reply to Getting all Headers

Subclass from LWP::UserAgent and implement the method progress. Then I think you can do pretty much whatever you want. The following snippet only prints out available response header names, but you can extend it to also print the header values, and for request headers as well.

$ cat lwp-headers.pl #!/usr/bin/perl package MyLWP; use base 'LWP::UserAgent'; sub progress { my($self, $status, $resp) = @_; if ($resp) { my @headers = $resp->header_field_names; print "response headers: @headers\n"; } } package main; my $ua = MyLWP->new; my $url = shift || 'http://gmail.google.com'; my $rp = $ua->get($url); print $rp->status_line, "\n"; $ ./lwp-headers.pl http://www.google.com response headers: Cache-Control Connection Date Location Content-Lengt +h Content-Type Client-Peer Client-Response-Num Set-Cookie Title X-Cac +he X-Cache-Lookup response headers: Cache-Control Connection Date Location Content-Lengt +h Content-Type Client-Date Client-Peer Client-Response-Num Set-Cookie + Title X-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Content-Type Client-Pe +er Client-Response-Num Set-Cookie Title X-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Content-Type Client-Pe +er Client-Response-Num Set-Cookie Title X-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Content-Type Client-Pe +er Client-Response-Num Set-Cookie Title X-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Content-Type Client-Pe +er Client-Response-Num Set-Cookie Title X-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Content-Type Client-Pe +er Client-Response-Num Set-Cookie Title X-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Content-Type Client-Pe +er Client-Response-Num Set-Cookie Title X-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Content-Type Client-Da +te Client-Peer Client-Response-Num Set-Cookie Title X-Cache X-Cache-L +ookup 200 OK $ ./lwp-headers.pl response headers: Cache-Control Connection Date Pragma Location Conten +t-Type Client-Peer Client-Response-Num Title X-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Pragma Location Conten +t-Type Client-Date Client-Peer Client-Response-Num Title X-Cache X-Ca +che-Lookup response headers: Cache-Control Connection Date Pragma Location Conten +t-Type Client-Peer Client-Response-Num Set-Cookie Title X-Cache X-Cac +he-Lookup response headers: Cache-Control Connection Date Pragma Location Conten +t-Type Client-Date Client-Peer Client-Response-Num Set-Cookie Title X +-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Pragma Location Conten +t-Type Client-Peer Client-Response-Num Set-Cookie Title X-Cache X-Cac +he-Lookup response headers: Cache-Control Connection Date Pragma Location Conten +t-Type Client-Peer Client-Response-Num Set-Cookie Title X-Cache X-Cac +he-Lookup response headers: Cache-Control Connection Date Pragma Location Conten +t-Type Client-Date Client-Peer Client-Response-Num Set-Cookie Title X +-Cache X-Cache-Lookup response headers: Cache-Control Connection Date Pragma Server Content- +Length Content-Type Client-Peer Client-Response-Num Client-SSL-Cert-I +ssuer Client-SSL-Cert-Subject Client-SSL-Cipher Client-SSL-Warning Se +t-Cookie ..... response headers: Cache-Control Connection Date Pragma Server Content- +Length Content-Type Client-Date Client-Peer Client-Response-Num Clien +t-SSL-Cert-Issuer Client-SSL-Cert-Subject Client-SSL-Cipher Client-SS +L-Warning Set-Cookie Title 200 OK

Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!


Comment on Re: Getting all Headers
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://666228]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-12-22 23:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (133 votes), past polls