1 package HTTP::Headers::Auth;
12 # we provide a new (and better) implementations below
13 undef(&www_authenticate);
14 undef(&proxy_authenticate);
17 require HTTP::Headers::Util;
19 sub _parse_authenticate
22 for (HTTP::Headers::Util::split_header_words(@_)) {
23 if (!defined($_->[1])) {
24 # this is a new auth scheme
25 push(@ret, lc(shift @$_) => {});
29 # this a new parameter pair for the last auth scheme
31 my $k = lc(shift @$_);
37 # something wrong, parameter pair without any scheme seen
48 my @old = $self->_header($header);
50 $self->remove_header($header);
53 my $a_scheme = shift(@new);
54 if ($a_scheme =~ /\s/) {
55 # assume complete valid value, pass it through
56 $self->push_header($header, $a_scheme);
62 if (ref($p) eq "ARRAY") {
66 elsif (ref($p) eq "HASH") {
71 my $val = ucfirst(lc($a_scheme));
77 if ($v =~ /[^0-9a-zA-Z]/ || lc($k) eq "realm") {
78 # must quote the value
79 $v =~ s,([\\\"]),\\$1,g;
86 $self->push_header($header, $val);
90 return unless defined wantarray;
91 wantarray ? _parse_authenticate(@old) : join(", ", @old);
95 sub www_authenticate { shift->_authenticate("WWW-Authenticate", @_) }
96 sub proxy_authenticate { shift->_authenticate("Proxy-Authenticate", @_) }