| 1 | package HTTP::Headers::Auth; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '7.04'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use HTTP::Headers; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | package | ||||||||||||||||||||||||||||
| 11 | HTTP::Headers; | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | # we provide a new (and better) implementations below | ||||||||||||||||||||||||||||
| 15 | 1 | undef(&www_authenticate); | |||||||||||||||||||||||||||
| 16 | 1 | undef(&proxy_authenticate); | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | require HTTP::Headers::Util; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | sub _parse_authenticate | ||||||||||||||||||||||||||||
| 22 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_parse_authenticate: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 23 | 4 | my @ret; | |||||||||||||||||||||||||||
| 24 | 4 | for (HTTP::Headers::Util::split_header_words(@_)) { | |||||||||||||||||||||||||||
| 25 | 9 | ▶ | if (!defined($_->[1])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | # this is a new auth scheme | ||||||||||||||||||||||||||||
| 27 | 6 | push(@ret, shift(@$_) => {}); | |||||||||||||||||||||||||||
| 28 | 6 | shift @$_; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | 9 | ▶ | if (@ret) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | # this a new parameter pair for the last auth scheme | ||||||||||||||||||||||||||||
| 32 | 9 | ▶ | while (@$_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 6 | my $k = shift @$_; | |||||||||||||||||||||||||||
| 34 | 6 | my $v = shift @$_; | |||||||||||||||||||||||||||
| 35 | 6 | $ret[-1]{$k} = $v; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | else { | ||||||||||||||||||||||||||||
| 39 | # something wrong, parameter pair without any scheme seen | ||||||||||||||||||||||||||||
| 40 | # IGNORE | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 4 | @ret; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | sub _authenticate | ||||||||||||||||||||||||||||
| 47 | 8 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_authenticate: called CC=13 SCAR=25.6
| |||||||||||||||||||||||||||||
| 48 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 49 | 8 | my $header = shift; | |||||||||||||||||||||||||||
| 50 | 8 | my @old = $self->_header($header); | |||||||||||||||||||||||||||
| 51 | 8 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 6 | $self->remove_header($header); | |||||||||||||||||||||||||||
| 53 | 6 | my @new = @_; | |||||||||||||||||||||||||||
| 54 | 6 | ▶ | while (@new) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 8 | my $a_scheme = shift(@new); | |||||||||||||||||||||||||||
| 56 | 8 | ▶ | if ($a_scheme =~ /\s/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | # assume complete valid value, pass it through | ||||||||||||||||||||||||||||
| 58 | 1 | $self->push_header($header, $a_scheme); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | else { | ||||||||||||||||||||||||||||
| 61 | 7 | my @param; | |||||||||||||||||||||||||||
| 62 | 7 | ▶ | if (@new) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 5 | my $p = $new[0]; | |||||||||||||||||||||||||||
| 64 | 5 | ▶ | if (ref($p) eq "ARRAY") { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 65 | 1 | @param = @$p; | |||||||||||||||||||||||||||
| 66 | 1 | shift(@new); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | elsif (ref($p) eq "HASH") { | ||||||||||||||||||||||||||||
| 69 | 3 | @param = %$p; | |||||||||||||||||||||||||||
| 70 | 3 | shift(@new); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 7 | my $val = ucfirst(lc($a_scheme)); | |||||||||||||||||||||||||||
| 74 | 7 | ▶ | if (@param) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 4 | my $sep = " "; | |||||||||||||||||||||||||||
| 76 | 4 | ▶ | while (@param) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 6 | my $k = shift @param; | |||||||||||||||||||||||||||
| 78 | 6 | my $v = shift @param; | |||||||||||||||||||||||||||
| 79 | 6 | ▶ | if ($v =~ /[^0-9a-zA-Z]/ || lc($k) eq "realm") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$v =~ /[^0-9a-zA-Z]/ or lc $k eq "realm"
MC/DC100%2/2
$v =~ /[^0-9a-zA-Z]/ or lc $k eq "realm"
$v =~ /[^0-9a-zA-Z]/
lc $k eq "realm"
Truth table100%3/3
A or B
A= $v =~ /[^0-9a-zA-Z]/B= lc $k eq "realm"
| |||||||||||||||||||||||||||||
| 80 | # must quote the value | ||||||||||||||||||||||||||||
| 81 | 3 | $v =~ s,([\\\"]),\\$1,g; | |||||||||||||||||||||||||||
| 82 | 3 | $v = qq("$v"); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 6 | $val .= "$sep$k=$v"; | |||||||||||||||||||||||||||
| 85 | 6 | $sep = ", "; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | 7 | $self->push_header($header, $val); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | 8 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 5 | ▶ | wantarray ? _parse_authenticate(@old) : join(", ", @old); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 5 | ▶ | sub www_authenticate { shift->_authenticate("WWW-Authenticate", @_) } | ||||||||||||||||||||||||||
|
Subroutine
www_authenticate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 98 | 3 | ▶ | sub proxy_authenticate { shift->_authenticate("Proxy-Authenticate", @_) } | ||||||||||||||||||||||||||
|
Subroutine
proxy_authenticate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 1 | 1; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | __END__ | ||||||||||||||||||||||||||||