Re: [PATCH] lwp-request - Option to change UserAgent
Gisle Aas (gisle@aas.no)
20 Jun 1999 02:01:42 +0200
Ask Bjoern Hansen <ask@valueclick.com> writes:
> I'm often using lwp-request to debug my web.applications[tm], and it's
> extremely useful for me to be able to specify the UserAgent on the
> commandline, and I figured it could be useful for others also, so here's
> the simple patch.
I would prefer to use the new -H option for this:
lwp-request -H 'UserAgent: foo/0.1' ...
The following patch will be in 5.44.
Regards,
Gisle
$ cvs diff -u -rR5_43 bin/lwp-request.PL
Index: bin/lwp-request.PL
===================================================================
RCS file: /home/cvs/aas/perl/mods/libwww-perl/bin/lwp-request.PL,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -u -r1.37 -r1.38
--- lwp-request.PL 1999/03/21 21:56:18 1.37
+++ lwp-request.PL 1999/06/01 10:40:51 1.38
@@ -12,7 +12,7 @@
!GROK!THIS!
print OUT <<'!NO!SUBS!';
-# $Id: lwp-request.PL,v 1.37 1999/03/21 21:56:18 gisle Exp $
+# $Id: lwp-request.PL,v 1.38 1999/06/01 10:40:51 gisle Exp $
#
# Simple user agent using LWP library.
@@ -190,7 +190,7 @@
$progname =~ s,.*/,,; # use basename only
$progname =~ s/\.\w*$//; # strip extension, if any
-$VERSION = sprintf("%d.%02d", q$Revision: 1.37 $ =~ /(\d+)\.(\d+)/);
+$VERSION = sprintf("%d.%02d", q$Revision: 1.38 $ =~ /(\d+)\.(\d+)/);
require LWP;
@@ -383,6 +383,7 @@
for my $user_header (@{ $options{'H'} || [] }) {
my ($header_name, $header_value) = split /:\s*/, $user_header, 2;
$request->header($header_name, $header_value);
+ $ua->agent($header_value) if lc($header_name) eq "user-agent"; # Ugh!
}
#$request->header('Accept', '*/*');
if ($options{'c'}) { # will always be set for request that wants content
use HTML::TokeParser;
my $gt = HTML::TokeParser->new(shift||"index.html") || die;
while (my $token = $gt->get_tag("h1")) {
print $gt->get_trimmed_text("/h1"), "\n";
}
Regards,
Gisle
> <H1> The One Before</H1>
>
> <H1> Wibble 99 22222222</H1>