| 1 | # $Id: http_paranoid.pm 2 2005-06-01 23:12:25Z bradfitz $ | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | package LWPx::Protocol::http_paranoid; | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | require LWP::Debug; | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | require HTTP::Response; | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | require HTTP::Status; | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | require Net::HTTP; | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Errno qw(EAGAIN); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use vars qw(@ISA $TOO_LATE $TIME_REMAIN); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | require LWP::Protocol; | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | @ISA = qw(LWP::Protocol); | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use vars qw(@ISA @EXTRA_SOCK_OPTS); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | my $CRLF = "\015\012"; | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # lame hack using globals in this package to communicate to sysread in the | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # package at bottom, but whatchya gonna do? Don't want to go modify | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # Net::HTTP::* to pass explicit timeouts to all the sysreads. | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub _set_time_remain { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_time_remain: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my $now = time; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | return unless defined $TOO_LATE; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | $TIME_REMAIN = $TOO_LATE - $now; | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | $TIME_REMAIN = 0 if $TIME_REMAIN < 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | sub _extra_sock_opts # to be overridden by subclass | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extra_sock_opts: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | return @EXTRA_SOCK_OPTS; | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | sub _new_socket | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_socket: called CC=10 SCAR=43.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | my($self, $host, $port, $timeout, $request) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | my $conn_cache = $self->{ua}{conn_cache}; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | if ($conn_cache) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if (my $sock = $conn_cache->withdraw("http", "$host:$port")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | return $sock if $sock && !$sock->can_read(0); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$sock and not $sock->can_read(0)
MC/DC0%0/2
$sock and not $sock->can_read(0)
$sock
not $sock->can_read(0)
Truth table0%0/3
A and not(B)
A= $sockB= not $sock->can_read(0)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # if the socket is readable, then either the peer has closed the | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # connection or there are some garbage bytes on it. In either | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # case we abandon it. | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $sock->close; | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | my @addrs = $self->{ua}->_resolve($host, $request, $timeout); | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | unless (@addrs) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | die "Can't connect to $host:$port (No suitable addresses found)"; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $sock; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | local($^W) = 0; # IO::Socket::INET can be noisy | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | while (! $sock && @addrs) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $sock and @addrs
MC/DC0%0/2
not $sock and @addrs
not $sock
@addrs
Truth table0%0/3
not(A) and B
A= not $sockB= @addrs
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $addr = shift @addrs; | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | my $conn_timeout = $request->{_timebegin} ? | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | (time() - $request->{_timebegin}) : | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | $timeout; | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $sock = $self->socket_class->new(PeerAddr => $addr, | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | PeerHost => $host, | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | SSL_hostname => $host, | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | PeerPort => $port, | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | Proto => 'tcp', | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | Timeout => $conn_timeout, | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | KeepAlive => !!$conn_cache, | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | SendTE => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | $self->_extra_sock_opts($addr,$port), | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | unless ($sock) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # IO::Socket::INET leaves additional error messages in $@ | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $@ =~ s/^.*?: //; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | die "Can't connect to $host:$port ($@)"; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # perl 5.005's IO::Socket does not have the blocking method. | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | eval { $sock->blocking(0); }; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $sock; | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | sub socket_class | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
socket_class: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | (ref($self) || $self) . "::Socket"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table0%0/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | sub _get_sock_info | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_sock_info: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my($self, $res, $sock) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if (defined(my $peerhost = $sock->peerhost)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $res->header("Client-Peer" => "$peerhost:" . $sock->peerport); | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | sub _fixup_header | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fixup_header: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my($self, $h, $url, $proxy) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # Extract 'Host' header | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $hhost = $url->authority; | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ($hhost =~ s/^([^\@]*)\@//) { # get rid of potential "user:pass@" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # add authorization header if we need them. HTTP URLs do | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # not really support specification of user and password, but | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # we allow it. | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | if (defined($1) && not $h->header('Authorization')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $1 and not $h->header("Authorization")
MC/DC0%0/2
defined $1 and not $h->header("Authorization")
defined $1
not $h->header("Authorization")
Truth table0%0/3
A and not(B)
A= defined $1B= not $h->header("Authorization")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | require URI::Escape; | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $h->authorization_basic(map URI::Escape::uri_unescape($_), | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | split(":", $1, 2)); | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $h->init_header('Host' => $hhost); | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub hlist_remove { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hlist_remove: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my($hlist, $k) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $k = lc $k; | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | for (my $i = @$hlist - 2; $i >= 0; $i -= 2) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | next unless lc($hlist->[$i]) eq $k; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | splice(@$hlist, $i, 2); | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | sub request | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request: called CC=61 SCAR=80.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | my($self, $request, $proxy, $arg, $size, $timeout) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | LWP::Debug::trace('()'); | |||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # paranoid: now $timeout means total time, not just between bytes coming in. | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # avoids attacker servers from tarpitting a service that fetches URLs. | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | $TOO_LATE = undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | $TIME_REMAIN = undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | ▶ | if ($timeout) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | ▶ | my $start_time = $request->{_time_begin} || time(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$request->{'_time_begin'} || time
MC/DC0%0/1
$request->{'_time_begin'} || time
$request->{'_time_begin'}
Truth table50%1/2
A
A= $request->{'_time_begin'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | $TOO_LATE = $start_time + $timeout; | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | ▶ | $size ||= 4096; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$size ||= 4096
MC/DC0%0/1
$size ||= 4096
$size
Truth table50%1/2
A
A= $size
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # check method | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | my $method = $request->method; | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | ▶ | unless ($method =~ /^[A-Za-z0-9_!\#\$%&\'*+\-.^\`|~]+$/) { # HTTP token | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST, | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | 'Library does not allow method ' . | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | "$method for 'http:' URLs"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | my $url = $request->url; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | my($host, $port, $fullpath); | |||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | $host = $url->host; | |||||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | $port = $url->port; | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | $fullpath = $url->path_query; | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | ▶ | $fullpath = "/$fullpath" unless $fullpath =~ m,^/,; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # connect to remote sites | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | my $socket = $self->_new_socket($host, $port, $timeout, $request); | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | my @h; | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | my $request_headers = $request->headers->clone; | |||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $self->_fixup_header($request_headers, $url, $proxy); | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | $request_headers->scan(sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my($k, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $k =~ s/^://; | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $v =~ s/\n/ /g; | |||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | push(@h, $k, $v); | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my $content_ref = $request->content_ref; | |||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | $content_ref = $$content_ref if ref($$content_ref); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $chunked; | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | my $has_content; | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | if (ref($content_ref) eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | my $clen = $request_headers->header('Content-Length'); | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | $has_content++ if $clen; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | unless (defined $clen) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | push(@h, "Transfer-Encoding" => "chunked"); | |||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $has_content++; | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | $chunked++; | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # Set (or override) Content-Length header | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my $clen = $request_headers->header('Content-Length'); | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if (defined($$content_ref) && length($$content_ref)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
defined $$content_ref and length $$content_ref
MC/DC0%0/2
defined $$content_ref and length $$content_ref
defined $$content_ref
length $$content_ref
Truth table0%0/3
A and B
A= defined $$content_refB= length $$content_ref
| |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $has_content++; | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | if (!defined($clen) || $clen ne length($$content_ref)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $clen or $clen ne length $$content_ref
MC/DC0%0/2
not defined $clen or $clen ne length $$content_ref
not defined $clen
$clen ne length $$content_ref
Truth table0%0/3
not(A) or B
A= not defined $clenB= $clen ne length $$content_ref
| |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | if (defined $clen) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | warn "Content-Length header value was wrong, fixed"; | |||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | hlist_remove(\@h, 'Content-Length'); | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | push(@h, 'Content-Length' => length($$content_ref)); | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | elsif ($clen) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | warn "Content-Length set when there is not content, fixed"; | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | hlist_remove(\@h, 'Content-Length'); | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | my $req_buf = $socket->format_request($method, $fullpath, @h); | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | #print "------\n$req_buf\n------\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # XXX need to watch out for write timeouts | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # FIXME_BRAD: make it non-blocking and select during the write | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my $n = $socket->syswrite($req_buf, length($req_buf)); | |||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | die $! unless defined($n); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | die "short write" unless $n == length($req_buf); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | #LWP::Debug::conns($req_buf); | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my($code, $mess, @junk); | |||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $drop_connection; | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | if ($has_content) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my $write_wait = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | $write_wait = 2 | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$request_headers->header('Expect') || ''
MC/DC0%0/1
$request_headers->header('Expect') || ''
$request_headers->header('Expect')
Truth table0%0/2
A
A= $request_headers->header('Expect')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | if ($request_headers->header("Expect") || "") =~ /100-continue/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my $eof; | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | my $wbuf; | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | my $woffset = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | if (ref($content_ref) eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | my $buf = &$content_ref(); | |||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | $buf = "" unless defined($buf); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | $buf = sprintf "%x%s%s%s", length($buf), $CRLF, $buf, $CRLF | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | if $chunked; | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $wbuf = \$buf; | |||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 249 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | $wbuf = $content_ref; | |||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | $eof = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | my $fbits = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | vec($fbits, fileno($socket), 1) = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | while ($woffset < length($$wbuf)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | my $time_before; | |||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | my $now = time(); | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | if ($now > $TOO_LATE) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | die "Request took too long."; | |||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | my $sel_timeout = $TOO_LATE - $now; | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | if ($write_wait) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | $time_before = time; | |||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | $sel_timeout = $write_wait if $write_wait < $sel_timeout; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my $rbits = $fbits; | |||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | my $wbits = $write_wait ? undef : $fbits; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my $nfound = select($rbits, $wbits, undef, $sel_timeout); | |||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | unless (defined $nfound) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | die "select failed: $!"; | |||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | if ($write_wait) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $write_wait -= time - $time_before; | |||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | $write_wait = 0 if $write_wait < 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | if (defined($rbits) && $rbits =~ /[^\0]/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $rbits and $rbits =~ /[^\0]/
MC/DC0%0/2
defined $rbits and $rbits =~ /[^\0]/
defined $rbits
$rbits =~ /[^\0]/
Truth table0%0/3
A and B
A= defined $rbitsB= $rbits =~ /[^\0]/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # readable | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my $buf = $socket->_rbuf; | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | _set_time_remain(); | |||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | my $n = $socket->sysread($buf, 1024, length($buf)); | |||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | unless ($n) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | die "EOF"; | |||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | $socket->_rbuf($buf); | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | if ($buf =~ /\015?\012\015?\012/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # a whole response present | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ($code, $mess, @h) = $socket->read_response_headers(laxed => 1, | |||||||||||||||||||||||||||||||||||||||||||||
| 298 | junk_out => \@junk, | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | if ($code eq "100") { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | $write_wait = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | undef($code); | |||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | $drop_connection++; | |||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||
| 307 | # XXX should perhaps try to abort write in a nice way too | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | if (defined($wbits) && $wbits =~ /[^\0]/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $wbits and $wbits =~ /[^\0]/
MC/DC0%0/2
defined $wbits and $wbits =~ /[^\0]/
defined $wbits
$wbits =~ /[^\0]/
Truth table0%0/3
A and B
A= defined $wbitsB= $wbits =~ /[^\0]/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | my $n = $socket->syswrite($$wbuf, length($$wbuf), $woffset); | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | unless ($n) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | die "syswrite: $!" unless defined $n; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | die "syswrite: no bytes written"; | |||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | $woffset += $n; | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | if (!$eof && $woffset >= length($$wbuf)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $eof and $woffset >= length $$wbuf
MC/DC0%0/2
not $eof and $woffset >= length $$wbuf
not $eof
$woffset >= length $$wbuf
Truth table0%0/3
not(A) and B
A= not $eofB= $woffset >= length $$wbuf
| |||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # need to refill buffer from $content_ref code | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | my $buf = &$content_ref(); | |||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | $buf = "" unless defined($buf); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | $eof++ unless length($buf); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | $buf = sprintf "%x%s%s%s", length($buf), $CRLF, $buf, $CRLF | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | if $chunked; | ||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | $wbuf = \$buf; | |||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | $woffset = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | _set_time_remain(); | |||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | ## Now we connected to host | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | ## Check host started to send any data in return | ||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | my $rbits = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | vec($rbits, fileno($socket), 1) = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | my $nfound = select($rbits, undef, undef, $TIME_REMAIN); | |||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | die "Headers not came for $TIME_REMAIN sec" unless $nfound; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | _set_time_remain(); | |||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | ($code, $mess, @h) = $socket->read_response_headers(laxed => 1, junk_out => \@junk) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | unless $code; | ||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | ($code, $mess, @h) = $socket->read_response_headers(laxed => 1, junk_out => \@junk) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 347 | if $code eq "100"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | my $response = HTTP::Response->new($code, $mess); | |||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my $peer_http_version = $socket->peer_http_version; | |||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | $response->protocol("HTTP/$peer_http_version"); | |||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | while (@h) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | my($k, $v) = splice(@h, 0, 2); | |||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | $response->push_header($k, $v); | |||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | $response->push_header("Client-Junk" => \@junk) if @junk; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | $response->request($request); | |||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | $self->_get_sock_info($response, $socket); | |||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | if ($method eq "CONNECT") { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $response->{client_socket} = $socket; # so it can be picked up | |||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | return $response; | |||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | if (my @te = $response->remove_header('Transfer-Encoding')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | $response->push_header('Client-Transfer-Encoding', \@te); | |||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | $response->push_header('Client-Response-Num', $socket->increment_response_count); | |||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | my $complete; | |||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | $response = $self->collect($arg, $response, sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | my $buf = ""; #prevent use of uninitialized value in SSLeay.xs | |||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | my $n; | |||||||||||||||||||||||||||||||||||||||||||||
| 375 | READ: | ||||||||||||||||||||||||||||||||||||||||||||||
| 376 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | _set_time_remain(); | |||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | $n = $socket->read_entity_body($buf, $size); | |||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | redo READ if not defined $n and $! == EAGAIN; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $n and $! == 11
MC/DC0%0/2
not defined $n and $! == 11
not defined $n
$! == 11
Truth table0%0/3
not(A) and B
A= not defined $nB= $! == 11
| |||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | redo READ if $n == -1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | die "Can't read entity body: $!" unless defined $n; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | die 'read timeout' unless($TIME_REMAIN - 1); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | $complete++ if !$n; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | return \$buf; | |||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | } ); | |||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | $drop_connection++ unless $complete; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | _set_time_remain(); | |||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | @h = $socket->get_trailers; | |||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | while (@h) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | my($k, $v) = splice(@h, 0, 2); | |||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $response->push_header($k, $v); | |||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # keep-alive support | ||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | unless ($drop_connection) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | if (my $conn_cache = $self->{ua}{conn_cache}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | my %connection = map { (lc($_) => 1) } | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$response->header('Connection') || ''
MC/DC0%0/1
$response->header('Connection') || ''
$response->header('Connection')
Truth table0%0/2
A
A= $response->header('Connection')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | split(/\s*,\s*/, ($response->header("Connection") || "")); | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | if (($peer_http_version eq "1.1" && !$connection{close}) || | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$peer_http_version eq "1.1" and not $connection{"close"} or $connection{"keep-alive"}
$peer_http_version eq "1.1" and not $connection{"close"}
MC/DC0%0/3
$peer_http_version eq "1.1" and not $connection{"close"} or $connection{"keep-alive"}
$peer_http_version eq "1.1"
not $connection{"close"}
$connection{"keep-alive"}
Truth table0%0/5
A and not(B) or C
A= $peer_http_version eq "1.1"B= not $connection{"close"}C= $connection{"keep-alive"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 402 | $connection{"keep-alive"}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 403 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | LWP::Debug::debug("Keep the http connection to $host:$port"); | |||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | $conn_cache->deposit("http", "$host:$port", $socket); | |||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | $response; | |||||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||
| 414 | #----------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 415 | package LWPx::Protocol::http_paranoid::SocketMethods; | ||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | ▶ | sub sysread { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sysread: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | my $timeout = $LWPx::Protocol::http_paranoid::TIME_REMAIN; | |||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | if (defined $timeout) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | die "read timeout" unless $self->can_read($timeout); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 424 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # since we have made the socket non-blocking we | ||||||||||||||||||||||||||||||||||||||||||||||
| 426 | # use select to wait for some data to arrive | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | $self->can_read(undef) || die "Assert"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | ▶ | sysread($self, $_[0], $_[1], $_[2] || 0); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$_[2] || 0
MC/DC0%0/1
$_[2] || 0
$_[2]
Truth table0%0/2
A
A= $_[2]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | sub can_read { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can_read: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | my($self, $timeout) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | $timeout ||= $LWPx::Protocol::http_paranoid::TIME_REMAIN; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$timeout ||= $LWPx::Protocol::http_paranoid::TIME_REMAIN
MC/DC0%0/2
$timeout ||= $LWPx::Protocol::http_paranoid::TIME_REMAIN
$timeout
$LWPx::Protocol::http_paranoid::TIME_REMAIN
Truth table0%0/3
A ||= B
A= $timeoutB= $LWPx::Protocol::http_paranoid::TIME_REMAIN
| |||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | my $fbits = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | vec($fbits, fileno($self), 1) = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | my $nfound = select($fbits, undef, undef, $timeout); | |||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | die "select failed: $!" unless defined $nfound; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | return $nfound > 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | sub ping { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ping: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | !$self->can_read(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | sub increment_response_count { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
increment_response_count: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | return ++${*$self}{'myhttp_response_count'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||
| 453 | #----------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 454 | package LWPx::Protocol::http_paranoid::Socket; | ||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 1 | ▶ | use vars qw(@ISA); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 1 | @ISA = qw(LWPx::Protocol::http_paranoid::SocketMethods Net::HTTP); | |||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||