blib/lib/LWP/Protocol/UWSGI.pm

filter: Statementstmt 12.2% 28 / 228 Branchbran 0.0% 0 / 138 Conditioncond 0.0% 0 / 61 MC/DCmcdc 0.0% 0 / 34 Subroutinesub 61.5% 8 / 13 Podpod 100% 1 / 1 totaltotal 7.7% 37 / 475 SCAR 88.7
CC
93
Cov
7%
request
7482.0
__ANON__
72.0
__ANON__
2.0
CRAP 7149.7
↑ Summary
1 package LWP::Protocol::UWSGI;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use version; our $VERSION = qv('v1.1.4');
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use HTTP::Response qw( );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use LWP::Protocol::http qw( );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use base qw/LWP::Protocol::http/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 LWP::Protocol::implementor($_, __PACKAGE__) for qw( uwsgi );
15  
16 1 our $CRLF = $LWP::Protocol::http::CRLF;
17  
18 =head1 NAME
19  
20 LWP::Protocol::UWSGI - uwsgi support for LWP
21  
22 =head1 SYNOPSIS
23  
24 use LWP::Protocol::UWSGI;
25 use LWP::UserAgent;
26 $res = $ua->get("uwsgi://www.example.com");
27  
28 =head1 DESCRIPTION
29  
30 The LWP::Protocol::UWSGI module provide support for using uwsgi
31 protocol with LWP.
32  
33 This module unbundled with the libwww-perl.
34  
35 =head1 SEE ALSO
36  
37 L<LWP::UserAgent>, L<LWP::Protocol>
38  
39 =head1 COPYRIGHT
40  
41 Copyright 2015 Nikolas Shulyakovskiy.
42  
43 This library is free software; you can redistribute it and/or
44 modify it under the same terms as Perl itself.
45  
46 =cut
47  
48 sub request {
49 0 ▶ my($self, $request, $proxy, $arg, $size, $timeout) = @_;
Subroutine request: not called CC=86 SCAR=89.2
Pod documented
50  
51 0 ▶ $size ||= 4096;
Condition0%0/2
$size ||= 4096
l!l
00
MC/DC0%0/1
$size ||= 4096
$size
Truth table0%0/2
A
A= $size
Aresult
11
00
52  
53 # check method
54 0 my $method = $request->method;
55 0 ▶ unless ($method =~ /^[A-Za-z0-9_!\#\$%&\'*+\-.^\`|~]+$/) { # HTTP token
Branch: 1 branch
BranchTrueFalseTotal
unless ($method =~ /^[A-Za-z0-9_!\#\$%&\'*+\-.^\`|~]+$/) 0 0 0
56 0 return HTTP::Response->new( &HTTP::Status::RC_BAD_REQUEST,
57 'Library does not allow method ' .
58 "$method for 'uwsgi:' URLs");
59 }
60  
61 0 my $url = $request->uri;
62 0 ▶ unless($$url =~ m,^uwsgi://([^/?\#:]+)(?:\:(\d+))/,){
Branch: 1 branch
BranchTrueFalseTotal
unless ($$url =~ m[^uwsgi://([^/?\#:]+)(?:\:(\d+))/]) 0 0 0
63 0 return HTTP::Response->new( &HTTP::Status::RC_BAD_REQUEST,
64 'Library does not allow this host ' .
65 "$$url for 'uwsgi:' URLs");
66 }
67 0 ▶ my ($host,$port) = $proxy
Branch: 1 branch
BranchTrueFalseTotal
$proxy ? : 0 0 0
68 ? ($proxy->host,$proxy->port)
69 : ($1,$2);
70 my $fullpath =
71 $method eq 'CONNECT'
72 ? $url->host . ":" . $url->port
73 : $proxy
74 ? $url->as_string
75 0 ▶ : do {
Branch: 2 branches
BranchTrueFalseTotal
$method eq 'CONNECT' ? : 0 0 0
$proxy ? : 0 0 0
76 0 my $path = $url->path_query;
77 0 ▶ $path = "/$path" if $path !~m{^/};
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ m[^/] 0 0 0
78 0 $path
79 };
80  
81 0 my $socket;
82 0 my $conn_cache = $self->{ua}{conn_cache};
83 0 my $cache_key;
84 0 ▶ if ( $conn_cache ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conn_cache) 0 0 0
85 0 $cache_key = "$host:$port";
86 0 ▶ if ( $socket = $conn_cache->withdraw($self->socket_type,$cache_key)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($socket = $conn_cache->withdraw($self->socket_type, $cache_key)) 0 0 0
87 0 ▶ if ($socket->can_read(0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($socket->can_read(0)) 0 0 0
88 # if the socket is readable, then either the peer has closed the
89 # connection or there are some garbage bytes on it. In either
90 # case we abandon it.
91 0 $socket->close;
92 0 $socket = undef;
93 } # else use $socket
94 }
95 }
96  
97 0 ▶ if ( ! $socket ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($socket) 0 0 0
98 # connect to remote site w/o reusing established socket
99 0 $socket = $self->_new_socket($host, $port, $timeout );
100 }
101  
102 0 $self->_check_sock($request, $socket);
103  
104 0 my %h;
105 0 my $request_headers = $request->headers->clone;
106 0 $self->_fixup_header($request_headers, $url, $proxy);
107  
108 $request_headers->scan(sub {
109 0 ▶ my($k, $v) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
110 0 $k =~ s/^://;
111 0 $v =~ s/\n/ /g;
112 0 $h{$k}=$v;
113 0 });
114  
115 0 my $content_ref = $request->content_ref;
116 0 ▶ $content_ref = $$content_ref if ref($$content_ref);
Branch: 1 branch
BranchTrueFalseTotal
if ref $$content_ref 0 0 0
117 0 my $chunked;
118 my $has_content;
119  
120 0 ▶ if (ref($content_ref) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $content_ref eq 'CODE') { } 0 0 0
121 0 my $clen = $request_headers->header('Content-Length');
122 0 ▶ $has_content++ if $clen;
Branch: 1 branch
BranchTrueFalseTotal
if $clen 0 0 0
123 0 ▶ unless (defined $clen) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $clen) 0 0 0
124 0 $h{"Transfer-Encoding"} = "chunked";
125 0 $has_content++;
126 0 $chunked++;
127 }
128 }
129 else {
130 # Set (or override) Content-Length header
131 0 my $clen = $request_headers->header('Content-Length');
132 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
133 0 $has_content = length($$content_ref);
134 0 ▶ if (!defined($clen) || $clen ne $has_content) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $clen or $clen ne $has_content) 0 0 0
Condition0%0/3
not defined $clen or $clen ne $has_content
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $clen or $clen ne $has_content
not defined $clen $clen ne $has_content
Truth table0%0/3
not(A) or B
A= not defined $clenB= $clen ne $has_content
ABresult
1X1
011
000
135 0 ▶ if (defined $clen) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $clen) 0 0 0
136 0 warn "Content-Length header value was wrong, fixed";
137 0 delete $h{'Content-Length'};
138 }
139 0 $h{'Content-Length'} = $has_content;
140 }
141 }
142 elsif ($clen) {
143 0 warn "Content-Length set when there is no content, fixed";
144 0 delete $h{'Content-Length'};
145 }
146 }
147  
148 0 my $env = {};
149 0 ▶ $env->{QUERY_STRING} = $fullpath =~ m,^[^?]+\?(.+)$, ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$fullpath =~ /^[^?]+\?(.+)$/ ? : 0 0 0
150 0 $env->{REQUEST_METHOD} = $method;
151 0 ▶ $env->{CONTENT_LENGTH} = defined $request_headers->header('Content-Length') ? $request_headers->header('Content-Length') : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $request_headers->header('Content-Length') ? : 0 0 0
152 0 ▶ $env->{CONTENT_TYPE} = $method =~ /post/i ? 'application/x-www-form-urlencoded' : '';
Branch: 1 branch
BranchTrueFalseTotal
$method =~ /post/i ? : 0 0 0
153 0 $env->{REQUEST_URI} = $fullpath;
154 0 $env->{PATH_INFO} = $url->path;
155 0 $env->{SERVER_PROTOCOL}= 'HTTP/1.1';
156 0 $env->{REMOTE_ADDR} = $socket->sockhost;
157 0 $env->{REMOTE_PORT} = $socket->sockport;
158 0 $env->{SERVER_PORT} = $port;
159 0 $env->{SERVER_NAME} = $host;
160
161 0 foreach my $k (keys %h) {
162 0 (my $env_k = uc $k) =~ tr/-/_/;
163 0 ▶ $env->{"HTTP_$env_k"} = defined $h{$k} ? $h{$k} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $h{$k} ? : 0 0 0
164 }
165  
166 0 my $data = '';
167 0 foreach my $k (sort keys %$env) {
168 0 ▶ die "Undef value found for $k" unless defined $env->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $env->{$k} 0 0 0
169 0 $data .= pack 'v/a*v/a*', map { Encode::encode('utf8', $_) } $k, $env->{$k};
170 }
171  
172 0 my $req_buf = pack('C1v1C1',
173 5, # PSGI_MODIFIER1,
174 length($data),
175 0, # PSGI_MODIFIER2,
176 ) . $data;
177  
178 0 ▶ if (!$has_content || $has_content > 8*1024) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $has_content or $has_content > 8192) 0 0 0
Condition0%0/3
not $has_content or $has_content > 8192
l!l&&r!l&&!r
000
MC/DC0%0/2
not $has_content or $has_content > 8192
not $has_content $has_content > 8192
Truth table0%0/3
not(A) or B
A= not $has_contentB= $has_content > 8192
ABresult
1X1
011
000
179 WRITE:
180 {
181 # Since this just writes out the header block it should almost
182 # always succeed to send the whole buffer in a single write call.
183 0 my $n = $socket->syswrite($req_buf, length($req_buf));
184 0 ▶ unless (defined $n) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $n) 0 0 0
185 0 ▶ redo WRITE if $!{EINTR};
Branch: 1 branch
BranchTrueFalseTotal
if $!{"EINTR"} 0 0 0
186 0 ▶ if ($!{EWOULDBLOCK} || $!{EAGAIN}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($!{"EWOULDBLOCK"} or $!{"EAGAIN"}) 0 0 0
Condition0%0/3
$!{"EWOULDBLOCK"} or $!{"EAGAIN"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$!{"EWOULDBLOCK"} or $!{"EAGAIN"}
$!{"EWOULDBLOCK"} $!{"EAGAIN"}
Truth table0%0/3
A or B
A= $!{"EWOULDBLOCK"}B= $!{"EAGAIN"}
ABresult
1X1
011
000
187 0 select(undef, undef, undef, 0.1);
188 0 redo WRITE;
189 }
190 0 die "write failed: $!";
191 }
192 0 ▶ if ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) { } 0 0 0
193 0 substr($req_buf, 0, $n, "");
194 }
195 else {
196 0 select(undef, undef, undef, 0.5);
197 }
198 0 ▶ redo WRITE if length $req_buf;
Branch: 1 branch
BranchTrueFalseTotal
if length $req_buf 0 0 0
199 }
200 }
201  
202 0 my($code, $mess, @junk);
203 0 my $drop_connection;
204  
205 0 ▶ if ($has_content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_content) 0 0 0
206 0 my $eof;
207 my $wbuf;
208 0 my $woffset = 0;
209 INITIAL_READ:
210 0 ▶ if (ref($content_ref) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $content_ref eq 'CODE') { } 0 0 0
211 0 my $buf = &$content_ref();
212 0 ▶ $buf = "" unless defined($buf);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $buf 0 0 0
213 0 ▶ $buf = sprintf "%x%s%s%s", length($buf), $CRLF, $buf, $CRLF
Branch: 1 branch
BranchTrueFalseTotal
if $chunked 0 0 0
214 if $chunked;
215 0 ▶ substr($buf, 0, 0) = $req_buf if $req_buf;
Branch: 1 branch
BranchTrueFalseTotal
if $req_buf 0 0 0
216 0 $wbuf = \$buf;
217 }
218 else {
219 0 ▶ if ($req_buf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req_buf) { } 0 0 0
220 0 my $buf = $req_buf . $$content_ref;
221 0 $wbuf = \$buf;
222 }
223 else {
224 0 $wbuf = $content_ref;
225 }
226 0 $eof = 1;
227 }
228  
229 0 my $fbits = '';
230 0 vec($fbits, fileno($socket), 1) = 1;
231  
232 WRITE:
233 0 ▶ while ($woffset < length($$wbuf)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($woffset < length $$wbuf) 0 0 0
234 0 my $sel_timeout = $timeout;
235 0 my $time_before;
236 0 ▶ $time_before = time if $sel_timeout;
Branch: 1 branch
BranchTrueFalseTotal
if $sel_timeout 0 0 0
237  
238 0 my $rbits = $fbits;
239 0 my $wbits = $fbits;
240 0 my $sel_timeout_before = $sel_timeout;
241 SELECT:
242 {
243 0 my $nfound = select($rbits, $wbits, undef, $sel_timeout);
244 0 ▶ if ($nfound < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nfound < 0) 0 0 0
245 0 ▶ if ($!{EINTR} || $!{EWOULDBLOCK} || $!{EAGAIN}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"}) 0 0 0
Condition0%0/6
$!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"}
l!l&&r!l&&!r
000
$!{"EINTR"} or $!{"EWOULDBLOCK"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"}
$!{"EINTR"} $!{"EWOULDBLOCK"} $!{"EAGAIN"}
Truth table0%0/4
A or B or C
A= $!{"EINTR"}B= $!{"EWOULDBLOCK"}C= $!{"EAGAIN"}
ABCresult
1XX1
01X1
0011
0000
246 0 ▶ if ($time_before) {
Branch: 1 branch
BranchTrueFalseTotal
if ($time_before) 0 0 0
247 0 $sel_timeout = $sel_timeout_before - (time - $time_before);
248 0 ▶ $sel_timeout = 0 if $sel_timeout < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $sel_timeout < 0 0 0 0
249 }
250 0 redo SELECT;
251 }
252 0 die "select failed: $!";
253 }
254 }
255  
256 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
257 # readable
258 0 my $buf = $socket->_rbuf;
259 0 my $n = $socket->sysread($buf, 1024, length($buf));
260 0 ▶ unless (defined $n) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $n) { } 0 0 0
(do { $n == 0 }) 0 0 0
261 0 ▶ die "read failed: $!" unless $!{EINTR} || $!{EWOULDBLOCK} || $!{EAGAIN};
Branch: 1 branch
BranchTrueFalseTotal
unless $!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"} 0 0 0
Condition0%0/6
$!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"}
l!l&&r!l&&!r
000
$!{"EINTR"} or $!{"EWOULDBLOCK"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"}
$!{"EINTR"} $!{"EWOULDBLOCK"} $!{"EAGAIN"}
Truth table0%0/4
A or B or C
A= $!{"EINTR"}B= $!{"EWOULDBLOCK"}C= $!{"EAGAIN"}
ABCresult
1XX1
01X1
0011
0000
262 # if we get here the rest of the block will do nothing
263 # and we will retry the read on the next round
264 }
265 0 elsif ($n == 0) {
266 # the server closed the connection before we finished
267 # writing all the request content. No need to write any more.
268 0 $drop_connection++;
269 0 last WRITE;
270 }
271 0 $socket->_rbuf($buf);
272 0 my @h;
273 0 ▶ if (!$code && $buf =~ /\015?\012\015?\012/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $code and $buf =~ /\015?\012\015?\012/) 0 0 0
Condition0%0/3
not $code and $buf =~ /\015?\012\015?\012/
!ll&&!rl&&r
000
MC/DC0%0/2
not $code and $buf =~ /\015?\012\015?\012/
not $code $buf =~ /\015?\012\015?\012/
Truth table0%0/3
not(A) and B
A= not $codeB= $buf =~ /\015?\012\015?\012/
ABresult
0X0
100
111
274 # a whole response header is present, so we can read it without blocking
275 0 ($code, $mess, @h) = $socket->read_response_headers( laxed => 1, junk_out => \@junk );
276 0 ▶ if ($code eq "100") {
Branch: 1 branch
BranchTrueFalseTotal
if ($code eq '100') { } 0 0 0
277 0 undef($code);
278 0 goto INITIAL_READ;
279 }
280 else {
281 0 $drop_connection++;
282 0 last WRITE;
283 # XXX should perhaps try to abort write in a nice way too
284 }
285 }
286 }
287 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
288 0 my $n = $socket->syswrite($$wbuf, length($$wbuf), $woffset);
289 0 ▶ unless (defined $n) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $n) { } 0 0 0
(do { $n == 0 }) 0 0 0
290 0 ▶ die "write failed: $!" unless $!{EINTR} || $!{EWOULDBLOCK} || $!{EAGAIN};
Branch: 1 branch
BranchTrueFalseTotal
unless $!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"} 0 0 0
Condition0%0/6
$!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"}
l!l&&r!l&&!r
000
$!{"EINTR"} or $!{"EWOULDBLOCK"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"}
$!{"EINTR"} $!{"EWOULDBLOCK"} $!{"EAGAIN"}
Truth table0%0/4
A or B or C
A= $!{"EINTR"}B= $!{"EWOULDBLOCK"}C= $!{"EAGAIN"}
ABCresult
1XX1
01X1
0011
0000
291 0 $n = 0; # will retry write on the next round
292 }
293 0 elsif ($n == 0) {
294 0 die "write failed: no bytes written";
295 }
296 0 $woffset += $n;
297  
298 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
299 # need to refill buffer from $content_ref code
300 0 my $buf = &$content_ref();
301 0 ▶ $buf = "" unless defined($buf);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $buf 0 0 0
302 0 ▶ $eof++ unless length($buf);
Branch: 1 branch
BranchTrueFalseTotal
unless length $buf 0 0 0
303 0 ▶ $buf = sprintf "%x%s%s%s", length($buf), $CRLF, $buf, $CRLF
Branch: 1 branch
BranchTrueFalseTotal
if $chunked 0 0 0
304 if $chunked;
305 0 $wbuf = \$buf;
306 0 $woffset = 0;
307 }
308 }
309 } # WRITE
310 }
311
312 0 my @h;
313 0 ▶ ($code, $mess, @h) = $socket->read_response_headers(laxed => 1, junk_out => \@junk)
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 0 0
314 unless $code;
315 0 ▶ ($code, $mess, @h) = $socket->read_response_headers(laxed => 1, junk_out => \@junk)
Branch: 1 branch
BranchTrueFalseTotal
if $code eq 100 0 0 0
316 if $code eq "100";
317  
318 0 my $response = HTTP::Response->new($code, $mess);
319 0 my $peer_http_version = $socket->peer_http_version;
320 0 $response->protocol("HTTP/$peer_http_version");
321 {
322 0 local $HTTP::Headers::TRANSLATE_UNDERSCORE;
323 0 $response->push_header(@h);
324 }
325 0 ▶ $response->push_header("Client-Junk" => \@junk) if @junk;
Branch: 1 branch
BranchTrueFalseTotal
if @junk 0 0 0
326  
327 0 $response->request($request);
328 0 $self->_get_sock_info($response, $socket);
329  
330 0 ▶ if ($method eq "CONNECT") {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "CONNECT") 0 0 0
331 0 $response->{client_socket} = $socket; # so it can be picked up
332 0 return $response;
333 }
334  
335 0 ▶ if (my @te = $response->remove_header('Transfer-Encoding')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@te) = $response->remove_header("Transfer-Encoding")) 0 0 0
336 0 $response->push_header('Client-Transfer-Encoding', \@te);
337 }
338 0 $response->push_header('Client-Response-Num', scalar $socket->increment_response_count);
339  
340 0 my $complete;
341 $response = $self->collect($arg, $response, sub {
342 0 ▶ my $buf = ""; #prevent use of uninitialized value in SSLeay.xs
Subroutine __ANON__: not called CC=8 SCAR=42.8
343 0 my $n;
344 READ:
345 {
346 0 $n = $socket->read_entity_body($buf, $size);
347 0 ▶ unless (defined $n) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $n) 0 0 0
348 0 ▶ redo READ if $!{EINTR} || $!{EWOULDBLOCK} || $!{EAGAIN} || $!{ENOTTY};
Branch: 1 branch
BranchTrueFalseTotal
if $!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"} or $!{"ENOTTY"} 0 0 0
Condition0%0/9
$!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"} or $!{"ENOTTY"}
l!l&&r!l&&!r
000
$!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"}
l!l&&r!l&&!r
000
$!{"EINTR"} or $!{"EWOULDBLOCK"}
l!l&&r!l&&!r
000
MC/DC0%0/4
$!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"} or $!{"ENOTTY"}
$!{"EINTR"} $!{"EWOULDBLOCK"} $!{"EAGAIN"} $!{"ENOTTY"}
Truth table0%0/5
A or B or C or D
A= $!{"EINTR"}B= $!{"EWOULDBLOCK"}C= $!{"EAGAIN"}D= $!{"ENOTTY"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
349 0 die "read failed: $!";
350 }
351 0 ▶ redo READ if $n == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $n == -1 0 0 0
352 }
353 0 ▶ $complete++ if !$n;
Branch: 1 branch
BranchTrueFalseTotal
unless $n 0 0 0
354 0 return \$buf;
355 0 });
356 0 ▶ $drop_connection++ unless $complete;
Branch: 1 branch
BranchTrueFalseTotal
unless $complete 0 0 0
357  
358 0 @h = $socket->get_trailers;
359 0 ▶ if (@h) {
Branch: 1 branch
BranchTrueFalseTotal
if (@h) 0 0 0
360 0 local $HTTP::Headers::TRANSLATE_UNDERSCORE;
361 0 $response->push_header(@h);
362 }
363  
364 # keep-alive support
365 0 ▶ unless ($drop_connection) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($drop_connection) 0 0 0
366 0 ▶ if ($cache_key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache_key) 0 0 0
367 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
368 split(/\s*,\s*/, ($response->header("Connection") || ""));
369 0 ▶ if (($peer_http_version eq "1.1" && !$connection{close}) || $connection{"keep-alive"}) {
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
370 0 $conn_cache->deposit($self->socket_type, $cache_key, $socket);
371 }
372 }
373 }
374 0 $response;
375 }
376  
377  
378 package LWP::Protocol::UWSGI::Socket;
379 1 ▶use base qw(IO::Socket::INET Net::HTTP);
Subroutine BEGIN: called CC=1 SCAR=0.0
380  
381 sub ping {
382 0 ▶ my $self = shift;
Subroutine ping: not called CC=1 SCAR=6.9
383 0 !$self->can_read(0);
384 }
385  
386 sub increment_response_count {
387 0 ▶ my $self = shift;
Subroutine increment_response_count: not called CC=1 SCAR=6.9
388 0 return ++${*$self}{'myhttp_response_count'};
389 }
390  
391 1 1;
↑ Summary