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!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|