Subject: | trivial patch for basic authenticatino in mech-dump |
Attached a simple patch to add options to pass user/password to
mech-dump, to allow basic authentication.
Subject: | mech-dump-authentication.patch |
--- /usr/bin/mech-dump 2006-04-19 14:13:47.000000000 +0200
+++ ./mech-dump 2006-06-23 14:34:30.000000000 +0200
@@ -16,6 +16,7 @@
my @actions;
my $absolute;
+my ($user, $password);
GetOptions(
forms => sub { push( @actions, \&dump_forms ); },
@@ -23,6 +24,8 @@
images => sub { push( @actions, \&dump_images ); },
all => sub { push( @actions, \&dump_forms, \&dump_links, \&dump_images ); },
absolute => \$absolute,
+ 'credentials=s' => sub { ($user, $password) = split(':', $_[1], 2);
+ defined $user && defined $password or die "syntax : --credentials user:password" },
help => sub { pod2usage(1); },
) or pod2usage(2);
@@ -37,6 +40,9 @@
--images Dump table of images
--all Dump all three of the above, in that order
+ --credentials user:password
+ Use basic authentication
+
--absolute Show URLs as absolute, even if relative in the page
--help Show this message
@@ -54,6 +60,16 @@
@actions = (\&dump_forms) unless @actions;
my $mech = WWW::Mechanize->new( cookie_jar => undef );
+
+
+defined $user and do
+{
+ package WWW::Mechanize;
+ sub get_basic_credentials {
+ return ($user, $password)
+ }
+};
+
my $response = $mech->get( $uri );
$response->is_success or die "Can't fetch $uri\n", $response->status_line, "\n";
$mech->is_html or die "$uri returns type \"", $mech->ct, "\", not \"text/html\"\n";