link-checker commit: Add support for cookies (command line mode only for now).

changeset:   330:162ab080f542
user:        ville
date:        Thu Dec 03 21:28:09 2009 +0000
files:       META.yml Makefile.PL bin/checklink bin/checklink.pod
description:
Add support for cookies (command line mode only for now).


diff -r a38b915a6b71 -r 162ab080f542 META.yml
--- a/META.yml	Thu Dec 03 20:36:39 2009 +0000
+++ b/META.yml	Thu Dec 03 21:28:09 2009 +0000
@@ -16,6 +16,7 @@
     Getopt::Long:                  2.17
     HTML::Entities:                0
     HTML::Parser:                  3.2
+    HTTP::Cookies:                 0
     HTTP::Request:                 0
     HTTP::Response:                1.5
     Locale::Country:               0
diff -r a38b915a6b71 -r 162ab080f542 Makefile.PL
--- a/Makefile.PL	Thu Dec 03 20:36:39 2009 +0000
+++ b/Makefile.PL	Thu Dec 03 21:28:09 2009 +0000
@@ -44,6 +44,9 @@
                      CGI::Carp        => 0,
                      CGI::Cookie      => 0,
 
+                     # Optional, required if using cookies:
+                     HTTP::Cookies    => 0,
+
                      # Required for the test suite:
                      File::Spec       => 0,
                      Test::More       => 0,
diff -r a38b915a6b71 -r 162ab080f542 bin/checklink
--- a/bin/checklink	Thu Dec 03 20:36:39 2009 +0000
+++ b/bin/checklink	Thu Dec 03 21:28:09 2009 +0000
@@ -5,7 +5,7 @@
 # (c) 1999-2009 World Wide Web Consortium
 # based on Renaud Bruyeron's checklink.pl
 #
-# $Id: checklink,v 4.170 2009-12-03 20:36:39 ville Exp $
+# $Id: checklink,v 4.171 2009-12-03 21:28:09 ville Exp $
 #
 # This program is licensed under the W3C(r) Software License:
 #       http://www.w3.org/Consortium/Legal/copyright-software
@@ -283,7 +283,7 @@
   $PROGRAM     = 'W3C-checklink';
   $VERSION     = '4.5';
   $REVISION    = sprintf('version %s (c) 1999-2009 W3C', $VERSION);
-  my ($cvsver) = q$Revision: 4.170 $ =~ /(\d+[\d\.]*\.\d+)/;
+  my ($cvsver) = q$Revision: 4.171 $ =~ /(\d+[\d\.]*\.\d+)/;
   $AGENT       = sprintf('%s/%s [%s] %s',
                          $PROGRAM, $VERSION, $cvsver,
                          (W3C::UserAgent::USE_ROBOT_UA
@@ -396,6 +396,7 @@
     Redirects         => 1,
     Dir_Redirects     => 1,
     Accept_Language   => $cmdline ? undef : $ENV{HTTP_ACCEPT_LANGUAGE},
+    Cookies           => undef,
     No_Referer        => 0,
     Hide_Same_Realm   => 0,
     Depth             => 0,    # < 0 means unlimited recursion.
@@ -445,6 +446,17 @@
   $ua->delay($Opts{Sleep_Time}/60);
 }
 $ua->timeout($Opts{Timeout});
+# Set up cookie stash if requested
+if (defined($Opts{Cookies})) {
+  require HTTP::Cookies;
+  my $cookie_file = $Opts{Cookies};
+  if ($cookie_file eq 'tmp') {
+    $cookie_file = undef;
+  } elsif ($cookie_file =~ /^(.*)$/) {
+    $cookie_file = $1; # untaint
+  }
+  $ua->cookie_jar(HTTP::Cookies->new(file => $cookie_file, autosave => 1));
+}
 eval {
   $ua->allow_private_ips($Opts{Allow_Private_IPs});
 };
@@ -658,6 +670,7 @@
              't|timeout=i'     => \$Opts{Timeout},
              'S|sleep=i'       => \$Opts{Sleep_Time},
              'L|languages=s'   => \$Opts{Accept_Language},
+             'c|cookies=s'     => \$Opts{Cookies},
              'R|no-referer'    => \$Opts{No_Referer},
              'D|depth=i'       => sub { $Opts{Depth} = $_[1]
                                           unless $_[1] == 0; },
@@ -797,6 +810,8 @@
                             specified multiple times.
  -L, --languages LANGS      Accept-Language header to send.  The special value
                             'auto' causes autodetection from the environment.
+ -c, --cookies FILE         Use cookies, load/save them in FILE.  The special
+                            value 'tmp' causes non-persistent use of cookies.
  -R, --no-referer           Do not send the Referer HTTP header.
  -q, --quiet                No output if no errors are found (implies -s).
  -v, --verbose              Verbose mode.
@@ -971,12 +986,22 @@
     my $s = $Opts{Sleep_Time} == 1 ? '' : 's';
     my $acclang = $Opts{Accept_Language} || '(not sent)';
     my $send_referer = $Opts{No_Referer} ? 'not sent' : 'sending';
-    printf(<<'EOF', $Accept, $acclang, $send_referer, $Opts{Sleep_Time}, $s);
+    my $cookies = 'not used';
+    if (defined($Opts{Cookies})) {
+      $cookies = 'used, ';
+      if ($Opts{Cookies} eq 'tmp') {
+        $cookies .= 'non-persistent';
+      } else {
+        $cookies .= "file $Opts{Cookies}";
+      }
+    }
+    printf(<<'EOF', $Accept, $acclang, $send_referer, $cookies, $Opts{Sleep_Time}, $s);
 
 Settings used:
 - Accept: %s
 - Accept-Language: %s
 - Referer: %s
+- Cookies: %s
 - Sleeping %d second%s between requests to each server
 EOF
     printf("- Excluding links matching %s\n", $Opts{Exclude})
diff -r a38b915a6b71 -r 162ab080f542 bin/checklink.pod
--- a/bin/checklink.pod	Thu Dec 03 20:36:39 2009 +0000
+++ b/bin/checklink.pod	Thu Dec 03 21:28:09 2009 +0000
@@ -1,4 +1,4 @@
-$Id: checklink.pod,v 1.27 2009-11-04 18:44:17 mernst Exp $
+$Id: checklink.pod,v 1.28 2009-12-03 21:28:09 ville Exp $
 
 =head1 NAME
 
@@ -115,6 +115,12 @@
 a value to be detected from the C<LANG> environment variable, and sent
 if found.  In CGI mode, the default is to send the value received from
 the client as is.
+
+=item B<-c, --cookies> I<cookie-file>
+
+Use cookies, load/save them in I<cookie-file>.  The special value
+C<tmp> causes non-persistent use of cookies, i.e. they are used but
+only stored in memory for the duration of this link checker run.
 
 =item B<-R, --no-referer>
 

Received on Thursday, 5 August 2010 14:47:40 UTC