Protocol/http_paranoid.pm

filter: Statementstmt 18.2% 45 / 246 Branchbran 2.7% 4 / 144 Conditioncond 4.0% 2 / 49 MC/DCmcdc 0.0% 0 / 30 Subroutinesub 36.8% 7 / 19 Podpod 33.3% 1 / 3 totaltotal 12.0% 59 / 491 CC 91 SCAR 74.4
CC
91
Cov
12%
request
3024.3
_new_socket
77.7
__ANON__
56.0
CRAP 1706.7
↑ Summary ParanoidAgent.pm »
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
BranchTrueFalseTotal
unless defined $LWPx::Protocol::http_paranoid::TOO_LATE 0 0 0
30 0 $TIME_REMAIN = $TOO_LATE - $now;
31 0 ▶ $TIME_REMAIN = 0 if $TIME_REMAIN < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $LWPx::Protocol::http_paranoid::TIME_REMAIN < 0 0 0 0
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
BranchTrueFalseTotal
if ($conn_cache) 0 1 1
46 0 ▶ if (my $sock = $conn_cache->withdraw("http", "$host:$port")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sock = $conn_cache->withdraw("http", "${host}:$port")) 0 0 0
47 0 ▶ return $sock if $sock && !$sock->can_read(0);
Branch: 1 branch
BranchTrueFalseTotal
if $sock and not $sock->can_read(0) 0 0 0
Condition0%0/3
$sock and not $sock->can_read(0)
!ll&&!rl&&r
000
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)
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless (@addrs) 0 0 0
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
BranchTrueFalseTotal
if (not $sock and @addrs) 0 0 0
Condition0%0/3
not $sock and @addrs
!ll&&!rl&&r
000
MC/DC0%0/2
not $sock and @addrs
not $sock @addrs
Truth table0%0/3
not(A) and B
A= not $sockB= @addrs
ABresult
0X0
100
111
64 0 my $addr = shift @addrs;
65  
66 my $conn_timeout = $request->{_timebegin} ?
67 0 ▶ (time() - $request->{_timebegin}) :
Branch: 1 branch
BranchTrueFalseTotal
$request->{'_timebegin'} ? : 0 0 0
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
BranchTrueFalseTotal
unless ($sock) 0 0 0
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
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if (defined(my $peerhost = $sock->peerhost)) 0 0 0
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
BranchTrueFalseTotal
if ($hhost =~ s/^([^\@]*)\@//) 0 0 0
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
BranchTrueFalseTotal
if (defined $1 and not $h->header("Authorization")) 0 0 0
Condition0%0/3
defined $1 and not $h->header("Authorization")
!ll&&!rl&&r
000
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")
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($i >= 0) 0 0 0
133 0 ▶ next unless lc($hlist->[$i]) eq $k;
Branch: 1 branch
BranchTrueFalseTotal
unless lc $hlist->[$i] eq $k 0 0 0
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
BranchTrueFalseTotal
if ($timeout) 1 0 1
148 1 ▶ my $start_time = $request->{_time_begin} || time();
Condition50%1/2
$request->{'_time_begin'} || time
l!l
10
MC/DC0%0/1
$request->{'_time_begin'} || time
$request->{'_time_begin'}
Truth table50%1/2
A
A= $request->{'_time_begin'}
Aresult
11
00
149 1 $TOO_LATE = $start_time + $timeout;
150 }
151  
152 1 ▶ $size ||= 4096;
Condition50%1/2
$size ||= 4096
l!l
01
MC/DC0%0/1
$size ||= 4096
$size
Truth table50%1/2
A
A= $size
Aresult
11
00
153  
154 # check method
155 1 my $method = $request->method;
156 1 ▶ unless ($method =~ /^[A-Za-z0-9_!\#\$%&\'*+\-.^\`|~]+$/) { # HTTP token
Branch: 1 branch
BranchTrueFalseTotal
unless ($method =~ /^[A-Za-z0-9_!\#\$%&\'*+\-.^\`|~]+$/) 0 1 1
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
BranchTrueFalseTotal
unless $fullpath =~ m[^/] 0 1 1
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
BranchTrueFalseTotal
if ref $$content_ref 0 0 0
187 0 my $chunked;
188 my $has_content;
189  
190 0 ▶ if (ref($content_ref) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $content_ref eq 'CODE') { } 0 0 0
191 0 my $clen = $request_headers->header('Content-Length');
192 0 ▶ $has_content++ if $clen;
Branch: 1 branch
BranchTrueFalseTotal
if $clen 0 0 0
193 0 ▶ unless (defined $clen) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $clen) 0 0 0
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
BranchTrueFalseTotal
if (defined $$content_ref and length $$content_ref) { } 0 0 0
elsif ($clen) { } 0 0 0
Condition0%0/3
defined $$content_ref and length $$content_ref
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
203 0 $has_content++;
204 0 ▶ if (!defined($clen) || $clen ne length($$content_ref)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $clen or $clen ne length $$content_ref) 0 0 0
Condition0%0/3
not defined $clen or $clen ne length $$content_ref
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
205 0 ▶ if (defined $clen) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $clen) 0 0 0
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
BranchTrueFalseTotal
unless defined $n 0 0 0
226 0 ▶ die "short write" unless $n == length($req_buf);
Branch: 1 branch
BranchTrueFalseTotal
unless $n == length $req_buf 0 0 0
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
BranchTrueFalseTotal
if ($has_content) 0 0 0
235 0 my $write_wait = 0;
236 0 ▶ $write_wait = 2
Branch: 1 branch
BranchTrueFalseTotal
if ($request_headers->header("Expect") || "") =~ /100-continue/ 0 0 0
Condition0%0/2
$request_headers->header('Expect') || ''
l!l
00
MC/DC0%0/1
$request_headers->header('Expect') || ''
$request_headers->header('Expect')
Truth table0%0/2
A
A= $request_headers->header('Expect')
Aresult
11
00
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
BranchTrueFalseTotal
if (ref $content_ref eq 'CODE') { } 0 0 0
243 0 my $buf = &$content_ref();
244 0 ▶ $buf = "" unless defined($buf);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $buf 0 0 0
245 0 ▶ $buf = sprintf "%x%s%s%s", length($buf), $CRLF, $buf, $CRLF
Branch: 1 branch
BranchTrueFalseTotal
if $chunked 0 0 0
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
BranchTrueFalseTotal
if ($woffset < length $$wbuf) 0 0 0
258
259 0 my $time_before;
260
261 0 my $now = time();
262 0 ▶ if ($now > $TOO_LATE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($now > $LWPx::Protocol::http_paranoid::TOO_LATE) 0 0 0
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
BranchTrueFalseTotal
if ($write_wait) 0 0 0
268 0 $time_before = time;
269 0 ▶ $sel_timeout = $write_wait if $write_wait < $sel_timeout;
Branch: 1 branch
BranchTrueFalseTotal
if $write_wait < $sel_timeout 0 0 0
270 }
271
272 0 my $rbits = $fbits;
273 0 ▶ my $wbits = $write_wait ? undef : $fbits;
Branch: 1 branch
BranchTrueFalseTotal
$write_wait ? : 0 0 0
274 0 my $nfound = select($rbits, $wbits, undef, $sel_timeout);
275 0 ▶ unless (defined $nfound) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $nfound) 0 0 0
276 0 die "select failed: $!";
277 }
278
279 0 ▶ if ($write_wait) {
Branch: 1 branch
BranchTrueFalseTotal
if ($write_wait) 0 0 0
280 0 $write_wait -= time - $time_before;
281 0 ▶ $write_wait = 0 if $write_wait < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $write_wait < 0 0 0 0
282 }
283
284 0 ▶ if (defined($rbits) && $rbits =~ /[^\0]/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rbits and $rbits =~ /[^\0]/) 0 0 0
Condition0%0/3
defined $rbits and $rbits =~ /[^\0]/
!ll&&!rl&&r
000
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]/
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless ($n) 0 0 0
292 0 die "EOF";
293 }
294 0 $socket->_rbuf($buf);
295 0 ▶ if ($buf =~ /\015?\012\015?\012/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /\015?\012\015?\012/) 0 0 0
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
BranchTrueFalseTotal
if ($code eq '100') { } 0 0 0
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
BranchTrueFalseTotal
if (defined $wbits and $wbits =~ /[^\0]/) 0 0 0
Condition0%0/3
defined $wbits and $wbits =~ /[^\0]/
!ll&&!rl&&r
000
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]/
ABresult
0X0
100
111
312 0 my $n = $socket->syswrite($$wbuf, length($$wbuf), $woffset);
313 0 ▶ unless ($n) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($n) 0 0 0
314 0 ▶ die "syswrite: $!" unless defined $n;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 0 0 0
315 0 die "syswrite: no bytes written";
316 }
317 0 $woffset += $n;
318
319 0 ▶ if (!$eof && $woffset >= length($$wbuf)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $eof and $woffset >= length $$wbuf) 0 0 0
Condition0%0/3
not $eof and $woffset >= length $$wbuf
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
320 # need to refill buffer from $content_ref code
321 0 my $buf = &$content_ref();
322 0 ▶ $buf = "" unless defined($buf);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $buf 0 0 0
323 0 ▶ $eof++ unless length($buf);
Branch: 1 branch
BranchTrueFalseTotal
unless length $buf 0 0 0
324 0 ▶ $buf = sprintf "%x%s%s%s", length($buf), $CRLF, $buf, $CRLF
Branch: 1 branch
BranchTrueFalseTotal
if $chunked 0 0 0
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
BranchTrueFalseTotal
unless $nfound 0 0 0
341  
342 0 _set_time_remain();
343  
344 0 ▶ ($code, $mess, @h) = $socket->read_response_headers(laxed => 1, junk_out => \@junk)
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 0 0
345 unless $code;
346 0 ▶ ($code, $mess, @h) = $socket->read_response_headers(laxed => 1, junk_out => \@junk)
Branch: 1 branch
BranchTrueFalseTotal
if $code eq 100 0 0 0
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
BranchTrueFalseTotal
if (@h) 0 0 0
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
BranchTrueFalseTotal
if @junk 0 0 0
357  
358 0 $response->request($request);
359 0 $self->_get_sock_info($response, $socket);
360  
361 0 ▶ if ($method eq "CONNECT") {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "CONNECT") 0 0 0
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
BranchTrueFalseTotal
if (my(@te) = $response->remove_header("Transfer-Encoding")) 0 0 0
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
BranchTrueFalseTotal
if not defined $n and $! == 11 0 0 0
Condition0%0/3
not defined $n and $! == 11
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
380 0 ▶ redo READ if $n == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $n == -1 0 0 0
381 0 ▶ die "Can't read entity body: $!" unless defined $n;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 0 0 0
382 0 ▶ die 'read timeout' unless($TIME_REMAIN - 1);
Branch: 1 branch
BranchTrueFalseTotal
unless $LWPx::Protocol::http_paranoid::TIME_REMAIN - 1 0 0 0
383 }
384 0 ▶ $complete++ if !$n;
Branch: 1 branch
BranchTrueFalseTotal
unless $n 0 0 0
385 0 return \$buf;
386 0 } );
387 0 ▶ $drop_connection++ unless $complete;
Branch: 1 branch
BranchTrueFalseTotal
unless $complete 0 0 0
388  
389 0 _set_time_remain();
390 0 @h = $socket->get_trailers;
391 0 ▶ while (@h) {
Branch: 1 branch
BranchTrueFalseTotal
if (@h) 0 0 0
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
BranchTrueFalseTotal
unless ($drop_connection) 0 0 0
398 0 ▶ if (my $conn_cache = $self->{ua}{conn_cache}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $conn_cache = $self->{"ua"}{"conn_cache"}) 0 0 0
399 0 ▶ my %connection = map { (lc($_) => 1) }
Condition0%0/2
$response->header('Connection') || ''
l!l
00
MC/DC0%0/1
$response->header('Connection') || ''
$response->header('Connection')
Truth table0%0/2
A
A= $response->header('Connection')
Aresult
11
00
400 split(/\s*,\s*/, ($response->header("Connection") || ""));
401 0 ▶ if (($peer_http_version eq "1.1" && !$connection{close}) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($peer_http_version eq "1.1" and not $connection{"close"} or $connection{"keep-alive"}) 0 0 0
Condition0%0/6
$peer_http_version eq "1.1" and not $connection{"close"} or $connection{"keep-alive"}
l!l&&r!l&&!r
000
$peer_http_version eq "1.1" and not $connection{"close"}
!ll&&!rl&&r
000
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"}
ABCresult
11X1
0X11
1011
0X00
1000
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
BranchTrueFalseTotal
if (defined $timeout) { } 0 0 0
422 0 ▶ die "read timeout" unless $self->can_read($timeout);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can_read($timeout) 0 0 0
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
BranchTrueFalseTotal
$self->can_read(undef) or die "Assert" 0 0 0
428 }
429 0 ▶ sysread($self, $_[0], $_[1], $_[2] || 0);
Condition0%0/2
$_[2] || 0
l!l
00
MC/DC0%0/1
$_[2] || 0
$_[2]
Truth table0%0/2
A
A= $_[2]
Aresult
11
00
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
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless defined $nfound 0 0 0
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;
↑ Summary ParanoidAgent.pm »