- From: Ville Skytta <ville@dev.w3.org>
- Date: Sun, 20 Jun 2004 19:33:47 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/validator/httpd/cgi-bin
In directory hutz:/tmp/cvs-serv27848
Modified Files:
Tag: validator-0_6_0-branch
check
Log Message:
Add support for multiple WWW-Authenticate headers. This is largely untested,
but the usual cases still work for me as they did before the change.
Hopefully fixes bug 805.
Index: check
===================================================================
RCS file: /sources/public/validator/httpd/cgi-bin/check,v
retrieving revision 1.305.2.144
retrieving revision 1.305.2.145
diff -u -d -r1.305.2.144 -r1.305.2.145
--- check 20 Jun 2004 16:48:38 -0000 1.305.2.144
+++ check 20 Jun 2004 19:33:45 -0000 1.305.2.145
@@ -47,6 +47,7 @@
use File::Spec qw();
use HTML::Parser 3.25 qw(); # Need 3.25 for $p->ignore_elements.
use HTTP::Request qw();
+use HTTP::Headers::Auth qw(); # Needs to be imported after other HTTP::*.
use IO::File qw();
use LWP::UserAgent 1.90 qw(); # Need 1.90 for protocols_(allowed|forbidden)
use Net::hostent qw(gethostbyname);
@@ -1203,20 +1204,30 @@
#
# Proxy authentication requests.
+# Note: expects the third argument to be a hash ref (see HTTP::Headers::Auth).
sub authenticate {
my $File = shift;
my $resource = shift;
- my $authHeader = shift;
+ my $authHeader = shift || {};
+
my $realm = $resource;
$realm =~ s([^\w\d.-]*){}g;
- $authHeader =~ s( realm=([\'\"])?([^\1]+)\1){ realm="$realm-$2"};
$resource = &ent($resource);
- print <<"EOF";
+ for my $scheme (keys(%$authHeader)) {
+ my $origrealm = $authHeader->{$scheme}->{realm};
+ next unless defined($origrealm);
+ $authHeader->{$scheme}->{realm} = "$realm-$origrealm";
+ }
+
+ my $headers = HTTP::Headers->new(Connection => 'close');
+ $headers->content_type('text/html; charset=utf-8');
+ $headers->www_authenticate(%$authHeader);
+ $headers = $headers->as_string();
+
+ print <<"EOF";
Status: 401 Authorization Required
-WWW-Authenticate: $authHeader
-Connection: close
-Content-Type: text/html; charset=utf-8
+$headers
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
@@ -1379,7 +1390,8 @@
unless ($res->code == 200 || $File->{Opt}->{'No200'}) {
if ($res->code == 401) {
- &authenticate($File, $res->request->url, $res->www_authenticate);
+ my %auth = $res->www_authenticate(); # HTTP::Headers::Auth
+ &authenticate($File, $res->request->url, \%auth);
} else {
print $File->{Results};
&http_error($uri->as_string, $res->code, $res->message);
Received on Sunday, 20 June 2004 15:33:47 UTC