HTTP/Client/Connection.pm

filter: Statementstmt 88.2% 460 / 521 Branchbran 66.2% 245 / 370 Conditioncond 56.0% 121 / 216 MC/DCmcdc 30.5% 40 / 131 Subroutinesub 93.7% 45 / 48 Podpod 85.7% 6 / 7 totaltotal 70.9% 917 / 1293 CC 271 SCAR 35.5
CC
271
Cov
75%
request
97.2
_request_chunked_transfer
72.1
_consume_response_body
53.5
CRAP 34.7
« HTTP/Client.pm ↑ Summary HTTP/_ServerConnect.pm »
1 package Linux::Event::HTTP::Client::Connection;
2 19 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 19 ▶use parent 'Linux::Event::IO::Sock::Stream';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 19 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 19 ▶use Config ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 19 ▶use Scalar::Util qw(blessed refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 19 ▶use utf8 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 19 ▶use Linux::Event::Framer ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 19 ▶use Linux::Event::HTTP::_HTTP1 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 19 ▶use Linux::Event::HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 19 ▶use Linux::Event::HTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 19 ▶use Linux::Event::HTTP::Transaction;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 19 our $VERSION = '0.003';
20  
21 19 Linux::Event::Framer->declare_native_consumer(
22 __PACKAGE__,
23 Linux::Event::HTTP::_HTTP1->_raw_client_consumer_definition,
24 );
25  
26 19 my $CHUNKED = 'Linux::Event::HTTP::_HTTP1::Chunked';
27 19 ▶my $MAX_CONTENT_LENGTH = $Config::Config{ivsize} >= 8
Branch: 1 branch
BranchTrueFalseTotal
$Config::Config{'ivsize'} >= 8 ? : 19 0 19
28 ? '9223372036854775807'
29 : '2147483647';
30  
31 19 my %RESERVED_CALLBACK = map { $_ => 1 } qw(
32 on_data on_eof on_error on_close on_message on_messages
33 );
34  
35 50 ▶sub _reject_reserved_callbacks ($operation, $option) {
Subroutine _reject_reserved_callbacks: called CC=2 SCAR=7.0
36 50 my @reserved = grep { exists $option->{$_} } sort keys %RESERVED_CALLBACK;
37 50 ▶ croak "$operation(): HTTP Client::Connection owns callbacks: "
Branch: 1 branch
BranchTrueFalseTotal
if @reserved 0 50 50
38 . join(', ', @reserved)
39 if @reserved;
40 50 return;
41 }
42  
43 50 ▶sub _take_drain_handler ($class, $option) {
Subroutine _take_drain_handler: called CC=3 SCAR=17.3
44 50 ▶ if (exists $option->{on_drain}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option->{"on_drain"}) 0 50 50
45 0 my $handler = delete $option->{on_drain};
46 0 ▶ croak 'on_drain must be a coderef' if ref($handler) ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $handler ne "CODE" 0 0 0
47 0 return $handler;
48 }
49 50 return $class->can('on_drain');
50 }
51  
52 49 ▶sub _init_http_client ($self, $user_on_drain = undef) {
Subroutine _init_http_client: called CC=2 SCAR=6.9
53 49 $self->{_http_client_input} = '';
54 49 $self->{_http_client_active_transaction} = undef;
55 49 $self->{_http_client_callbacks} = undef;
56 49 $self->{_http_client_request_state} = undef;
57 49 $self->{_http_client_response_state} = undef;
58 49 $self->{_http_client_pending_upgrade} = undef;
59 49 $self->{_http_client_pending_connect} = undef;
60 49 $self->{_http_client_user_on_drain} = $user_on_drain;
61 49 $self->{_http_client_driving} = 0;
62 49 $self->{_http_client_reusable} = 1;
63 49 return $self;
64 }
65  
66 0 ▶sub new ($class, %option) {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
67 0 _reject_reserved_callbacks('new', \%option);
68 0 my $user_on_drain = _take_drain_handler($class, \%option);
69 0 $option{on_drain} = \&_http_client_transport_drain;
70 0 my $self = $class->SUPER::new(%option);
71 0 return $self->_init_http_client($user_on_drain);
72 }
73  
74 50 ▶sub connect ($class, %option) {
Subroutine connect: called CC=2 SCAR=7.0
Pod documented
75 50 ▶ croak 'connect(): must be called as a class method' if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 50 50
76 50 _reject_reserved_callbacks('connect', \%option);
77 50 my $user_on_drain = _take_drain_handler($class, \%option);
78 50 $option{on_drain} = \&_http_client_transport_drain;
79 50 my $self = $class->SUPER::connect(%option);
80 49 return $self->_init_http_client($user_on_drain);
81 }
82  
83 77 ▶sub transaction ($self) {
Subroutine transaction: called CC=1 SCAR=0.0
Pod documented
84 77 return $self->{_http_client_active_transaction};
85 }
86  
87 1 ▶sub _http_client_transport_drain ($self) {
Subroutine _http_client_transport_drain: called CC=5 SCAR=17.8
88 1 ▶ if (my $executor = $self->{_http2_executor}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $executor = $self->{'_http2_executor'}) { } 0 1 1
elsif (my $transaction = $self->{'_http_client_active_transaction'}) { } 1 0 1
89 0 $executor->transport_drain;
90 } elsif (my $transaction = $self->{_http_client_active_transaction}) {
91 1 ▶ if (my $body = $transaction->_request_body_object) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $transaction->_request_body_object) 1 0 1
92 1 $body->_drain;
93 }
94 }
95 1 ▶ if (my $callback = $self->{_http_client_user_on_drain}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $callback = $self->{"_http_client_user_on_drain"}) 1 0 1
96 1 $callback->($self);
97 }
98 1 return;
99 }
100  
101 407 ▶sub _byte_string ($operation, $value) {
Subroutine _byte_string: called CC=5 SCAR=20.1
102 407 ▶ croak "$operation(): value must be a scalar byte string" if ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 407 407
103 407 ▶ my $bytes = defined($value) ? "$value" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 407 0 407
104 407 ▶ if (utf8::is_utf8($bytes)) {
Branch: 1 branch
BranchTrueFalseTotal
if (utf8::is_utf8($bytes)) 0 407 407
105 0 ▶ croak "$operation(): value contains wide characters; encode it to bytes first"
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::downgrade($bytes, 1) 0 0 0
106 if !utf8::downgrade($bytes, 1);
107 }
108 407 return $bytes;
109 }
110  
111 18 ▶sub _buffer_limit ($value) {
Subroutine _buffer_limit: called CC=8 SCAR=26.5
112 18 ▶ croak 'request(): buffer_body must be a positive integer byte limit'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or ref $value or not "$value" =~ /\A[0-9]+\z/u 0 18 18
Condition33%2/6
not defined $value or ref $value or not "$value" =~ /\A[0-9]+\z/u
l!l&&r!l&&!r
0018
not defined $value or ref $value
l!l&&r!l&&!r
0018
MC/DC0%0/3
not defined $value or ref $value or not "$value" =~ /\A[0-9]+\z/u
not defined $value ref $value not "$value" =~ /\A[0-9]+\z/u
Truth table25%1/4
not(A) or B or not(C)
A= not defined $valueB= ref $valueC= not "$value" =~ /\A[0-9]+\z/u
ABCresult
1XX1
01X1
0011
0000
113 if !defined($value) || ref($value) || "$value" !~ /\A[0-9]+\z/;
114  
115 18 my $digits = "$value";
116 18 $digits =~ s/\A0+(?=\d)//;
117 18 ▶ croak 'request(): buffer_body must be greater than zero'
Branch: 1 branch
BranchTrueFalseTotal
if $digits eq 0 0 18 18
118 if $digits eq '0';
119 18 ▶ croak 'request(): buffer_body exceeds supported range'
Branch: 1 branch
BranchTrueFalseTotal
if length $digits > length $MAX_CONTENT_LENGTH or length $digits == length $MAX_CONTENT_LENGTH and $digits gt $MAX_CONTENT_LENGTH 0 18 18
Condition33%2/6
length $digits > length $MAX_CONTENT_LENGTH or length $digits == length $MAX_CONTENT_LENGTH and $digits gt $MAX_CONTENT_LENGTH
l!l&&r!l&&!r
0018
length $digits == length $MAX_CONTENT_LENGTH and $digits gt $MAX_CONTENT_LENGTH
!ll&&!rl&&r
1800
MC/DC0%0/3
length $digits > length $MAX_CONTENT_LENGTH or length $digits == length $MAX_CONTENT_LENGTH and $digits gt $MAX_CONTENT_LENGTH
length $digits > length $MAX_CONTENT_LENGTH length $digits == length $MAX_CONTENT_LENGTH $digits gt $MAX_CONTENT_LENGTH
Truth table25%1/4
A or B and C
A= length $digits > length $MAX_CONTENT_LENGTHB= length $digits == length $MAX_CONTENT_LENGTHC= $digits gt $MAX_CONTENT_LENGTH
ABCresult
1XX1
0111
00X0
0100
120 if length($digits) > length($MAX_CONTENT_LENGTH)
121 || (length($digits) == length($MAX_CONTENT_LENGTH)
122 && $digits gt $MAX_CONTENT_LENGTH);
123 18 return 0 + $digits;
124 }
125  
126 75 ▶sub _serialize_request_head ($request) {
Subroutine _serialize_request_head: called CC=6 SCAR=18.3
127 75 my $version = $request->version;
128 75 ▶ croak "request(): HTTP/1 client supports version 1.0 or 1.1, not $version"
Branch: 1 branch
BranchTrueFalseTotal
if $version ne "1.0" and $version ne "1.1" 0 75 75
Condition66%2/3
$version ne "1.0" and $version ne "1.1"
!ll&&!rl&&r
1740
MC/DC0%0/2
$version ne "1.0" and $version ne "1.1"
$version ne "1.0" $version ne "1.1"
Truth table66%2/3
A and B
A= $version ne "1.0"B= $version ne "1.1"
ABresult
0X0
100
111
129 if $version ne '1.0' && $version ne '1.1';
130  
131 75 my $method = _byte_string('request method', $request->method);
132 75 my $target = _byte_string('request target', $request->target);
133 75 my $head = "$method $target HTTP/$version\r\n";
134  
135 75 for my $index (0 .. $request->header_count - 1) {
136 124 my $name = _byte_string('request header name', $request->header_name($index));
137 124 my $value = _byte_string('request header value', $request->header_value($index));
138 124 ▶ croak 'request(): invalid header field name'
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /\A[!#\$%&'*+\-.^_`|~0-9A-Za-z]+\z/u 0 124 124
139 if $name !~ /\A[!#\$%&'*+\-.^_`|~0-9A-Za-z]+\z/;
140 124 ▶ croak 'request(): header field value contains invalid control characters'
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /[\x00-\x08\x0a-\x1f\x7f]/u 0 124 124
141 if $value =~ /[\x00-\x08\x0a-\x1f\x7f]/;
142 124 $head .= "$name: $value\r\n";
143 }
144  
145 75 $head .= "\r\n";
146 75 return $head;
147 }
148  
149 8 ▶sub _request_chunked_transfer ($version, $values) {
Subroutine _request_chunked_transfer: called CC=9 SCAR=42.8
150 8 ▶ return 0 if !@$values;
Branch: 1 branch
BranchTrueFalseTotal
unless @$values 8 0 8
151 0 ▶ croak 'request(): Transfer-Encoding is not valid for HTTP/1.0 requests'
Branch: 1 branch
BranchTrueFalseTotal
if $version ne "1.1" 0 0 0
152 if $version ne '1.1';
153  
154 0 my @coding;
155 0 for my $value (@$values) {
156 0 for my $member (split /,/, $value, -1) {
157 0 $member =~ s/\A[ \t]+//;
158 0 $member =~ s/[ \t]+\z//;
159 0 ▶ croak 'request(): invalid Transfer-Encoding request value'
Branch: 1 branch
BranchTrueFalseTotal
if $member eq "" or $member =~ /;/u 0 0 0
Condition0%0/3
$member eq "" or $member =~ /;/u
l!l&&r!l&&!r
000
MC/DC0%0/2
$member eq "" or $member =~ /;/u
$member eq "" $member =~ /;/u
Truth table0%0/3
A or B
A= $member eq ""B= $member =~ /;/u
ABresult
1X1
011
000
160 if $member eq '' || $member =~ /;/;
161 0 push @coding, lc $member;
162 }
163 }
164  
165 0 ▶ croak 'request(): only chunked request Transfer-Encoding is supported'
Branch: 1 branch
BranchTrueFalseTotal
if @coding != 1 or $coding[0] ne "chunked" 0 0 0
Condition0%0/3
@coding != 1 or $coding[0] ne "chunked"
l!l&&r!l&&!r
000
MC/DC0%0/2
@coding != 1 or $coding[0] ne "chunked"
@coding != 1 $coding[0] ne "chunked"
Truth table0%0/3
A or B
A= @coding != 1B= $coding[0] ne "chunked"
ABresult
1X1
011
000
166 if @coding != 1 || $coding[0] ne 'chunked';
167 0 return 1;
168 }
169  
170 4 ▶sub _chunk_wire ($bytes) {
Subroutine _chunk_wire: called CC=2 SCAR=7.2
171 4 ▶ return '' if !length($bytes);
Branch: 1 branch
BranchTrueFalseTotal
unless length $bytes 0 4 4
172 4 return sprintf('%x', length($bytes)) . "\r\n" . $bytes . "\r\n";
173 }
174  
175 77 ▶sub _prepare_request ($request, $streaming = 0) {
Subroutine _prepare_request: called CC=26 SCAR=36.7
176 77 ▶ croak 'request(): requires a Linux::Event::HTTP::Request'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($request) and $request->isa("Linux::Event::HTTP::Request") 0 77 77
Condition33%1/3
builtin::blessed($request) and $request->isa("Linux::Event::HTTP::Request")
!ll&&!rl&&r
0077
MC/DC0%0/2
builtin::blessed($request) and $request->isa("Linux::Event::HTTP::Request")
builtin::blessed($request) $request->isa("Linux::Event::HTTP::Request")
Truth table33%1/3
A and B
A= builtin::blessed($request)B= $request->isa("Linux::Event::HTTP::Request")
ABresult
0X0
100
111
177 if !blessed($request)
178 || !$request->isa('Linux::Event::HTTP::Request');
179  
180 77 my $version = $request->version;
181 77 ▶ croak "request(): HTTP/1 client supports version 1.0 or 1.1, not $version"
Branch: 1 branch
BranchTrueFalseTotal
if $version ne "1.0" and $version ne "1.1" 0 77 77
Condition66%2/3
$version ne "1.0" and $version ne "1.1"
!ll&&!rl&&r
2750
MC/DC0%0/2
$version ne "1.0" and $version ne "1.1"
$version ne "1.0" $version ne "1.1"
Truth table66%2/3
A and B
A= $version ne "1.0"B= $version ne "1.1"
ABresult
0X0
100
111
182 if $version ne '1.0' && $version ne '1.1';
183  
184 77 my @host = $request->_header_values_list('Host');
185 77 ▶ croak 'request(): HTTP/1.1 requires exactly one Host field'
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "1.1" and @host != 1 1 76 77
Condition100%3/3
$version eq "1.1" and @host != 1
!ll&&!rl&&r
2741
MC/DC100%2/2
$version eq "1.1" and @host != 1
$version eq "1.1" @host != 1
Truth table100%3/3
A and B
A= $version eq "1.1"B= @host != 1
ABresult
0X0
100
111
186 if $version eq '1.1' && @host != 1;
187 76 ▶ croak 'request(): multiple Host fields are not allowed'
Branch: 1 branch
BranchTrueFalseTotal
if @host > 1 0 76 76
188 if @host > 1;
189  
190 76 my @transfer = $request->_header_values_list('Transfer-Encoding');
191 76 my $body = $request->body;
192 76 my $length = $request->content_length;
193  
194 76 ▶ if ($streaming) {
Branch: 1 branch
BranchTrueFalseTotal
if ($streaming) 8 68 76
195 8 ▶ croak 'request(): stream_body cannot be combined with a scalar Request body'
Branch: 1 branch
BranchTrueFalseTotal
if defined $body or $request->_has_scalar_body 0 8 8
Condition33%1/3
defined $body or $request->_has_scalar_body
l!l&&r!l&&!r
008
MC/DC0%0/2
defined $body or $request->_has_scalar_body
defined $body $request->_has_scalar_body
Truth table33%1/3
A or B
A= defined $bodyB= $request->_has_scalar_body
ABresult
1X1
011
000
196 if defined($body) || $request->_has_scalar_body;
197 8 ▶ croak 'request(): streaming Request cannot contain both Transfer-Encoding and Content-Length'
Branch: 1 branch
BranchTrueFalseTotal
if @transfer and defined $length 0 8 8
Condition33%1/3
@transfer and defined $length
!ll&&!rl&&r
800
MC/DC0%0/2
@transfer and defined $length
@transfer defined $length
Truth table33%1/3
A and B
A= @transferB= defined $length
ABresult
0X0
100
111
198 if @transfer && defined $length;
199  
200 8 my $chunked = _request_chunked_transfer($version, \@transfer);
201 8 ▶ if (!@transfer && !defined $length) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@transfer or defined $length) 4 4 8
Condition66%2/3
@transfer or defined $length
l!l&&r!l&&!r
044
MC/DC50%1/2
@transfer or defined $length
@transfer defined $length
Truth table66%2/3
A or B
A= @transferB= defined $length
ABresult
1X1
011
000
202 4 ▶ croak 'request(): HTTP/1.0 streaming Request requires Content-Length'
Branch: 1 branch
BranchTrueFalseTotal
if $version ne "1.1" 1 3 4
203 if $version ne '1.1';
204 3 $request->header('Transfer-Encoding', 'chunked');
205 3 $chunked = 1;
206 }
207  
208 $request->_begin_stream_body
209 7 ▶ if !$request->_has_incremental_body;
Branch: 1 branch
BranchTrueFalseTotal
unless $request->_has_incremental_body 7 0 7
210 7 my $head = _serialize_request_head($request);
211 return (
212 7 ▶ $head,
Branch: 1 branch
BranchTrueFalseTotal
$chunked ? : 3 4 7
213 '',
214 {
215 streaming => 1,
216 chunked => $chunked ? 1 : 0,
217 expected => $length,
218 sent => 0,
219 complete => 0,
220 },
221 );
222 }
223  
224 68 ▶ croak 'request(): Transfer-Encoding requires stream_body'
Branch: 1 branch
BranchTrueFalseTotal
if @transfer 0 68 68
225 if @transfer;
226  
227 68 ▶ if (defined $body) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $body) { } 8 60 68
elsif (defined $length and $length != 0) { } 0 120 120
228 8 my $body_length = length($body);
229 8 ▶ if (defined $length) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $length) { } 0 8 8
230 0 ▶ croak 'request(): Content-Length does not match scalar body length'
Branch: 1 branch
BranchTrueFalseTotal
if $length != $body_length 0 0 0
231 if $length != $body_length;
232 } else {
233 8 $request->header('Content-Length', $body_length);
234 }
235 ▶ } elsif (defined($length) && $length != 0) {
Condition33%1/3
defined $length and $length != 0
!ll&&!rl&&r
6000
MC/DC0%0/2
defined $length and $length != 0
defined $length $length != 0
Truth table33%1/3
A and B
A= defined $lengthB= $length != 0
ABresult
0X0
100
111
236 0 croak 'request(): non-zero Content-Length requires a scalar or streaming body';
237 }
238  
239 68 my $head = _serialize_request_head($request);
240 return (
241 68 ▶ $head,
Condition100%2/2
$body // ""
l!l
860
MC/DC100%1/1
$body // ""
$body
Truth table100%2/2
A
A= $body
Aresult
11
00
242 $body // '',
243 {
244 streaming => 0,
245 complete => 1,
246 },
247 );
248 }
249  
250 83 ▶sub request ($self, $request, %option) {
Subroutine request: called CC=49 SCAR=45.8
Pod documented
251 83 ▶ croak 'request(): connection is closed' if $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_closed 0 83 83
252 83 my $provided_transaction = delete $option{_transaction};
253 83 ▶ croak 'request(): connection is not reusable' if !$self->{_http_client_reusable};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_http_client_reusable"} 0 83 83
254 croak 'request(): another Transaction is already active on this connection'
255 83 ▶ if $self->{_http_client_active_transaction};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_client_active_transaction"} 1 82 83
256  
257 82 my $stream_body;
258 82 ▶ if (exists $option{stream_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option{"stream_body"}) 8 74 82
259 8 $stream_body = delete $option{stream_body};
260 8 ▶ croak 'request(): stream_body must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
if ref $stream_body ne "HASH" 0 8 8
261 if ref($stream_body) ne 'HASH';
262 8 $stream_body = { %$stream_body };
263 }
264  
265 82 my $buffer_limit;
266 82 ▶ if (exists $option{buffer_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option{"buffer_body"}) 18 64 82
267 18 $buffer_limit = _buffer_limit(delete $option{buffer_body});
268 }
269  
270 my $upgrade_to = exists($option{upgrade_to})
271 ? delete($option{upgrade_to})
272 82 ▶ : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'upgrade_to'} ? : 5 77 82
273 my $tunnel_to = exists($option{tunnel_to})
274 ? delete($option{tunnel_to})
275 82 ▶ : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'tunnel_to'} ? : 10 72 82
276  
277 82 my %callback;
278 82 my %known = map { $_ => 1 } qw(
279 on_response on_body on_complete on_error on_informational
280 on_upgrade on_tunnel
281 );
282 82 my @unknown = grep { !$known{$_} } keys %option;
283 82 ▶ croak 'request(): unknown options: ' . join(', ', sort @unknown)
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 0 82 82
284 if @unknown;
285  
286 82 for my $name (keys %option) {
287 268 my $value = $option{$name};
288 268 ▶ croak "request(): $name must be a coderef"
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and ref $value ne "CODE" 0 268 268
Condition33%1/3
defined $value and ref $value ne "CODE"
!ll&&!rl&&r
02680
MC/DC0%0/2
defined $value and ref $value ne "CODE"
defined $value ref $value ne "CODE"
Truth table33%1/3
A and B
A= defined $valueB= ref $value ne "CODE"
ABresult
0X0
100
111
289 if defined($value) && ref($value) ne 'CODE';
290 268 ▶ $callback{$name} = $value if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 268 0 268
291 }
292  
293 croak 'request(): buffer_body cannot be combined with on_body'
294 82 ▶ if defined($buffer_limit) && $callback{on_body};
Branch: 1 branch
BranchTrueFalseTotal
if defined $buffer_limit and $callback{"on_body"} 0 82 82
Condition66%2/3
defined $buffer_limit and $callback{"on_body"}
!ll&&!rl&&r
64180
MC/DC0%0/2
defined $buffer_limit and $callback{"on_body"}
defined $buffer_limit $callback{"on_body"}
Truth table66%2/3
A and B
A= defined $buffer_limitB= $callback{"on_body"}
ABresult
0X0
100
111
295 croak 'request(): on_upgrade requires upgrade_to'
296 82 ▶ if $callback{on_upgrade} && !defined($upgrade_to);
Branch: 1 branch
BranchTrueFalseTotal
if $callback{"on_upgrade"} and not defined $upgrade_to 0 82 82
Condition66%2/3
$callback{"on_upgrade"} and not defined $upgrade_to
!ll&&!rl&&r
7840
MC/DC0%0/2
$callback{"on_upgrade"} and not defined $upgrade_to
$callback{"on_upgrade"} not defined $upgrade_to
Truth table66%2/3
A and not(B)
A= $callback{"on_upgrade"}B= not defined $upgrade_to
ABresult
0X0
100
111
297 croak 'request(): on_tunnel requires tunnel_to'
298 82 ▶ if $callback{on_tunnel} && !defined($tunnel_to);
Branch: 1 branch
BranchTrueFalseTotal
if $callback{"on_tunnel"} and not defined $tunnel_to 0 82 82
Condition66%2/3
$callback{"on_tunnel"} and not defined $tunnel_to
!ll&&!rl&&r
7660
MC/DC0%0/2
$callback{"on_tunnel"} and not defined $tunnel_to
$callback{"on_tunnel"} not defined $tunnel_to
Truth table66%2/3
A and not(B)
A= $callback{"on_tunnel"}B= not defined $tunnel_to
ABresult
0X0
100
111
299 82 ▶ croak 'request(): upgrade_to and tunnel_to are mutually exclusive'
Branch: 1 branch
BranchTrueFalseTotal
if defined $upgrade_to and defined $tunnel_to 0 82 82
Condition66%2/3
defined $upgrade_to and defined $tunnel_to
!ll&&!rl&&r
7750
MC/DC0%0/2
defined $upgrade_to and defined $tunnel_to
defined $upgrade_to defined $tunnel_to
Truth table66%2/3
A and B
A= defined $upgrade_toB= defined $tunnel_to
ABresult
0X0
100
111
300 if defined($upgrade_to) && defined($tunnel_to);
301 82 ▶ croak 'request(): upgrade_to cannot be combined with buffer_body'
Branch: 1 branch
BranchTrueFalseTotal
if defined $upgrade_to and defined $buffer_limit 0 82 82
Condition66%2/3
defined $upgrade_to and defined $buffer_limit
!ll&&!rl&&r
7750
MC/DC0%0/2
defined $upgrade_to and defined $buffer_limit
defined $upgrade_to defined $buffer_limit
Truth table66%2/3
A and B
A= defined $upgrade_toB= defined $buffer_limit
ABresult
0X0
100
111
302 if defined($upgrade_to) && defined($buffer_limit);
303 croak 'request(): upgrade_to cannot be combined with on_body'
304 82 ▶ if defined($upgrade_to) && $callback{on_body};
Branch: 1 branch
BranchTrueFalseTotal
if defined $upgrade_to and $callback{"on_body"} 0 82 82
Condition66%2/3
defined $upgrade_to and $callback{"on_body"}
!ll&&!rl&&r
7750
MC/DC0%0/2
defined $upgrade_to and $callback{"on_body"}
defined $upgrade_to $callback{"on_body"}
Truth table66%2/3
A and B
A= defined $upgrade_toB= $callback{"on_body"}
ABresult
0X0
100
111
305 82 ▶ $callback{buffer_body} = $buffer_limit if defined $buffer_limit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $buffer_limit 18 64 82
306  
307 82 my $is_connect = uc($request->method) eq 'CONNECT';
308 82 ▶ croak 'request(): CONNECT requires tunnel_to'
Branch: 1 branch
BranchTrueFalseTotal
if $is_connect and not defined $tunnel_to 1 81 82
Condition100%3/3
$is_connect and not defined $tunnel_to
!ll&&!rl&&r
7291
MC/DC100%2/2
$is_connect and not defined $tunnel_to
$is_connect not defined $tunnel_to
Truth table100%3/3
A and not(B)
A= $is_connectB= not defined $tunnel_to
ABresult
0X0
100
111
309 if $is_connect && !defined($tunnel_to);
310 81 ▶ croak 'request(): tunnel_to requires CONNECT method'
Branch: 1 branch
BranchTrueFalseTotal
if defined $tunnel_to and not $is_connect 1 80 81
Condition100%3/3
defined $tunnel_to and not $is_connect
!ll&&!rl&&r
7191
MC/DC100%2/2
defined $tunnel_to and not $is_connect
defined $tunnel_to not $is_connect
Truth table100%3/3
A and not(B)
A= defined $tunnel_toB= not $is_connect
ABresult
0X0
100
111
311 if defined($tunnel_to) && !$is_connect;
312  
313 80 ▶ if (defined $tunnel_to) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tunnel_to) 9 71 80
314 9 require Linux::Event::HTTP::_ClientConnect;
315 9 ▶ $tunnel_to = Linux::Event::HTTP::_ClientConnect->prepare_request(
Branch: 1 branch
BranchTrueFalseTotal
defined $stream_body ? : 0 9 9
316 $request,
317 $tunnel_to,
318 { streaming => defined($stream_body) ? 1 : 0 },
319 );
320 6 $callback{tunnel_to} = $tunnel_to;
321 }
322  
323 77 ▶ my ($head, $body, $request_state) = _prepare_request(
Branch: 1 branch
BranchTrueFalseTotal
defined $stream_body ? : 8 69 77
324 $request, defined($stream_body) ? 1 : 0,
325 );
326  
327 75 ▶ if (defined $upgrade_to) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $upgrade_to) 5 70 75
328 5 require Linux::Event::HTTP::_ClientUpgrade;
329 5 $upgrade_to = Linux::Event::HTTP::_ClientUpgrade->prepare_request(
330 $request, $upgrade_to, $request_state,
331 );
332 4 $callback{upgrade_to} = $upgrade_to;
333 }
334  
335 74 $request->_mark_committed;
336  
337 74 my $transaction;
338 74 ▶ if ($provided_transaction) {
Branch: 1 branch
BranchTrueFalseTotal
if ($provided_transaction) { } 0 74 74
339 0 ▶ croak 'request(): _transaction must be a Linux::Event::HTTP::Transaction'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($provided_transaction) and $provided_transaction->isa("Linux::Event::HTTP::Transaction") 0 0 0
Condition0%0/3
builtin::blessed($provided_transaction) and $provided_transaction->isa("Linux::Event::HTTP::Transaction")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($provided_transaction) and $provided_transaction->isa("Linux::Event::HTTP::Transaction")
builtin::blessed($provided_transaction) $provided_transaction->isa("Linux::Event::HTTP::Transaction")
Truth table0%0/3
A and B
A= builtin::blessed($provided_transaction)B= $provided_transaction->isa("Linux::Event::HTTP::Transaction")
ABresult
0X0
100
111
340 if !blessed($provided_transaction)
341 || !$provided_transaction->isa('Linux::Event::HTTP::Transaction');
342 0 ▶ croak 'request(): _transaction Request does not match'
Branch: 1 branch
BranchTrueFalseTotal
if builtin::refaddr($provided_transaction->request) != builtin::refaddr($request) 0 0 0
343 if refaddr($provided_transaction->request) != refaddr($request);
344 0 ▶ croak 'request(): _transaction is already terminal'
Branch: 1 branch
BranchTrueFalseTotal
if $provided_transaction->is_terminal 0 0 0
345 if $provided_transaction->is_terminal;
346 0 $transaction = $provided_transaction;
347 0 $transaction->_set_controller($self);
348 0 $transaction->_activate;
349 } else {
350 74 $transaction = Linux::Event::HTTP::Transaction->_new(
351 request => $request,
352 controller => $self,
353 );
354 74 $transaction->_activate;
355 }
356 74 my $request_body;
357 74 ▶ if (defined $stream_body) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stream_body) 7 67 74
358 7 $request_body = $transaction->_request_body_object;
359 7 ▶ $request_body //= $transaction->request_body(%$stream_body);
Condition33%1/3
$request_body //= $transaction->request_body(%$stream_body)
l!l&&r!l&&!r
070
MC/DC0%0/2
$request_body //= $transaction->request_body(%$stream_body)
$request_body $transaction->request_body(%$stream_body)
Truth table33%1/3
A //= B
A= $request_bodyB= $transaction->request_body(%$stream_body)
ABresult
1X1
011
000
360 }
361  
362 74 $self->{_http_client_active_transaction} = $transaction;
363 74 $self->{_http_client_callbacks} = \%callback;
364 74 $self->{_http_client_request_state} = $request_state;
365 74 $self->{_http_client_response_state} = undef;
366 74 $self->{_http_client_pending_upgrade} = undef;
367 74 $self->{_http_client_pending_connect} = undef;
368  
369 74 my $wire = $head . $body;
370 74 my ($accepted, $written);
371 74 my $ok = eval {
372 74 $accepted = $self->write($wire);
373 74 $written = 1;
374 74 1;
375 };
376 74 ▶ if (!$ok || !$written) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok and $written) 0 74 74
Condition33%1/3
$ok and $written
!ll&&!rl&&r
0074
MC/DC0%0/2
$ok and $written
$ok $written
Truth table33%1/3
A and B
A= $okB= $written
ABresult
0X0
100
111
377 0 my $error = "$@";
378 0 ▶ $self->_fail_active_transaction($error || 'request write failed', 1);
Condition0%0/2
$error || 'request write failed'
l!l
00
MC/DC0%0/1
$error || 'request write failed'
$error
Truth table0%0/2
A
A= $error
Aresult
11
00
379 0 ▶ croak $error || 'request(): write failed';
Condition0%0/2
$error || 'request(): write failed'
l!l
00
MC/DC0%0/1
$error || 'request(): write failed'
$error
Truth table0%0/2
A
A= $error
Aresult
11
00
380 }
381 74 ▶ $request_body->_block if $request_body && !$accepted;
Branch: 1 branch
BranchTrueFalseTotal
if $request_body and not $accepted 1 73 74
Condition100%3/3
$request_body and not $accepted
!ll&&!rl&&r
6761
MC/DC100%2/2
$request_body and not $accepted
$request_body not $accepted
Truth table100%3/3
A and not(B)
A= $request_bodyB= not $accepted
ABresult
0X0
100
111
382  
383 74 ▶ $self->_drive_http1 if length($self->{_http_client_input});
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"_http_client_input"} 0 74 74
384 74 return $transaction;
385 }
386  
387 0 ▶sub _http_client_native_protocol_error ($self, $error) {
Subroutine _http_client_native_protocol_error: not called CC=4 SCAR=30.0
388 0 ▶ return 0 if $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_closed 0 0 0
389  
390 0 my $transaction = $self->{_http_client_active_transaction};
391 0 ▶ if ($transaction && !$transaction->is_terminal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($transaction and not $transaction->is_terminal) { } 0 0 0
Condition0%0/3
$transaction and not $transaction->is_terminal
!ll&&!rl&&r
000
MC/DC0%0/2
$transaction and not $transaction->is_terminal
$transaction not $transaction->is_terminal
Truth table0%0/3
A and not(B)
A= $transactionB= not $transaction->is_terminal
ABresult
0X0
100
111
392 0 $self->_fail_active_transaction($error, 1);
393 } else {
394 0 $self->{_http_client_reusable} = 0;
395 0 $self->close;
396 }
397 0 return 0;
398 }
399  
400 74 ▶sub _http_client_native_response ($self, $response) {
Subroutine _http_client_native_response: called CC=30 SCAR=35.1
401 74 ▶ return 0 if $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_closed 0 74 74
402  
403 74 my $transaction = $self->{_http_client_active_transaction};
404 74 ▶ if (!$transaction || $transaction->is_terminal) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $transaction or $transaction->is_terminal) 0 74 74
Condition33%1/3
not $transaction or $transaction->is_terminal
l!l&&r!l&&!r
0074
MC/DC0%0/2
not $transaction or $transaction->is_terminal
not $transaction $transaction->is_terminal
Truth table33%1/3
not(A) or B
A= not $transactionB= $transaction->is_terminal
ABresult
1X1
011
000
405 0 $self->{_http_client_reusable} = 0;
406 0 $self->close;
407 0 return 0;
408 }
409  
410 74 ▶ if ($response->status >= 100 && $response->status < 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->status >= 100 and $response->status < 200) 6 68 74
Condition66%2/3
$response->status >= 100 and $response->status < 200
!ll&&!rl&&r
0686
MC/DC50%1/2
$response->status >= 100 and $response->status < 200
$response->status >= 100 $response->status < 200
Truth table66%2/3
A and B
A= $response->status >= 100B= $response->status < 200
ABresult
0X0
100
111
411 6 ▶ if ($response->status == 101) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->status == 101) 4 2 6
412 4 my $target = $self->{_http_client_callbacks}{upgrade_to};
413 4 ▶ if (!defined $target) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $target) 1 3 4
414 1 $self->_fail_active_transaction(
415 'HTTP/1 101 Upgrade requires upgrade_to', 1,
416 );
417 1 return 0;
418 }
419  
420 3 my $scheduled = eval {
421 3 require Linux::Event::HTTP::_ClientUpgrade;
422 3 Linux::Event::HTTP::_ClientUpgrade->schedule(
423 $self, $transaction, $response, $target,
424 );
425 2 1;
426 };
427 3 ▶ if (!$scheduled) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($scheduled) 1 2 3
428 1 my $error = "$@";
429 1 $self->_fail_active_transaction($error, 1);
430 }
431 3 return 0;
432 }
433  
434 2 my $valid = eval {
435 2 _response_transfer_mode($transaction->request, $response);
436 2 1;
437 };
438 2 ▶ if (!$valid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($valid) 0 2 2
439 0 my $error = "$@";
440 0 $self->_fail_active_transaction($error, 1);
441 0 return 0;
442 }
443  
444 2 $response->_mark_complete;
445 $self->_callback(
446 'on_informational', $transaction, $response,
447 2 ▶ ) if $self->{_http_client_callbacks}{on_informational};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_client_callbacks"}{"on_informational"} 2 0 2
448 2 return 0;
449 }
450  
451 68 ▶ if (uc($transaction->request->method) eq 'CONNECT'
Branch: 1 branch
BranchTrueFalseTotal
if (uc $transaction->request->method eq "CONNECT" and $response->status >= 200 and $response->status < 300) 3 65 68
Condition83%5/6
uc $transaction->request->method eq "CONNECT" and $response->status >= 200 and $response->status < 300
!ll&&!rl&&r
6233
uc $transaction->request->method eq "CONNECT" and $response->status >= 200
!ll&&!rl&&r
6206
MC/DC66%2/3
uc $transaction->request->method eq "CONNECT" and $response->status >= 200 and $response->status < 300
uc $transaction->request->method eq "CONNECT" $response->status >= 200 $response->status < 300
Truth table75%3/4
A and B and C
A= uc $transaction->request->method eq "CONNECT"B= $response->status >= 200C= $response->status < 300
ABCresult
0XX0
10X0
1100
1111
452 && $response->status >= 200
453 && $response->status < 300) {
454 3 my $target = $self->{_http_client_callbacks}{tunnel_to};
455 3 ▶ if (!defined $target) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $target) 0 3 3
456 0 $self->_fail_active_transaction(
457 'HTTP/1 successful CONNECT requires tunnel_to', 1,
458 );
459 0 return 0;
460 }
461  
462 3 my $scheduled = eval {
463 3 require Linux::Event::HTTP::_ClientConnect;
464 3 Linux::Event::HTTP::_ClientConnect->schedule(
465 $self, $transaction, $response, $target,
466 );
467 3 1;
468 };
469 3 ▶ if (!$scheduled) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($scheduled) 0 3 3
470 0 my $error = "$@";
471 0 $self->_fail_active_transaction($error, 1);
472 }
473 3 return 0;
474 }
475  
476 65 my $state;
477 65 my $valid = eval {
478 65 $state = _response_transfer_mode(
479 $transaction->request, $response,
480 );
481 64 1;
482 };
483 65 ▶ if (!$valid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($valid) 1 64 65
484 1 my $error = "$@";
485 1 $self->_fail_active_transaction($error, 1);
486 1 return 0;
487 }
488  
489 64 my $buffer_limit = $self->{_http_client_callbacks}{buffer_body};
490 64 ▶ if (defined $buffer_limit) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buffer_limit) 18 46 64
491 18 $state->{buffer_limit} = $buffer_limit;
492 18 $state->{buffer} = '';
493 }
494  
495 64 my $request_state = $self->{_http_client_request_state};
496 64 ▶ if ($request_state && $request_state->{streaming}
Branch: 1 branch
BranchTrueFalseTotal
if ($request_state and $request_state->{"streaming"} and not $request_state->{"complete"}) 1 63 64
Condition83%5/6
$request_state and $request_state->{"streaming"} and not $request_state->{"complete"}
!ll&&!rl&&r
5941
$request_state and $request_state->{"streaming"}
!ll&&!rl&&r
0595
MC/DC66%2/3
$request_state and $request_state->{"streaming"} and not $request_state->{"complete"}
$request_state $request_state->{"streaming"} not $request_state->{"complete"}
Truth table75%3/4
A and B and not(C)
A= $request_stateB= $request_state->{"streaming"}C= not $request_state->{"complete"}
ABCresult
0XX0
10X0
1100
1111
497 && !$request_state->{complete}) {
498 1 ▶ if (my $body = $transaction->_request_body_object) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $transaction->_request_body_object) 1 0 1
499 1 $body->_cancel;
500 }
501 1 $state->{keep_alive} = 0;
502 1 $self->{_http_client_reusable} = 0;
503 }
504  
505 64 $transaction->_set_response($response);
506 64 $self->{_http_client_response_state} = $state;
507  
508 $self->_callback('on_response', $transaction, $response)
509 64 ▶ if $self->{_http_client_callbacks}{on_response};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_client_callbacks"}{"on_response"} 62 2 64
510 64 ▶ return 0 if !$self->_same_active_transaction($transaction);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_same_active_transaction($transaction) 1 63 64
511  
512 63 ▶ if (exists($state->{buffer_limit})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $state->{"buffer_limit"} and $state->{"mode"} eq "content-length" and $state->{"remaining"} > $state->{"buffer_limit"}) 1 62 63
Condition100%6/6
exists $state->{"buffer_limit"} and $state->{"mode"} eq "content-length" and $state->{"remaining"} > $state->{"buffer_limit"}
!ll&&!rl&&r
49131
exists $state->{"buffer_limit"} and $state->{"mode"} eq "content-length"
!ll&&!rl&&r
45414
MC/DC100%3/3
exists $state->{"buffer_limit"} and $state->{"mode"} eq "content-length" and $state->{"remaining"} > $state->{"buffer_limit"}
exists $state->{"buffer_limit"} $state->{"mode"} eq "content-length" $state->{"remaining"} > $state->{"buffer_limit"}
Truth table100%4/4
A and B and C
A= exists $state->{"buffer_limit"}B= $state->{"mode"} eq "content-length"C= $state->{"remaining"} > $state->{"buffer_limit"}
ABCresult
0XX0
10X0
1100
1111
513 && $state->{mode} eq 'content-length'
514 && $state->{remaining} > $state->{buffer_limit}) {
515 1 my $limit = $state->{buffer_limit};
516 1 $self->_fail_active_transaction(
517 "response body exceeds buffer_body limit of $limit bytes", 1,
518 );
519 1 return 0;
520 }
521  
522 62 ▶ if ($state->{mode} eq 'none'
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"mode"} eq "none" or $state->{"mode"} eq "content-length" and $state->{"remaining"} == 0) 6 56 62
Condition100%6/6
$state->{"mode"} eq "none" or $state->{"mode"} eq "content-length" and $state->{"remaining"} == 0
l!l&&r!l&&!r
1556
$state->{"mode"} eq "content-length" and $state->{"remaining"} == 0
!ll&&!rl&&r
5515
MC/DC100%3/3
$state->{"mode"} eq "none" or $state->{"mode"} eq "content-length" and $state->{"remaining"} == 0
$state->{"mode"} eq "none" $state->{"mode"} eq "content-length" $state->{"remaining"} == 0
Truth table100%4/4
A or B and C
A= $state->{"mode"} eq "none"B= $state->{"mode"} eq "content-length"C= $state->{"remaining"} == 0
ABCresult
1XX1
0111
00X0
0100
523 || ($state->{mode} eq 'content-length'
524 && $state->{remaining} == 0)) {
525 6 $self->_finish_active_response;
526 6 return 0;
527 }
528  
529 56 return 1;
530 }
531  
532 58 ▶sub _http_client_native_fallback_input ($self, $bytes) {
Subroutine _http_client_native_fallback_input: called CC=8 SCAR=21.6
533 58 ▶ return 0 if $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_closed 0 58 58
534  
535 58 $self->{_http_client_input} .= $bytes;
536 58 $self->_drive_http1;
537  
538 58 ▶ return 0 if $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_closed 20 38 58
539 return 0 if $self->{_http_client_pending_upgrade}
540 38 ▶ || $self->{_http_client_pending_connect};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_client_pending_upgrade"} or $self->{"_http_client_pending_connect"} 0 38 38
Condition33%1/3
$self->{"_http_client_pending_upgrade"} or $self->{"_http_client_pending_connect"}
l!l&&r!l&&!r
0038
MC/DC0%0/2
$self->{"_http_client_pending_upgrade"} or $self->{"_http_client_pending_connect"}
$self->{"_http_client_pending_upgrade"} $self->{"_http_client_pending_connect"}
Truth table33%1/3
A or B
A= $self->{"_http_client_pending_upgrade"}B= $self->{"_http_client_pending_connect"}
ABresult
1X1
011
000
541  
542 my $transaction = $self->{_http_client_active_transaction}
543 38 ▶ or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $transaction = $self->{"_http_client_active_transaction"} or return 0 23 15 38
544 23 ▶ return 0 if !$transaction->response;
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->response 19 4 23
545  
546 4 ▶ return $self->{_http_client_response_state} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_http_client_response_state'} ? : 4 0 4
547 }
548  
549 58 ▶sub _decimal_content_length ($value) {
Subroutine _decimal_content_length: called CC=6 SCAR=22.1
550 58 my $digits = $value;
551 58 $digits =~ s/\A0+(?=\d)//;
552 58 ▶ croak 'invalid or conflicting response Content-Length'
Branch: 1 branch
BranchTrueFalseTotal
if $digits eq "" or not $digits =~ /\A[0-9]+\z/u 0 58 58
Condition33%1/3
$digits eq "" or not $digits =~ /\A[0-9]+\z/u
l!l&&r!l&&!r
0058
MC/DC0%0/2
$digits eq "" or not $digits =~ /\A[0-9]+\z/u
$digits eq "" not $digits =~ /\A[0-9]+\z/u
Truth table33%1/3
A or not(B)
A= $digits eq ""B= not $digits =~ /\A[0-9]+\z/u
ABresult
1X1
011
000
553 if $digits eq '' || $digits !~ /\A[0-9]+\z/;
554 58 ▶ croak 'response Content-Length exceeds supported range'
Branch: 1 branch
BranchTrueFalseTotal
if length $digits > length $MAX_CONTENT_LENGTH or length $digits == length $MAX_CONTENT_LENGTH and $digits gt $MAX_CONTENT_LENGTH 0 58 58
Condition33%2/6
length $digits > length $MAX_CONTENT_LENGTH or length $digits == length $MAX_CONTENT_LENGTH and $digits gt $MAX_CONTENT_LENGTH
l!l&&r!l&&!r
0058
length $digits == length $MAX_CONTENT_LENGTH and $digits gt $MAX_CONTENT_LENGTH
!ll&&!rl&&r
5800
MC/DC0%0/3
length $digits > length $MAX_CONTENT_LENGTH or length $digits == length $MAX_CONTENT_LENGTH and $digits gt $MAX_CONTENT_LENGTH
length $digits > length $MAX_CONTENT_LENGTH length $digits == length $MAX_CONTENT_LENGTH $digits gt $MAX_CONTENT_LENGTH
Truth table25%1/4
A or B and C
A= length $digits > length $MAX_CONTENT_LENGTHB= length $digits == length $MAX_CONTENT_LENGTHC= $digits gt $MAX_CONTENT_LENGTH
ABCresult
1XX1
0111
00X0
0100
555 if length($digits) > length($MAX_CONTENT_LENGTH)
556 || (length($digits) == length($MAX_CONTENT_LENGTH)
557 && $digits gt $MAX_CONTENT_LENGTH);
558 58 return 0 + $digits;
559 }
560  
561 60 ▶sub _response_content_length ($response) {
Subroutine _response_content_length: called CC=6 SCAR=18.2
562 60 my @values = $response->_header_values_list('Content-Length');
563 60 ▶ return undef if !@values;
Branch: 1 branch
BranchTrueFalseTotal
unless @values 2 58 60
564  
565 58 my $length;
566 58 for my $value (@values) {
567 58 for my $member (split /,/, $value, -1) {
568 58 $member =~ s/\A[ \t]+//;
569 58 $member =~ s/[ \t]+\z//;
570 58 my $parsed = _decimal_content_length($member);
571 58 ▶ croak 'invalid or conflicting response Content-Length'
Branch: 1 branch
BranchTrueFalseTotal
if defined $length and $length != $parsed 0 58 58
Condition33%1/3
defined $length and $length != $parsed
!ll&&!rl&&r
5800
MC/DC0%0/2
defined $length and $length != $parsed
defined $length $length != $parsed
Truth table33%1/3
A and B
A= defined $lengthB= $length != $parsed
ABresult
0X0
100
111
572 if defined($length) && $length != $parsed;
573 58 $length = $parsed;
574 }
575 }
576 58 return $length;
577 }
578  
579 67 ▶sub _connection_tokens ($response) {
Subroutine _connection_tokens: called CC=4 SCAR=13.9
580 67 my %token;
581 67 for my $value ($response->_header_values_list('Connection')) {
582 7 for my $member (split /,/, $value, -1) {
583 7 $member =~ s/\A[ \t]+//;
584 7 $member =~ s/[ \t]+\z//;
585 7 ▶ next if $member eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $member eq "" 0 7 7
586 7 $token{lc $member} = 1;
587 }
588 }
589 67 return \%token;
590 }
591  
592 67 ▶sub _response_keep_alive ($response) {
Subroutine _response_keep_alive: called CC=4 SCAR=13.9
593 67 my $token = _connection_tokens($response);
594 67 ▶ return 0 if $token->{close};
Branch: 1 branch
BranchTrueFalseTotal
if $token->{"close"} 4 63 67
595 63 ▶ return 1 if $response->version eq '1.1';
Branch: 1 branch
BranchTrueFalseTotal
if $response->version eq "1.1" 61 2 63
596 2 ▶ return $token->{'keep-alive'} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$token->{'keep-alive'} ? : 0 2 2
597 }
598  
599 67 ▶sub _response_transfer_mode ($request, $response) {
Subroutine _response_transfer_mode: called CC=19 SCAR=32.3
600 67 my $status = $response->status;
601 67 my $keep_alive = _response_keep_alive($response);
602 67 my @transfer = $response->_header_values_list('Transfer-Encoding');
603 67 my @length_fields = $response->_header_values_list('Content-Length');
604  
605 67 ▶ if ($status >= 100 && $status < 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status >= 100 and $status < 200) 2 65 67
Condition66%2/3
$status >= 100 and $status < 200
!ll&&!rl&&r
0652
MC/DC50%1/2
$status >= 100 and $status < 200
$status >= 100 $status < 200
Truth table66%2/3
A and B
A= $status >= 100B= $status < 200
ABresult
0X0
100
111
606 2 ▶ croak 'informational response must not contain Content-Length or Transfer-Encoding'
Branch: 1 branch
BranchTrueFalseTotal
if @transfer or @length_fields 0 2 2
Condition33%1/3
@transfer or @length_fields
l!l&&r!l&&!r
002
MC/DC0%0/2
@transfer or @length_fields
@transfer @length_fields
Truth table33%1/3
A or B
A= @transferB= @length_fields
ABresult
1X1
011
000
607 if @transfer || @length_fields;
608 2 return { mode => 'none', keep_alive => $keep_alive };
609 }
610  
611 65 ▶ if ($status == 204) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status == 204) 0 65 65
612 0 ▶ croak '204 response must not contain Content-Length or Transfer-Encoding'
Branch: 1 branch
BranchTrueFalseTotal
if @transfer or @length_fields 0 0 0
Condition0%0/3
@transfer or @length_fields
l!l&&r!l&&!r
000
MC/DC0%0/2
@transfer or @length_fields
@transfer @length_fields
Truth table0%0/3
A or B
A= @transferB= @length_fields
ABresult
1X1
011
000
613 if @transfer || @length_fields;
614 0 return { mode => 'none', keep_alive => $keep_alive };
615 }
616  
617 65 ▶ if (uc($request->method) eq 'HEAD' || $status == 304) {
Branch: 1 branch
BranchTrueFalseTotal
if (uc $request->method eq "HEAD" or $status == 304) 1 64 65
Condition66%2/3
uc $request->method eq "HEAD" or $status == 304
l!l&&r!l&&!r
1064
MC/DC50%1/2
uc $request->method eq "HEAD" or $status == 304
uc $request->method eq "HEAD" $status == 304
Truth table66%2/3
A or B
A= uc $request->method eq "HEAD"B= $status == 304
ABresult
1X1
011
000
618 1 return { mode => 'none', keep_alive => $keep_alive };
619 }
620  
621 64 ▶ if (@transfer && @length_fields) {
Branch: 1 branch
BranchTrueFalseTotal
if (@transfer and @length_fields) 1 63 64
Condition100%3/3
@transfer and @length_fields
!ll&&!rl&&r
6031
MC/DC100%2/2
@transfer and @length_fields
@transfer @length_fields
Truth table100%3/3
A and B
A= @transferB= @length_fields
ABresult
0X0
100
111
622 1 croak 'response cannot contain both Transfer-Encoding and Content-Length';
623 }
624  
625 63 ▶ if (@transfer) {
Branch: 1 branch
BranchTrueFalseTotal
if (@transfer) 3 60 63
626 3 my @coding;
627 3 for my $value (@transfer) {
628 3 for my $member (split /,/, $value, -1) {
629 3 $member =~ s/\A[ \t]+//;
630 3 $member =~ s/[ \t]+\z//;
631 3 ▶ croak 'invalid response Transfer-Encoding' if $member eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $member eq "" 0 3 3
632 3 push @coding, lc $member;
633 }
634 }
635 3 ▶ croak 'unsupported response Transfer-Encoding; only chunked is currently implemented'
Branch: 1 branch
BranchTrueFalseTotal
if @coding != 1 or $coding[0] ne "chunked" 0 3 3
Condition33%1/3
@coding != 1 or $coding[0] ne "chunked"
l!l&&r!l&&!r
003
MC/DC0%0/2
@coding != 1 or $coding[0] ne "chunked"
@coding != 1 $coding[0] ne "chunked"
Truth table33%1/3
A or B
A= @coding != 1B= $coding[0] ne "chunked"
ABresult
1X1
011
000
636 if @coding != 1 || $coding[0] ne 'chunked';
637 return {
638 3 mode => 'chunked',
639 keep_alive => $keep_alive,
640 decoder => $CHUNKED->new,
641 };
642 }
643  
644 60 my $length = _response_content_length($response);
645 60 ▶ if (defined $length) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $length) 58 2 60
646 return {
647 58 mode => 'content-length',
648 keep_alive => $keep_alive,
649 remaining => $length,
650 };
651 }
652  
653 return {
654 2 mode => 'close',
655 keep_alive => 0,
656 };
657 }
658  
659 116 ▶sub _same_active_transaction ($self, $transaction) {
Subroutine _same_active_transaction: called CC=2 SCAR=7.1
660 116 my $active = $self->{_http_client_active_transaction};
661 116 ▶ return $active && refaddr($active) == refaddr($transaction);
Condition66%2/3
$active && builtin::refaddr($active) == builtin::refaddr($transaction)
!ll&&!rl&&r
20114
MC/DC50%1/2
$active && builtin::refaddr($active) == builtin::refaddr($transaction)
$active builtin::refaddr($active) == builtin::refaddr($transaction)
Truth table66%2/3
A && B
A= $activeB= builtin::refaddr($active) == builtin::refaddr($transaction)
ABresult
0X0
100
111
662 }
663  
664 105 ▶sub _callback ($self, $name, @args) {
Subroutine _callback: called CC=2 SCAR=7.1
665 105 ▶ my $callback = $self->{_http_client_callbacks}{$name} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $callback = $self->{"_http_client_callbacks"}{$name} or return 105 0 105
666 105 $callback->(@args);
667 105 return;
668 }
669  
670 74 ▶sub _clear_active_transaction ($self) {
Subroutine _clear_active_transaction: called CC=1 SCAR=0.0
671 74 $self->{_http_client_active_transaction} = undef;
672 74 $self->{_http_client_callbacks} = undef;
673 74 $self->{_http_client_request_state} = undef;
674 74 $self->{_http_client_response_state} = undef;
675 74 $self->{_http_client_pending_upgrade} = undef;
676 74 $self->{_http_client_pending_connect} = undef;
677 74 return;
678 }
679  
680 9 ▶sub _write_http_request_body ($self, $transaction, $body, $final, $operation) {
Subroutine _write_http_request_body: called CC=14 SCAR=26.6
681 9 ▶ croak "$operation(): Transaction is not active on this HTTP connection"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_same_active_transaction($transaction) 0 9 9
682 if !$self->_same_active_transaction($transaction);
683  
684 my $state = $self->{_http_client_request_state}
685 9 ▶ or croak "$operation(): Request body state is unavailable";
Branch: 1 branch
BranchTrueFalseTotal
my $state = $self->{"_http_client_request_state"} or croak("$operation(): Request body state is unavailable") 9 0 9
686 croak "$operation(): Request does not have an incremental body producer"
687 9 ▶ if !$state->{streaming};
Branch: 1 branch
BranchTrueFalseTotal
unless $state->{"streaming"} 0 9 9
688 croak "$operation(): streaming Request body is already complete"
689 9 ▶ if $state->{complete};
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"complete"} 0 9 9
690  
691 9 my $bytes = _byte_string($operation, $body);
692 9 my $new_sent = $state->{sent} + length($bytes);
693 9 ▶ if (defined($state->{expected}) && $new_sent > $state->{expected}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $state->{"expected"} and $new_sent > $state->{"expected"}) 1 8 9
Condition100%3/3
defined $state->{"expected"} and $new_sent > $state->{"expected"}
!ll&&!rl&&r
441
MC/DC100%2/2
defined $state->{"expected"} and $new_sent > $state->{"expected"}
defined $state->{"expected"} $new_sent > $state->{"expected"}
Truth table100%3/3
A and B
A= defined $state->{"expected"}B= $new_sent > $state->{"expected"}
ABresult
0X0
100
111
694 1 croak "$operation(): Request body exceeds Content-Length";
695 }
696 8 ▶ if ($final && defined($state->{expected}) && $new_sent != $state->{expected}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($final and defined $state->{"expected"} and $new_sent != $state->{"expected"}) 1 7 8
Condition100%6/6
$final and defined $state->{"expected"} and $new_sent != $state->{"expected"}
!ll&&!rl&&r
521
$final and defined $state->{"expected"}
!ll&&!rl&&r
323
MC/DC100%3/3
$final and defined $state->{"expected"} and $new_sent != $state->{"expected"}
$final defined $state->{"expected"} $new_sent != $state->{"expected"}
Truth table100%4/4
A and B and C
A= $finalB= defined $state->{"expected"}C= $new_sent != $state->{"expected"}
ABCresult
0XX0
10X0
1100
1111
697 1 croak "$operation(): Request body length does not match Content-Length";
698 }
699  
700 my $wire = $state->{chunked}
701 7 ▶ ? _chunk_wire($bytes) . ($final ? "0\r\n\r\n" : '')
Branch: 2 branches
BranchTrueFalseTotal
$state->{'chunked'} ? : 4 3 7
$final ? : 2 2 4
702 : $bytes;
703 7 ▶ my $accepted = length($wire) ? $self->write($wire) : 1;
Branch: 1 branch
BranchTrueFalseTotal
length $wire ? : 7 0 7
704  
705 7 $state->{sent} = $new_sent;
706 7 ▶ $state->{complete} = 1 if $final;
Branch: 1 branch
BranchTrueFalseTotal
if $final 4 3 7
707 7 return $accepted;
708 }
709  
710 17 ▶sub _buffer_response_chunk ($self, $chunk) {
Subroutine _buffer_response_chunk: called CC=4 SCAR=14.0
711 17 ▶ my $state = $self->{_http_client_response_state} or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $state = $self->{"_http_client_response_state"} or return 1 17 0 17
712 17 ▶ return 1 if !exists $state->{buffer_limit};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $state->{"buffer_limit"} 0 17 17
713  
714 17 my $new_length = length($state->{buffer}) + length($chunk);
715 17 ▶ if ($new_length > $state->{buffer_limit}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_length > $state->{"buffer_limit"}) 1 16 17
716 1 my $limit = $state->{buffer_limit};
717 1 $self->_fail_active_transaction(
718 "response body exceeds buffer_body limit of $limit bytes", 1,
719 );
720 1 return 0;
721 }
722  
723 16 $state->{buffer} .= $chunk;
724 16 return 1;
725 }
726  
727 60 ▶sub _finish_active_response ($self) {
Subroutine _finish_active_response: called CC=13 SCAR=26.1
728 60 ▶ my $transaction = $self->{_http_client_active_transaction} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $transaction = $self->{"_http_client_active_transaction"} or return 60 0 60
729 60 ▶ my $response = $transaction->response or return;
Branch: 1 branch
BranchTrueFalseTotal
my $response = $transaction->response or return 60 0 60
730 my $state = $self->{_http_client_response_state}
731 60 ▶ or croak 'response completion requires framing state';
Branch: 1 branch
BranchTrueFalseTotal
my $state = $self->{"_http_client_response_state"} or croak("response completion requires framing state") 60 0 60
732 60 my $request_state = $self->{_http_client_request_state};
733 60 my $callback = $self->{_http_client_callbacks}{on_complete};
734 60 ▶ my $keep_alive = $state->{keep_alive} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$state->{'keep_alive'} ? : 53 7 60
735  
736 60 ▶ if ($request_state && $request_state->{streaming} && !$request_state->{complete}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request_state and $request_state->{"streaming"} and not $request_state->{"complete"}) 1 59 60
Condition83%5/6
$request_state and $request_state->{"streaming"} and not $request_state->{"complete"}
!ll&&!rl&&r
5541
$request_state and $request_state->{"streaming"}
!ll&&!rl&&r
0555
MC/DC66%2/3
$request_state and $request_state->{"streaming"} and not $request_state->{"complete"}
$request_state $request_state->{"streaming"} not $request_state->{"complete"}
Truth table75%3/4
A and B and not(C)
A= $request_stateB= $request_state->{"streaming"}C= not $request_state->{"complete"}
ABCresult
0XX0
10X0
1100
1111
737 1 ▶ if (my $body = $transaction->_request_body_object) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $transaction->_request_body_object) 1 0 1
738 1 $body->_cancel;
739 }
740 1 $keep_alive = 0;
741 1 $self->{_http_client_reusable} = 0;
742 }
743  
744 $response->_set_received_body($state->{buffer})
745 60 ▶ if exists $state->{buffer_limit};
Branch: 1 branch
BranchTrueFalseTotal
if exists $state->{"buffer_limit"} 16 44 60
746 60 $response->_mark_complete;
747 60 $transaction->_mark_complete;
748 60 $self->_clear_active_transaction;
749  
750 60 ▶ if (!$keep_alive) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($keep_alive) 7 53 60
751 7 $self->{_http_client_reusable} = 0;
752 7 $self->{_http_client_input} = '';
753 7 ▶ $self->close if !$self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_closed 7 0 7
754 }
755  
756 60 ▶ $callback->($transaction) if $callback;
Branch: 1 branch
BranchTrueFalseTotal
if $callback 60 0 60
757 60 return;
758 }
759  
760 6 ▶sub _fail_active_transaction ($self, $error, $close_connection = 1) {
Subroutine _fail_active_transaction: called CC=7 SCAR=20.2
761 6 my $transaction = $self->{_http_client_active_transaction};
762 6 ▶ return if !$transaction || $transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if not $transaction or $transaction->is_terminal 0 6 6
Condition33%1/3
not $transaction or $transaction->is_terminal
l!l&&r!l&&!r
006
MC/DC0%0/2
not $transaction or $transaction->is_terminal
not $transaction $transaction->is_terminal
Truth table33%1/3
not(A) or B
A= not $transactionB= $transaction->is_terminal
ABresult
1X1
011
000
763  
764 6 my $callback = $self->{_http_client_callbacks}{on_error};
765 6 $transaction->_fail($error);
766 6 $self->_clear_active_transaction;
767 6 $self->{_http_client_reusable} = 0;
768 6 $self->{_http_client_input} = '';
769  
770 6 ▶ $self->close if $close_connection && !$self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $close_connection and not $self->is_closed 5 1 6
Condition66%2/3
$close_connection and not $self->is_closed
!ll&&!rl&&r
105
MC/DC50%1/2
$close_connection and not $self->is_closed
$close_connection not $self->is_closed
Truth table66%2/3
A and not(B)
A= $close_connectionB= not $self->is_closed
ABresult
0X0
100
111
771 6 ▶ $callback->($transaction, $error) if $callback;
Branch: 1 branch
BranchTrueFalseTotal
if $callback 6 0 6
772 6 return;
773 }
774  
775 3 ▶sub _cancel_http_transaction ($self, $transaction) {
Subroutine _cancel_http_transaction: called CC=4 SCAR=14.2
776 3 ▶ return if $transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal 0 3 3
777 3 ▶ croak 'cancel(): Transaction is not active on this HTTP connection'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_same_active_transaction($transaction) 0 3 3
778 if !$self->_same_active_transaction($transaction);
779  
780 3 $transaction->_mark_cancelled;
781 3 $self->_clear_active_transaction;
782 3 $self->{_http_client_reusable} = 0;
783 3 $self->{_http_client_input} = '';
784 3 ▶ $self->close if !$self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_closed 3 0 3
785 3 return;
786 }
787  
788 62 ▶sub _consume_response_body ($self) {
Subroutine _consume_response_body: called CC=36 SCAR=39.8
789 62 ▶ my $transaction = $self->{_http_client_active_transaction} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $transaction = $self->{"_http_client_active_transaction"} or return 0 62 0 62
790 62 ▶ my $response = $transaction->response or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $response = $transaction->response or return 0 62 0 62
791 62 ▶ my $state = $self->{_http_client_response_state} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $state = $self->{"_http_client_response_state"} or return 0 62 0 62
792  
793 62 ▶ if ($state->{mode} eq 'content-length') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"mode"} eq "content-length") 51 11 62
794 51 ▶ if ($state->{remaining} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"remaining"} == 0) 0 51 51
795 0 $self->_finish_active_response;
796 0 return 1;
797 }
798 51 ▶ return 0 if !length($self->{_http_client_input});
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"_http_client_input"} 0 51 51
799  
800 51 my $available = length($self->{_http_client_input});
801 my $take = $available < $state->{remaining}
802 51 ▶ ? $available : $state->{remaining};
Branch: 1 branch
BranchTrueFalseTotal
$available < $state->{'remaining'} ? : 1 50 51
803 51 my $chunk = substr($self->{_http_client_input}, 0, $take, '');
804 51 $state->{remaining} -= $take;
805  
806 51 ▶ if (length($chunk) && exists $state->{buffer_limit}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $chunk and exists $state->{"buffer_limit"}) 13 38 51
Condition66%2/3
length $chunk and exists $state->{"buffer_limit"}
!ll&&!rl&&r
03813
MC/DC50%1/2
length $chunk and exists $state->{"buffer_limit"}
length $chunk exists $state->{"buffer_limit"}
Truth table66%2/3
A and B
A= length $chunkB= exists $state->{"buffer_limit"}
ABresult
0X0
100
111
807 13 ▶ return 1 if !$self->_buffer_response_chunk($chunk);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_buffer_response_chunk($chunk) 0 13 13
808 }
809  
810 51 ▶ if (length($chunk) && $self->{_http_client_callbacks}{on_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $chunk and $self->{"_http_client_callbacks"}{"on_body"}) 33 18 51
Condition66%2/3
length $chunk and $self->{"_http_client_callbacks"}{"on_body"}
!ll&&!rl&&r
01833
MC/DC50%1/2
length $chunk and $self->{"_http_client_callbacks"}{"on_body"}
length $chunk $self->{"_http_client_callbacks"}{"on_body"}
Truth table66%2/3
A and B
A= length $chunkB= $self->{"_http_client_callbacks"}{"on_body"}
ABresult
0X0
100
111
811 33 $self->_callback('on_body', $transaction, $response, $chunk);
812 33 ▶ return 1 if !$self->_same_active_transaction($transaction);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_same_active_transaction($transaction) 1 32 33
813 }
814  
815 50 ▶ $self->_finish_active_response if $state->{remaining} == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"remaining"} == 0 50 0 50
816 50 return 1;
817 }
818  
819 11 ▶ if ($state->{mode} eq 'chunked') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"mode"} eq "chunked") 7 4 11
820 7 ▶ return 0 if !length($self->{_http_client_input});
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"_http_client_input"} 2 5 7
821  
822 5 my ($done, $decoded);
823 my $emit = $self->{_http_client_callbacks}{on_body}
824 5 ▶ || exists($state->{buffer_limit});
Condition66%2/3
$self->{'_http_client_callbacks'}{'on_body'} || exists $state->{'buffer_limit'}
l!l&&r!l&&!r
230
MC/DC0%0/2
$self->{'_http_client_callbacks'}{'on_body'} || exists $state->{'buffer_limit'}
$self->{'_http_client_callbacks'}{'on_body'} exists $state->{'buffer_limit'}
Truth table66%2/3
A || B
A= $self->{'_http_client_callbacks'}{'on_body'}B= exists $state->{'buffer_limit'}
ABresult
1X1
011
000
825 5 my $ok = eval {
826 ($done, $decoded) = $state->{decoder}->feed(
827 5 ▶ $self->{_http_client_input}, $emit ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
$emit ? : 5 0 5
828 );
829 5 1;
830 };
831 5 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 5 5
832 0 my $error = "$@";
833 0 $self->_fail_active_transaction(
834 "malformed HTTP/1 chunked response body: $error", 1,
835 );
836 0 return 1;
837 }
838  
839 5 ▶ if (defined($decoded) && length($decoded)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $decoded and length $decoded and exists $state->{"buffer_limit"}) 3 2 5
Condition50%3/6
defined $decoded and length $decoded and exists $state->{"buffer_limit"}
!ll&&!rl&&r
023
defined $decoded and length $decoded
!ll&&!rl&&r
005
MC/DC33%1/3
defined $decoded and length $decoded and exists $state->{"buffer_limit"}
defined $decoded length $decoded exists $state->{"buffer_limit"}
Truth table50%2/4
A and B and C
A= defined $decodedB= length $decodedC= exists $state->{"buffer_limit"}
ABCresult
0XX0
10X0
1100
1111
840 && exists $state->{buffer_limit}) {
841 3 ▶ return 1 if !$self->_buffer_response_chunk($decoded);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_buffer_response_chunk($decoded) 1 2 3
842 }
843  
844 4 ▶ if (defined($decoded) && length($decoded)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $decoded and length $decoded and $self->{"_http_client_callbacks"}{"on_body"}) 2 2 4
Condition50%3/6
defined $decoded and length $decoded and $self->{"_http_client_callbacks"}{"on_body"}
!ll&&!rl&&r
022
defined $decoded and length $decoded
!ll&&!rl&&r
004
MC/DC33%1/3
defined $decoded and length $decoded and $self->{"_http_client_callbacks"}{"on_body"}
defined $decoded length $decoded $self->{"_http_client_callbacks"}{"on_body"}
Truth table50%2/4
A and B and C
A= defined $decodedB= length $decodedC= $self->{"_http_client_callbacks"}{"on_body"}
ABCresult
0XX0
10X0
1100
1111
845 && $self->{_http_client_callbacks}{on_body}) {
846 2 $self->_callback('on_body', $transaction, $response, $decoded);
847 2 ▶ return 1 if !$self->_same_active_transaction($transaction);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_same_active_transaction($transaction) 0 2 2
848 }
849  
850 4 ▶ $self->_finish_active_response if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 2 2 4
851 4 return 1;
852 }
853  
854 4 ▶ if ($state->{mode} eq 'close') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"mode"} eq "close") 4 0 4
855 4 ▶ return 0 if !length($self->{_http_client_input});
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"_http_client_input"} 2 2 4
856 my $chunk = substr(
857 $self->{_http_client_input}, 0,
858 2 length($self->{_http_client_input}), '',
859 );
860  
861 2 ▶ if (length($chunk) && exists $state->{buffer_limit}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $chunk and exists $state->{"buffer_limit"}) 1 1 2
Condition66%2/3
length $chunk and exists $state->{"buffer_limit"}
!ll&&!rl&&r
011
MC/DC50%1/2
length $chunk and exists $state->{"buffer_limit"}
length $chunk exists $state->{"buffer_limit"}
Truth table66%2/3
A and B
A= length $chunkB= exists $state->{"buffer_limit"}
ABresult
0X0
100
111
862 1 ▶ return 1 if !$self->_buffer_response_chunk($chunk);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_buffer_response_chunk($chunk) 0 1 1
863 }
864  
865 2 ▶ if (length($chunk) && $self->{_http_client_callbacks}{on_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $chunk and $self->{"_http_client_callbacks"}{"on_body"}) 1 1 2
Condition66%2/3
length $chunk and $self->{"_http_client_callbacks"}{"on_body"}
!ll&&!rl&&r
011
MC/DC50%1/2
length $chunk and $self->{"_http_client_callbacks"}{"on_body"}
length $chunk $self->{"_http_client_callbacks"}{"on_body"}
Truth table66%2/3
A and B
A= length $chunkB= $self->{"_http_client_callbacks"}{"on_body"}
ABresult
0X0
100
111
866 1 $self->_callback('on_body', $transaction, $response, $chunk);
867 }
868 2 return 1;
869 }
870  
871 0 $self->_finish_active_response;
872 0 return 1;
873 }
874  
875 58 ▶sub _drive_http1 ($self) {
Subroutine _drive_http1: called CC=7 SCAR=19.7
876 58 ▶ return if $self->{_http_client_driving} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_client_driving"} or $self->is_closed 0 58 58
Condition33%1/3
$self->{"_http_client_driving"} or $self->is_closed
l!l&&r!l&&!r
0058
MC/DC0%0/2
$self->{"_http_client_driving"} or $self->is_closed
$self->{"_http_client_driving"} $self->is_closed
Truth table33%1/3
A or B
A= $self->{"_http_client_driving"}B= $self->is_closed
ABresult
1X1
011
000
877 58 local $self->{_http_client_driving} = 1;
878  
879 58 ▶ while (!$self->is_closed) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_closed) 96 20 116
880 96 ▶ my $transaction = $self->{_http_client_active_transaction} or last;
Branch: 1 branch
BranchTrueFalseTotal
my $transaction = $self->{"_http_client_active_transaction"} or last 81 15 96
881  
882 81 ▶ last if !$transaction->response;
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->response 19 62 81
883  
884 62 my $progress = $self->_consume_response_body;
885 62 ▶ last if !$progress;
Branch: 1 branch
BranchTrueFalseTotal
unless $progress 4 58 62
886 }
887  
888 58 return;
889 }
890  
891 2 ▶sub on_eof ($self) {
Subroutine on_eof: called CC=9 SCAR=26.9
Pod documented
892 2 my $transaction = $self->{_http_client_active_transaction};
893 2 ▶ if ($transaction && !$transaction->is_terminal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($transaction and not $transaction->is_terminal) 2 0 2
Condition33%1/3
$transaction and not $transaction->is_terminal
!ll&&!rl&&r
002
MC/DC0%0/2
$transaction and not $transaction->is_terminal
$transaction not $transaction->is_terminal
Truth table33%1/3
A and not(B)
A= $transactionB= not $transaction->is_terminal
ABresult
0X0
100
111
894 2 my $state = $self->{_http_client_response_state};
895 2 ▶ if ($transaction->response && $state && $state->{mode} eq 'close') {
Branch: 1 branch
BranchTrueFalseTotal
if ($transaction->response and $state and $state->{'mode'} eq 'close') { } 2 0 2
Condition33%2/6
$transaction->response and $state and $state->{"mode"} eq "close"
!ll&&!rl&&r
002
$transaction->response and $state
!ll&&!rl&&r
002
MC/DC0%0/3
$transaction->response and $state and $state->{"mode"} eq "close"
$transaction->response $state $state->{"mode"} eq "close"
Truth table25%1/4
A and B and C
A= $transaction->responseB= $stateC= $state->{"mode"} eq "close"
ABCresult
0XX0
10X0
1100
1111
896 2 ▶ $self->_consume_response_body if length($self->{_http_client_input});
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"_http_client_input"} 0 2 2
897 $self->_finish_active_response
898 2 ▶ if $self->{_http_client_active_transaction};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_client_active_transaction"} 2 0 2
899 } else {
900 0 $self->_fail_active_transaction(
901 'unexpected EOF before HTTP response completed', 0,
902 );
903 }
904 }
905  
906 2 $self->{_http_client_reusable} = 0;
907 2 ▶ $self->close if !$self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_closed 0 2 2
908 2 return;
909 }
910  
911 0 ▶sub on_error ($self, $error) {
Subroutine on_error: not called CC=1 SCAR=6.9
Pod documented
912 0 $self->_fail_active_transaction($error, 0);
913 0 $self->{_http_client_reusable} = 0;
914 0 return;
915 }
916  
917 44 ▶sub on_close ($self) {
Subroutine on_close: called CC=3 SCAR=11.0
Pod documented
918 44 ▶ if (my $transaction = $self->{_http_client_active_transaction}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $transaction = $self->{"_http_client_active_transaction"}) 1 43 44
919 1 ▶ $self->_fail_active_transaction(
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->is_terminal 1 0 1
920 'HTTP connection closed before Transaction completed', 0,
921 ) if !$transaction->is_terminal;
922 }
923 44 $self->{_http_client_reusable} = 0;
924 44 return;
925 }
926  
927 19 1;
928  
929 __END__
« HTTP/Client.pm ↑ Summary HTTP/_ServerConnect.pm »