| 1 | package IO::Lambda::HTTP::Client; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use vars qw(@ISA @EXPORT_OK $DEBUG); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | @EXPORT_OK = qw(http_request); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | our $DEBUG = $IO::Lambda::DEBUG{http} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$IO::Lambda::DEBUG{'http'} || 0
MC/DC0%0/1
$IO::Lambda::DEBUG{'http'} || 0
$IO::Lambda::DEBUG{'http'}
Truth table50%1/2
A
A= $IO::Lambda::DEBUG{'http'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Socket; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Errno; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use IO::Socket; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use HTTP::Response; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use IO::Lambda qw(:lambda :stream); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use IO::Lambda::Socket qw(connect); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use Time::HiRes qw(time); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | sub http_request(&) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | __PACKAGE__-> new(context)-> | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
http_request: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | condition(shift, \&http_request, 'http_request') | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 5 | ▶ | my ( $class, $req, %options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=14 SCAR=32.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 5 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 5 | ▶ | $self-> {deadline} = $options{timeout} + time if defined $options{timeout}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 5 | ▶ | $self-> {deadline} = $options{deadline} if defined $options{deadline}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 5 | ▶ | $self-> {max_redirect} = defined($options{max_redirect}) ? $options{max_redirect} : 7; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | delete @options{qw(deadline timeout max_redirect)}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 5 | $self-> {$_} = $options{$_} for keys %options; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | my %headers; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 5 | $headers{'User-Agent'} = "perl/IO-Lambda-HTTP v$IO::Lambda::VERSION"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 5 | ▶ | if ( $self-> {keep_alive}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | unless ( $self-> {conn_cache}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | require LWP::ConnCache; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $self-> {conn_cache} = LWP::ConnCache-> new; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | unless ( $req-> protocol) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $req-> protocol('HTTP/1.1'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $headers{Host} = $req-> uri-> host; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $headers{Connection} = 'Keep-Alive'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $headers{'Keep-Alive'} = 300; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 5 | ▶ | require IO::Lambda::DNS if $self-> {async_dns}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 5 | my $h = $req-> headers; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 5 | ▶ | while ( my ($k, $v) = each %headers) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 5 | ▶ | $h-> header($k, $v) unless defined $h-> header($k); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | ▶ | if ( $options{cookie_jar} //= {} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$options{"cookie_jar"} //= {}
MC/DC0%0/1
$options{"cookie_jar"} //= {}
$options{"cookie_jar"}
Truth table50%1/2
A
A= $options{"cookie_jar"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 5 | ▶ | if ( ref($options{cookie_jar}) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 5 | require HTTP::Cookies; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 5 | $options{cookie_jar} = HTTP::Cookies->new(%{$options{cookie_jar}}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 5 | $self->{cookie_jar} = $options{cookie_jar}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 5 | return $self-> handle_redirect( $req); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # HTTP::Response features methods base() and request() that we need to set as well | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | sub finalize_response | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | my ( $self, $req, $response) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finalize_response: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | return $response; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | sub redirect | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my ( $self, $location, $req) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
redirect: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | return URI-> new_abs( $location, $req-> uri); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # reissue the request, if necessary, because of 30X or 401 errors | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | sub handle_redirect | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 5 | ▶ | my ( $self, $req) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_redirect: called CC=1 SCAR=4.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 5 | my $was_redirected = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 5 | my $was_failed_auth = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 5 | my $auth = $self-> {auth}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | lambda { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 5 | ▶ | my $method; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=29.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 5 | ▶ | if ( $auth) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # create fake response for protocol initiation, -- but just once | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $x = HTTP::Response-> new; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $x-> headers-> header('WWW-Authenticate', split(',', $auth)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $method = $self-> get_authenticator( $req, $x); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | undef $auth; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | $self->{cookie_jar}->add_cookie_header($req) if | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | $self->{cookie_jar} && | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 5 | ▶ | !$req->headers->header('Cookie'); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"cookie_jar"} and not $req->headers->header("Cookie")
MC/DC0%0/2
$self->{"cookie_jar"} and not $req->headers->header("Cookie")
$self->{"cookie_jar"}
not $req->headers->header("Cookie")
Truth table33%1/3
A and not(B)
A= $self->{"cookie_jar"}B= not $req->headers->header("Cookie")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 5 | ▶ | context $method || $self-> handle_connection( $req); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$method || $self->handle_connection($req)
MC/DC0%0/2
$method || $self->handle_connection($req)
$method
$self->handle_connection($req)
Truth table33%1/3
A || B
A= $methodB= $self->handle_connection($req)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | tail { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # request is finished | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 5 | ▶ | my $response = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=14 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 5 | ▶ | return $response unless ref($response); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $response-> request($req); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | $self->{cookie_jar}->extract_cookies($response) if $self->{cookie_jar}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if ( $response-> code =~ /^30[12378]$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | return $self-> finalize_response($req, $response) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if $self->{max_redirect} == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $was_failed_auth = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | return 'too many redirects' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ++$was_redirected > $self-> {max_redirect}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my $location = $response-> header('Location'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | return $response unless defined $location; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my $uri = $self->redirect( $location, $req ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | return $response if $uri->scheme !~ /^https?$/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | $req-> uri($uri); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $req-> headers-> header( Host => $req-> uri-> host); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $req-> remove_header('Cookie'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $req-> method('GET'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | warn "redirect to " . $req-> uri . "\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | this-> start; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | ▶ | } elsif ( | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
not $was_failed_auth and $response->code eq 401 and defined $self->{"username"} and defined $self->{"password"}
not $was_failed_auth and $response->code eq 401 and defined $self->{"username"}
not $was_failed_auth and $response->code eq 401
MC/DC0%0/4
not $was_failed_auth and $response->code eq 401 and defined $self->{"username"} and defined $self->{"password"}
not $was_failed_auth
$response->code eq 401
defined $self->{"username"}
defined $self->{"password"}
Truth table0%0/5
not(A) and B and C and D
A= not $was_failed_authB= $response->code eq 401C= defined $self->{"username"}D= defined $self->{"password"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | not($was_failed_auth) and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | $response-> code eq '401' and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | defined($self-> {username}) and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | defined($self-> {password}) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $was_failed_auth++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $method = $self-> get_authenticator( $req, $response); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | context $method; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | return $method ? tail { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | my $r = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | return $r unless $r; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # start from beginning, from handle_connection; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | this-> start; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | } : $self-> finalize_response($req, $response); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | return $self-> finalize_response($req, $response); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 5 | }}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # if request needs authentication, and we can do something about it, create | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # a lambda that handles the authentication | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | sub get_authenticator | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | my ( $self, $req, $response) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_authenticator: not called CC=17 SCAR=57.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # supports authentication? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my %auth; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | for my $auth ( $response-> header('WWW-Authenticate')) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | $auth =~ s/\s.*$//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $auth{$auth}++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | my %preferred = defined($self-> {preferred_auth}) ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | ref($self-> {preferred_auth}) ? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | %{ $self-> {preferred_auth} } : | |||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | ( $self-> {preferred_auth} => 1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | ) : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | my @auth = sort { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | ($preferred{$b} || 0) <=> ($preferred{$a} || 0) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
$preferred{$b} || 0
$preferred{$a} || 0
MC/DC0%0/1
$preferred{$b} || 0
$preferred{$b}
MC/DC0%0/1
$preferred{$a} || 0
$preferred{$a}
Truth table0%0/2
A
A= $preferred{$b}
Truth table0%0/2
A
A= $preferred{$a}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | not exists($preferred{$_}) or $preferred{$_} >= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } keys %auth; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my $compilation_errors = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | for my $auth ( @auth) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | if ( $auth eq 'Basic') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # always | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | warn "trying basic authentication\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $req-> authorization_basic( $self-> {username}, $self-> {password}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | return $self-> handle_connection( $req); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | eval { require "IO/Lambda/HTTP/Authen/$auth.pm" }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | $compilation_errors .= "$@\n" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ and not $@ =~ m[^Can't locate IO/Lambda/HTTP/Authen/$auth]
MC/DC0%0/2
$@ and not $@ =~ m[^Can't locate IO/Lambda/HTTP/Authen/$auth]
$@
not $@ =~ m[^Can't locate IO/Lambda/HTTP/Authen/$auth]
Truth table0%0/3
A and not(B)
A= $@B= not $@ =~ m[^Can't locate IO/Lambda/HTTP/Authen/$auth]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | if $@ and ($@ !~ m{^Can't locate IO/Lambda/HTTP/Authen/$auth}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | next if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | my $lambda = "IO::Lambda::HTTP::Authen::$auth"-> | |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | authenticate( $self, $req, $response); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | warn "trying authentication with '$auth'\n" if $DEBUG and $lambda; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$IO::Lambda::HTTP::Client::DEBUG and $lambda
MC/DC0%0/2
$IO::Lambda::HTTP::Client::DEBUG and $lambda
$IO::Lambda::HTTP::Client::DEBUG
$lambda
Truth table0%0/3
A and B
A= $IO::Lambda::HTTP::Client::DEBUGB= $lambda
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | return $lambda if $lambda; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # XXX Propagate compilation errors as http errors. Doubtful. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | return lambda { $compilation_errors } if length $compilation_errors; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # get scheme and eventually load module | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 2 | my $got_https; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | sub prepare_transport | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 5 | ▶ | my ( $self, $req) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_transport: called CC=7 SCAR=31.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 5 | my $scheme = $req-> uri-> scheme; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 5 | ▶ | unless ( defined $scheme) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | return "bad URI: " . $req-> uri-> as_string; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } elsif ( $scheme eq 'https') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | unless ( $got_https) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | eval { require IO::Lambda::HTTP::HTTPS; }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | return "https not supported: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | $got_https++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $self-> {reader} = IO::Lambda::HTTP::HTTPS::https_reader(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | $self-> {writer} = \&IO::Lambda::HTTP::HTTPS::https_writer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | warn "https enabled\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } elsif ( $scheme ne 'http') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | return "bad URI scheme: $scheme"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 5 | $self-> {reader} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 5 | $self-> {writer} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # returns static lambda that reads from socket until a condition (see sysreader) is satisfied | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | sub http_read | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | my ( $self, $cond) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
http_read: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | return $self-> {reader}, $self-> {socket}, \ $self-> {buf}, $cond, $self-> {deadline}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # read from socket until a condition (see sysreader) is satisfied | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # after this call no communication should happen | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | sub http_tail | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | my ( $self, $cond) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
http_tail: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | context $self-> http_read($cond); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | &tail(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | my $tcp_proto; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | sub socket | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 5 | ▶ | my ( $self, $host, $port) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
socket: called CC=7 SCAR=33.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 5 | my ($iaddr,$paddr,$sock,$error); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 5 | ▶ | $tcp_proto //= getprotobyname('tcp'); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$tcp_proto //= getprotobyname "tcp"
MC/DC0%0/2
$tcp_proto //= getprotobyname "tcp"
$tcp_proto
getprotobyname "tcp"
Truth table33%1/3
A //= B
A= $tcp_protoB= getprotobyname "tcp"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 5 | ▶ | return undef, "gethostbyname(tcp) error:$!" unless $tcp_proto; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | return undef, "cannot resolve $host" unless $iaddr = inet_aton($host); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | $paddr = sockaddr_in($port,$iaddr); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | return undef, "error creating socket:$!" unless socket($sock,PF_INET,SOCK_STREAM,$tcp_proto); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | $sock->blocking(0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | return undef, "connect($host,$port) error:$!" unless CORE::connect($sock,$paddr) or $!{EINPROGRESS}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
CORE::connect $sock, $paddr or $!{"EINPROGRESS"}
MC/DC0%0/2
CORE::connect $sock, $paddr or $!{"EINPROGRESS"}
CORE::connect $sock, $paddr
$!{"EINPROGRESS"}
Truth table0%0/3
A or B
A= CORE::connect $sock, $paddrB= $!{"EINPROGRESS"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | return $sock; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | sub parse_proxy | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 5 | ▶ | my ( $self, $req) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_proxy: called CC=16 SCAR=39.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 5 | my ( $host, $port); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 5 | ▶ | if ( exists( $self-> {proxy})) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | ▶ | if ( !defined $self->{proxy}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | ( $host, $port) = ( $req-> uri-> host, $req-> uri-> port); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } elsif ( ref($self->{proxy})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | Carp::confess("'proxy' option must be a non-empty array") if | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | ref($self->{proxy}) ne 'ARRAY' or | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | not @{$self->{proxy}}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $self->{"proxy"} ne "ARRAY" or not @{$self->{"proxy"};}
MC/DC0%0/2
ref $self->{"proxy"} ne "ARRAY" or not @{$self->{"proxy"};}
ref $self->{"proxy"} ne "ARRAY"
not @{$self->{"proxy"};}
Truth table0%0/3
A or not(B)
A= ref $self->{"proxy"} ne "ARRAY"B= not @{$self->{"proxy"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ($host, $port) = @{$self->{proxy}}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | $host = $self-> {proxy}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | ▶ | $port ||= $req-> uri-> port; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$port ||= $req->uri->port
MC/DC0%0/2
$port ||= $req->uri->port
$port
$req->uri->port
Truth table33%1/3
A ||= B
A= $portB= $req->uri->port
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 4 | my $scheme = $req-> uri-> scheme; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 4 | ( $host, $port) = ( $req-> uri-> host, $req-> uri-> port); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 4 | my %proxy; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 4 | for my $id ($scheme, qw(all no)) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 12 | ▶ | if ( exists $ENV{"${id}_proxy"}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | $proxy{$id} = $ENV{"${id}_proxy"}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } elsif ( exists $ENV{uc "${id}_proxy"}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $proxy{$id} = $ENV{uc "${id}_proxy"}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 4 | ▶ | my $proxy = $proxy{all} // $proxy{$scheme}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$proxy{"all"} // $proxy{$scheme}
MC/DC0%0/2
$proxy{"all"} // $proxy{$scheme}
$proxy{"all"}
$proxy{$scheme}
Truth table33%1/3
A // B
A= $proxy{"all"}B= $proxy{$scheme}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 4 | ▶ | $proxy{no} //= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$proxy{"no"} //= ""
MC/DC0%0/1
$proxy{"no"} //= ""
$proxy{"no"}
Truth table50%1/2
A
A= $proxy{"no"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | ($host, $port) = ( $proxy =~ /^(.+?)\:(\d+)$/) ? ($1, $2) : ($proxy, 80) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 4 | ▶ | if defined($proxy) and $proxy{no} ne '*' and $proxy{no} !~ /\b\Q$host\E\b/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
defined $proxy and $proxy{"no"} ne "*" and not $proxy{"no"} =~ /\b\Q$host\E\b/
defined $proxy and $proxy{"no"} ne "*"
MC/DC0%0/3
defined $proxy and $proxy{"no"} ne "*" and not $proxy{"no"} =~ /\b\Q$host\E\b/
defined $proxy
$proxy{"no"} ne "*"
not $proxy{"no"} =~ /\b\Q$host\E\b/
Truth table25%1/4
A and B and not(C)
A= defined $proxyB= $proxy{"no"} ne "*"C= not $proxy{"no"} =~ /\b\Q$host\E\b/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 5 | return ( $host, $port); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | # Connect to the remote, wait for protocol to finish, and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | # close the connection if needed. Returns HTTP::Response object on success | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | sub handle_connection | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 5 | ▶ | my ( $self, $req) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_connection: called CC=2 SCAR=13.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 5 | my ( $host, $port) = $self->parse_proxy($req); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | # have a chance to load eventual modules early | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 5 | my $err = $self-> prepare_transport( $req); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 5 | ▶ | return lambda { $err } if defined $err; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | lambda { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | # resolve hostname | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 5 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=16 SCAR=50.1
Branch: 1 branch
Condition33%1/3
$self->{"async_dns"} and not $host =~ /^(\d{1,3}\.){3}(\d{1,3})$/
MC/DC0%0/2
$self->{"async_dns"} and not $host =~ /^(\d{1,3}\.){3}(\d{1,3})$/
$self->{"async_dns"}
not $host =~ /^(\d{1,3}\.){3}(\d{1,3})$/
Truth table33%1/3
A and not(B)
A= $self->{"async_dns"}B= not $host =~ /^(\d{1,3}\.){3}(\d{1,3})$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | $self-> {async_dns} and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | $host !~ /^(\d{1,3}\.){3}(\d{1,3})$/ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | context $host, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | timeout => ($self-> {deadline} || $IO::Lambda::DNS::TIMEOUT); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'deadline'} || $IO::Lambda::DNS::TIMEOUT
MC/DC0%0/2
$self->{'deadline'} || $IO::Lambda::DNS::TIMEOUT
$self->{'deadline'}
$IO::Lambda::DNS::TIMEOUT
Truth table0%0/3
A || B
A= $self->{'deadline'}B= $IO::Lambda::DNS::TIMEOUT
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | warn "resolving $host\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | return IO::Lambda::DNS::dns( sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | $host = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | return $host unless $host =~ /^\d/; # error | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | warn "resolved to $host\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | return this-> start; # restart the lambda with different $host | |||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 5 | delete $self-> {close_connection}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 5 | ▶ | $self-> {close_connection}++ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$req->header('Connection') || ''
MC/DC0%0/1
$req->header('Connection') || ''
$req->header('Connection')
Truth table50%1/2
A
A= $req->header('Connection')
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | if ( $req-> header('Connection') || '') =~ /^close/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | # got cached socket? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 5 | my ( $sock, $cached); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 5 | my $cc = $self-> {conn_cache}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 5 | ▶ | if ( $cc) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | $sock = $cc-> withdraw( __PACKAGE__, "$host:$port"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | if ( $sock) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | my $err = unpack('i', getsockopt( $sock, SOL_SOCKET, SO_ERROR)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | $err ? undef $sock : $cached++; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | warn "reused socket is ".($err ? "bad" : "ok")."\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | # connect | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 5 | my $err; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 5 | ▶ | warn "connecting\n" if $DEBUG and not($sock); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$IO::Lambda::HTTP::Client::DEBUG and not $sock
MC/DC0%0/2
$IO::Lambda::HTTP::Client::DEBUG and not $sock
$IO::Lambda::HTTP::Client::DEBUG
not $sock
Truth table33%1/3
A and not(B)
A= $IO::Lambda::HTTP::Client::DEBUGB= not $sock
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 5 | ▶ | ( $sock, $err) = $self-> socket( $host, $port) unless $sock; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 5 | ▶ | return $err unless $sock; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | context( $sock, $self-> {deadline}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | connect { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | return shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | # connected | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | $self-> {socket} = $sock; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | $self-> {reader} = readbuf ( $self-> {reader}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | $self-> {writer} = $self-> {writer}-> ($cached, $host, $port) if $self-> {writer}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | $self-> {writer} = writebuf( $self-> {writer}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | context $self-> handle_request( $req); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | autocatch tail { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | my $response = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | # put back the connection, if possible | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | if ( $cc and not $self-> {close_connection}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$cc and not $self->{"close_connection"}
MC/DC0%0/2
$cc and not $self->{"close_connection"}
$cc
not $self->{"close_connection"}
Truth table0%0/3
A and not(B)
A= $ccB= not $self->{"close_connection"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | my $err = unpack('i', getsockopt( $sock, SOL_SOCKET, SO_ERROR)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | warn "deposited socket back\n" if $DEBUG and not($err); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$IO::Lambda::HTTP::Client::DEBUG and not $err
MC/DC0%0/2
$IO::Lambda::HTTP::Client::DEBUG and not $err
$IO::Lambda::HTTP::Client::DEBUG
not $err
Truth table0%0/3
A and not(B)
A= $IO::Lambda::HTTP::Client::DEBUGB= not $err
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | $cc-> deposit( __PACKAGE__, "$host:$port", $sock) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | unless $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | warn "connection:close\n" if $DEBUG and $self-> {close_connection}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$IO::Lambda::HTTP::Client::DEBUG and $self->{"close_connection"}
MC/DC0%0/2
$IO::Lambda::HTTP::Client::DEBUG and $self->{"close_connection"}
$IO::Lambda::HTTP::Client::DEBUG
$self->{"close_connection"}
Truth table0%0/3
A and B
A= $IO::Lambda::HTTP::Client::DEBUGB= $self->{"close_connection"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | delete @{$self}{qw(close_connection socket buf writer reader)}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | return $response; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | }}} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 5 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | # Execute single http request over an established connection. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # Returns either a HTTP::Response object, or an error string | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | sub handle_request | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | my ( $self, $req) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_request: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | lambda { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | $self-> {buf} = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | context $self-> handle_request_in_buffer( $req); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | if ( $DEBUG) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | warn "request sent\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | warn $req-> as_string . "\n" if $DEBUG > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | tail { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | my ( undef, $error) = @_; # readbuf style | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | if ( $DEBUG) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | warn "got response\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | warn (( $error ? $error : $self-> {buf}) . "\n") if $DEBUG > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | return defined($error) ? $error : $self-> parse( \ $self-> {buf} ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | }} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | # Execute single http request over an established connection. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | # Returns 2 parameters, readbuf-style, where actually only the 2nd matters, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | # and signals error if defined. 2 parameters are there for readbuf() compatibility, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | # so that the protocol handler can easily fall back to readbuf() itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | sub handle_request_in_buffer | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | my ( $self, $req) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_request_in_buffer: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | my $method = $req-> method; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | # fixup path - otherwise LWP generates request as GET http://hostname/uri HTTP/1.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # which not all servers understand | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | my ($req_line, $save_uri); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | if (!$self-> {proxy} && ( $req-> protocol || '') =~ /http\/1.\d/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
not $self->{"proxy"} and ($req->protocol || "") =~ m[http/1.\d]i
$req->protocol || ''
MC/DC0%0/2
not $self->{"proxy"} and ($req->protocol || "") =~ m[http/1.\d]i
not $self->{"proxy"}
$req->protocol
Truth table0%0/3
not(A) and B
A= not $self->{"proxy"}B= $req->protocol
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | $save_uri = $req-> uri; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | my $fullpath = $save_uri-> path_query; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | $fullpath = "/$fullpath" unless $fullpath =~ m[^/]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | $req-> uri( $fullpath); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $req_line = $req-> as_string("\x0d\x0a"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | $req-> uri($save_uri) if defined $save_uri; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | lambda { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | # send request | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | context | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | $self-> {writer}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | $self-> {socket}, \ $req_line, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | ▶ | undef, 0, $self-> {deadline}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | state write => tail { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | my ( $bytes_written, $error) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | return undef, $error if $error; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | context $self-> {socket}, $self-> {deadline}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | readable { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | # request sent, now wait for data | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | return undef, 'timeout' unless shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | # read first line | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | context $self-> http_read(qr/^.*?\n/); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | state head => tail { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | my $line = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | unless ( defined $line) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | my $error = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | # remote closed connection and content is single-line HTTP/1.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | return (undef, $error) if $error ne 'eof'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | return (undef, undef); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | # no headers? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | ▶ | return $self-> http_tail | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | unless $line =~ /^HTTP\/[\.\d]+\s+\d{3}\s+/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | # got some headers | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | context $self-> http_read( qr/^.*?\r?\n\r?\n/s); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | state body => tail { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | ▶ | $line = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | return undef, shift unless defined $line; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | my $headers = HTTP::Response-> parse( $line); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | # Connection: close | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | my $c = lc( $headers-> header('Connection') || ''); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$headers->header('Connection') || ''
MC/DC0%0/1
$headers->header('Connection') || ''
$headers->header('Connection')
Truth table0%0/2
A
A= $headers->header('Connection')
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | $self-> {close_connection} = $c =~ /^close\s*$/i; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | return 1 if $method eq 'HEAD'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | return $self-> http_read_body( length $line, $headers); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | }}}}} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | # have headers, read body | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | sub http_read_body | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | my ( $self, $offset, $headers) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
http_read_body: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | # have Content-Length? read that many bytes then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | my $l = $headers-> header('Content-Length'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | return $self-> http_tail( $1 + $offset ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $l and $l =~ /^(\d+)\s*$/
MC/DC0%0/2
defined $l and $l =~ /^(\d+)\s*$/
defined $l
$l =~ /^(\d+)\s*$/
Truth table0%0/3
A and B
A= defined $lB= $l =~ /^(\d+)\s*$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | if defined ($l) and $l =~ /^(\d+)\s*$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # have 'Transfer-Encoding: chunked' ? read the chunks | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | my $te = lc( $headers-> header('Transfer-Encoding') || ''); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$headers->header('Transfer-Encoding') || ''
MC/DC0%0/1
$headers->header('Transfer-Encoding') || ''
$headers->header('Transfer-Encoding')
Truth table0%0/2
A
A= $headers->header('Transfer-Encoding')
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | return $self-> http_read_chunked($offset) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | ▶ | if $self-> {chunked} = $te =~ /^chunked\s*$/i; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | # just read as much as possible then -- however with considerations; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | # we can't do that if server keeps connection open, otherwise we'll hang | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | # http/1.0 and less doesn't implement open connections | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | ▶ | return $self-> http_tail if | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$headers->protocol =~ m[^HTTP/(\d+\.\d+)] and $1 < "1.1"
MC/DC0%0/2
$headers->protocol =~ m[^HTTP/(\d+\.\d+)] and $1 < "1.1"
$headers->protocol =~ m[^HTTP/(\d+\.\d+)]
$1 < "1.1"
Truth table0%0/3
A and B
A= $headers->protocol =~ m[^HTTP/(\d+\.\d+)]B= $1 < "1.1"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | $headers-> protocol =~ /^HTTP\/(\d+\.\d+)/ and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | $1 < 1.1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | # server wants to close the connection | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | return $self-> http_tail if | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | ▶ | $self-> {close_connection}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | # read sequence of TE chunks | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | sub http_read_chunked | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | ▶ | my ( $self, $offset) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
http_read_chunked: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | # read chunk size | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | pos( $self-> {buf} ) = $offset; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | context $self-> http_read( qr/\G[^\r\n]+\r?\n/i); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | state size => tail { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | ▶ | my $line = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | return undef, shift unless defined $line; # got error | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | # advance | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | substr( $self-> {buf}, $offset, length($line), ''); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | pos( $self-> {buf} ) = $offset; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | $line =~ s/\r?\n//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | ▶ | return undef, "protocol error: chunk size error" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | unless $line =~ /^[\da-f]+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | my $size = hex $line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | ▶ | warn "reading chunk $size bytes\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | ▶ | return 1 unless $size; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | $size += 2; # CRLF | |||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | my $frame = restartable; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | # read the chunk itself | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | context $self-> http_read( $offset + $size); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | state chunk => tail { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | return undef, shift unless shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | $offset += $size - 2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | substr( $self->{buf}, $offset, 2, '' ); # remove CRLF | |||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | pos( $self-> {buf} ) = $offset; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | ▶ | warn "chunk $size bytes ok\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | again($frame); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | }}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | sub parse | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | ▶ | my ( $self, $buf_ptr) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | ▶ | return HTTP::Response-> parse( $$buf_ptr) if $$buf_ptr =~ /^(HTTP\S+)\s+(\d{3})\s+/i; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | return HTTP::Response-> new( '000', '', undef, $$buf_ptr); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | __DATA__ | ||||||||||||||||||||||||||||||||||||||||||||||||||