blib/lib/Unblock/HTTP1/Client.pm

filter: Statementstmt 96.2% 363 / 377 Branchbran 73.3% 195 / 266 Conditioncond 58.8% 70 / 119 MC/DCmcdc 35.3% 23 / 65 Subroutinesub 89.6% 26 / 29 Podpod 100% 3 / 3 totaltotal 79.1% 680 / 859 CC 178 SCAR 39.4
CC
178
Cov
82%
_drive
112.0
request
30.0
_transaction_write
18.7
CRAP 51.5
« blib/lib/Unblock/HTTP1/_Wire.pm ↑ Summary blib/lib/Unblock/HTTP1/Server.pm »
1 package Unblock::HTTP1::Client;
2  
3 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 29 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 29 ▶use parent 'Unblock::HTTP1::_Engine';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 29 ▶use Uniform::HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 29 ▶use Uniform::HTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 29 ▶use Unblock::HTTP1::_Native ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 29 ▶use Unblock::HTTP1::_Wire ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 29 ▶use Unblock::HTTP1::Transaction;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 29 our $VERSION = '0.13';
15  
16 66 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
17 66 my ($class, %option) = @_;
18 66 my $self = bless {
19 queue => [],
20 active => undef,
21 rx => undef,
22 }, $class;
23 66 $self->_init_engine(%option);
24 66 return $self;
25 }
26  
27 76 ▶sub request {
Subroutine request: called CC=23 SCAR=34.0
Pod documented
28 76 my ($self, @arg) = @_;
29 76 ▶ croak 'request(): connection is closed' if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 1 75 76
30 75 ▶ croak 'request(): connection has switched protocols' if $self->{switched};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"switched"} 0 75 75
31 75 ▶ croak 'request(): read side is at EOF' if $self->{eof};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"eof"} 0 75 75
32  
33 75 my ($request, %option);
34 75 ▶ if (@arg && ref($arg[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@arg and ref $arg[0]) { } 68 7 75
Condition66%2/3
@arg and ref $arg[0]
!ll&&!rl&&r
0768
MC/DC50%1/2
@arg and ref $arg[0]
@arg ref $arg[0]
Truth table66%2/3
A and B
A= @argB= ref $arg[0]
ABresult
0X0
100
111
35 68 $request = shift @arg;
36 68 ▶ croak 'request(): options must be key/value pairs' if @arg % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @arg % 2 0 68 68
37 68 %option = @arg;
38 } else {
39 7 ▶ croak 'request(): request fields must be key/value pairs' if @arg % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @arg % 2 0 7 7
40 7 my %field = @arg;
41 7 for my $name (qw(
42 stream_body
43 on_informational
44 on_response
45 on_body
46 on_data
47 on_finish
48 on_complete
49 on_error
50 on_switch
51 on_drain
52 )) {
53 70 ▶ $option{$name} = delete $field{$name} if exists $field{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $field{$name} 10 60 70
54 }
55 7 $request = Uniform::HTTP::Request->new(%field);
56 }
57  
58 75 ▶ croak 'request(): requires a Uniform HTTP request object'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $request and $request->can("method") and $request->can("target") and $request->can("header_count") and $request->can("has_buffered_body") 0 75 75
Condition33%4/12
ref $request and $request->can("method") and $request->can("target") and $request->can("header_count") and $request->can("has_buffered_body")
!ll&&!rl&&r
0075
ref $request and $request->can("method") and $request->can("target") and $request->can("header_count")
!ll&&!rl&&r
0075
ref $request and $request->can("method") and $request->can("target")
!ll&&!rl&&r
0075
ref $request and $request->can("method")
!ll&&!rl&&r
0075
MC/DC0%0/5
ref $request and $request->can("method") and $request->can("target") and $request->can("header_count") and $request->can("has_buffered_body")
ref $request $request->can("method") $request->can("target") $request->can("header_count") $request->can("has_buffered_body")
Truth table16%1/6
A and B and C and D and E
A= ref $requestB= $request->can("method")C= $request->can("target")D= $request->can("header_count")E= $request->can("has_buffered_body")
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
59 unless ref($request) && $request->can('method') && $request->can('target')
60 && $request->can('header_count') && $request->can('has_buffered_body');
61  
62 75 ▶ my $stream_body = delete($option{stream_body}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $option{'stream_body'} ? : 5 70 75
63 75 my %callbacks;
64 75 for my $name (qw(on_informational on_response on_body on_data on_finish on_complete on_error on_switch on_drain)) {
65 675 ▶ next unless exists $option{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $option{$name} 523 152 675
66 152 my $cb = delete $option{$name};
67 152 ▶ croak "request(): $name must be a coderef" unless ref($cb) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cb eq "CODE" 0 152 152
68 152 $callbacks{$name} = $cb;
69 }
70 croak 'request(): on_drain requires stream_body'
71 75 ▶ if $callbacks{on_drain} && !$stream_body;
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks{"on_drain"} and not $stream_body 0 75 75
Condition66%2/3
$callbacks{"on_drain"} and not $stream_body
!ll&&!rl&&r
7410
MC/DC0%0/2
$callbacks{"on_drain"} and not $stream_body
$callbacks{"on_drain"} not $stream_body
Truth table66%2/3
A and not(B)
A= $callbacks{"on_drain"}B= not $stream_body
ABresult
0X0
100
111
72 75 ▶ croak 'request(): unknown options: ' . join(', ', sort keys %option) if %option;
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 75 75
73  
74 75 my $tx = Unblock::HTTP1::Transaction->_new(
75 $self, $request,
76 callbacks => \%callbacks,
77 local_done => 0,
78 );
79 75 $tx->{stream_body} = $stream_body;
80 75 push @{ $self->{queue} }, $tx;
81 75 ▶ $self->_start_next unless $self->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"active"} 68 7 75
82 75 return $tx;
83 }
84  
85 0 ▶sub transaction { $_[0]{active} }
Subroutine transaction: not called CC=1 SCAR=6.9
Pod documented
86  
87 103 ▶sub _start_next {
Subroutine _start_next: called CC=7 SCAR=19.7
88 103 my ($self) = @_;
89 103 ▶ return if $self->{active} || $self->{closed} || $self->{switched};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"active"} or $self->{"closed"} or $self->{"switched"} 0 103 103
Condition33%2/6
$self->{"active"} or $self->{"closed"} or $self->{"switched"}
l!l&&r!l&&!r
00103
$self->{"active"} or $self->{"closed"}
l!l&&r!l&&!r
00103
MC/DC0%0/3
$self->{"active"} or $self->{"closed"} or $self->{"switched"}
$self->{"active"} $self->{"closed"} $self->{"switched"}
Truth table25%1/4
A or B or C
A= $self->{"active"}B= $self->{"closed"}C= $self->{"switched"}
ABCresult
1XX1
01X1
0011
0000
90 103 ▶ my $tx = shift @{ $self->{queue} } or return;
Branch: 1 branch
BranchTrueFalseTotal
my $tx = shift @{$$self{"queue"};} or return 72 31 103
91 72 my $plan;
92 72 my $ok = eval {
93 $plan = Unblock::HTTP1::_Wire::request_plan(
94 $tx->request,
95 stream_body => $tx->{stream_body},
96 72 );
97 68 1;
98 };
99 72 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 4 68 72
100 4 $tx->_fail("$@");
101 4 $tx->_invoke('on_error', $tx->error);
102 4 $tx->_notify_finish;
103 4 return $self->_start_next;
104 }
105 68 $tx->{send_plan} = $plan;
106 68 ▶ $tx->{local_done} = $plan->{body_finalized} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$plan->{'body_finalized'} ? : 63 5 68
107 68 $self->{active} = $tx;
108 # Keep framing state, but transfer serialized bytes to the output queue.
109 68 $self->_queue_output(delete $plan->{wire});
110 68 return;
111 }
112  
113 2 ▶sub _input_native_head {
Subroutine _input_native_head: called CC=10 SCAR=24.5
114 2 my ($self, $head, $response) = @_;
115 croak '_input_native_head(): cannot be called recursively from an engine callback'
116 2 ▶ if $self->{driving};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"driving"} 0 2 2
117 2 ▶ return (4, 0) if $self->{switched};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"switched"} 0 2 2
118 2 ▶ return (3, 0) if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 2 2
119 croak '_input_native_head(): cannot mix native head input with buffered portable input'
120 2 ▶ if length $self->{input};
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"input"} 0 2 2
121 croak '_input_native_head(): response received with no outstanding request'
122 2 ▶ unless $self->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"active"} 0 2 2
123 croak '_input_native_head(): response body is already active'
124 2 ▶ if $self->{rx};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"rx"} 0 2 2
125  
126 2 my ($status, $ready);
127 {
128 2 local $self->{borrowed_head} = $head;
129 2 local $self->{borrowed_message} = $response;
130 2 local $self->{native_head_preconsumed} = 1;
131 2 local $self->{driving} = 1;
132 2 $self->_drive;
133 2 ▶ $status = $self->{closed} ? 3 : $self->{switched} ? 4 : 0;
Branch: 2 branches
BranchTrueFalseTotal
$self->{'closed'} ? : 0 2 2
$self->{'switched'} ? : 0 2 2
134 2 $ready = $self->_borrowed_native_head_ready;
135 }
136 2 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 0 2 2
137 2 return ($status, $ready);
138 }
139  
140 208 ▶sub _drive {
Subroutine _drive: called CC=81 SCAR=47.2
141 208 my ($self) = @_;
142  
143 208 ▶ if (!$self->{closed} && !$self->{switched}
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"closed"} || $self->{"switched"} || $self->{"active"} and $self->_input_length) 2 206 208
Condition55%5/9
not $self->{"closed"} || $self->{"switched"} || $self->{"active"} and $self->_input_length
!ll&&!rl&&r
20602
$self->{'closed'} || $self->{'switched'} || $self->{'active'}
l!l&&r!l&&!r
02062
$self->{"closed"} or $self->{"switched"}
l!l&&r!l&&!r
00208
MC/DC25%1/4
not $self->{"closed"} || $self->{"switched"} || $self->{"active"} and $self->_input_length
$self->{"closed"} $self->{"switched"} $self->{'active'} $self->_input_length
Truth table40%2/5
not(A or B || C) and D
A= $self->{"closed"}B= $self->{"switched"}C= $self->{'active'}D= $self->_input_length
ABCDresult
1XXX0
01XX0
001X0
00000
00011
144 && !$self->{active} && $self->_input_length) {
145 2 ▶ if ($self->_input_remaining =~ /\A(?:\r\n)+\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_input_remaining =~ /\A(?:\r\n)+\z/) 1 1 2
146 1 $self->_input_clear;
147 1 return;
148 }
149 1 return $self->_connection_error(
150 'HTTP/1 response bytes received with no outstanding request'
151 );
152 }
153  
154 206 ▶ while (!$self->{closed} && !$self->{switched} && $self->{active}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"closed"} || $self->{"switched"} and $self->{"active"}) 219 32 251
Condition83%5/6
not $self->{"closed"} || $self->{"switched"} and $self->{"active"}
!ll&&!rl&&r
527219
$self->{'closed'} || $self->{'switched'}
l!l&&r!l&&!r
50246
MC/DC66%2/3
not $self->{"closed"} || $self->{"switched"} and $self->{"active"}
$self->{'closed'} $self->{'switched'} $self->{"active"}
Truth table75%3/4
not(A || B) and C
A= $self->{'closed'}B= $self->{'switched'}C= $self->{"active"}
ABCresult
1XX0
01X0
0000
0011
155 219 my $tx = $self->{active};
156 219 my $rx = $self->{rx};
157  
158 219 ▶ if (!$rx) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rx) 175 44 219
159 175 my $head = delete $self->{borrowed_head};
160 175 my $response = delete $self->{borrowed_message};
161 175 ▶ my $native_response = $response ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$response ? : 5 170 175
162 175 ▶ if (!$head) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($head) 170 5 175
163 170 my ($input, $offset) = $self->_input_window;
164 $head = Unblock::HTTP1::_Native->parse_response_head(
165 170 $input, 0, $self->{max_headers}, $offset,
166 );
167 }
168 175 ▶ if (!$head) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($head) 113 62 175
169 return $self->_connection_error('HTTP/1 response head exceeds configured limit')
170 113 ▶ if $self->_input_length > $self->{max_head_size};
Branch: 1 branch
BranchTrueFalseTotal
if $self->_input_length > $self->{"max_head_size"} 0 113 113
171 113 return;
172 }
173 62 ▶ return $self->_connection_error($head->{error}) unless $head->{ok};
Branch: 1 branch
BranchTrueFalseTotal
unless $head->{"ok"} 0 62 62
174 return $self->_connection_error('HTTP/1 response head exceeds configured limit')
175 62 ▶ if $head->{consumed} > $self->{max_head_size};
Branch: 1 branch
BranchTrueFalseTotal
if $head->{"consumed"} > $self->{"max_head_size"} 1 61 62
176 $self->_input_discard($head->{consumed})
177 61 ▶ unless $self->{native_head_preconsumed};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"native_head_preconsumed"} 59 2 61
178  
179 my $informational =
180 $head->{status} >= 100 && $head->{status} < 200
181 61 ▶ && $head->{status} != 101 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$head->{'status'} >= 100 && $head->{'status'} < 200 && $head->{'status'} != 101 ? : 4 57 61
Condition83%5/6
$head->{"status"} >= 100 and $head->{"status"} < 200 and $head->{"status"} != 101
!ll&&!rl&&r
5344
$head->{"status"} >= 100 and $head->{"status"} < 200
!ll&&!rl&&r
0538
MC/DC66%2/3
$head->{"status"} >= 100 and $head->{"status"} < 200 and $head->{"status"} != 101
$head->{"status"} >= 100 $head->{"status"} < 200 $head->{"status"} != 101
Truth table75%3/4
A and B and C
A= $head->{"status"} >= 100B= $head->{"status"} < 200C= $head->{"status"} != 101
ABCresult
0XX0
10X0
1100
1111
182 61 ▶ if (!$response) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response) 56 5 61
183 56 $response =
184 Unblock::HTTP1::_Wire::_response_from_validated_head(
185 $head, $informational,
186 );
187 }
188  
189 61 my $plan;
190 61 my $ok = eval {
191 61 ▶ $plan = Unblock::HTTP1::_Wire::response_receive_plan(
Branch: 1 branch
BranchTrueFalseTotal
$native_response ? : 5 56 61
192 $tx->request,
193 $head,
194 $native_response ? $response : undef,
195 );
196 51 1;
197 };
198 61 ▶ return $self->_connection_error("$@") unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 10 51 61
199  
200 51 ▶ if ($informational) {
Branch: 1 branch
BranchTrueFalseTotal
if ($informational) 3 48 51
201 3 my $cb = $tx->_invoke('on_informational', $response);
202 3 ▶ return $self->_connection_error($cb) unless $cb eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $cb eq 1 0 3 3
203 3 next;
204 }
205  
206 48 $tx->_set_response($response);
207  
208 my $fixed_ready = !$plan->{switch}
209 && $plan->{mode} eq 'content-length'
210 && defined($plan->{remaining})
211 48 ▶ && $self->_input_length >= $plan->{remaining};
Condition88%8/9
!$plan->{'switch'} && $plan->{'mode'} eq 'content-length' && defined $plan->{'remaining'} && $self->_input_length >= $plan->{'remaining'}
!ll&&!rl&&r
21621
not $plan->{"switch"} and $plan->{"mode"} eq "content-length" and defined $plan->{"remaining"}
!ll&&!rl&&r
21027
not $plan->{"switch"} and $plan->{"mode"} eq "content-length"
!ll&&!rl&&r
41727
MC/DC75%3/4
!$plan->{'switch'} && $plan->{'mode'} eq 'content-length' && defined $plan->{'remaining'} && $self->_input_length >= $plan->{'remaining'}
not $plan->{"switch"} $plan->{"mode"} eq "content-length" defined $plan->{"remaining"} $self->_input_length >= $plan->{'remaining'}
Truth table80%4/5
not(A) and B and C && D
A= not $plan->{"switch"}B= $plan->{"mode"} eq "content-length"C= defined $plan->{"remaining"}D= $self->_input_length >= $plan->{'remaining'}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
212 my $immediate = !$plan->{switch}
213 48 ▶ && ($plan->{mode} eq 'none' || $fixed_ready);
Condition100%6/6
!$plan->{'switch'} && ($plan->{'mode'} eq 'none' || $fixed_ready)
!ll&&!rl&&r
41628
$plan->{"mode"} eq "none" or $fixed_ready
l!l&&r!l&&!r
72116
MC/DC100%3/3
!$plan->{'switch'} && ($plan->{'mode'} eq 'none' || $fixed_ready)
!$plan->{'switch'} $plan->{"mode"} eq "none" $fixed_ready
Truth table100%4/4
not(A) && B or C
A= !$plan->{'switch'}B= $plan->{"mode"} eq "none"C= $fixed_ready
ABCresult
0XX0
1000
11X1
1011
214  
215 48 ▶ if (!$immediate) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($immediate) 20 28 48
216 $self->{rx} = $rx = {
217 response => $response,
218 mode => $plan->{mode},
219 remaining => $plan->{remaining},
220 keep_alive => $plan->{keep_alive},
221 switch => $plan->{switch},
222 20 ▶ forbid_content => $plan->{forbid_content} ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
$plan->{'forbid_content'} ? : 2 18 20
223 };
224 20 ▶ if ($rx->{mode} eq 'chunked') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rx->{"mode"} eq "chunked") 8 12 20
225 8 $rx->{decoder} = Unblock::HTTP1::_Native::Chunked->new($self->{max_chunk_extension_size});
226 }
227 }
228  
229 48 my $cb = $tx->_invoke('on_response', $response);
230 48 ▶ return $self->_connection_error($cb) unless $cb eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $cb eq 1 1 47 48
231 47 ▶ return if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 47 47
232  
233 47 ▶ if ($plan->{switch}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plan->{"switch"}) 4 43 47
234 return $self->_connection_error(
235 'protocol switch received before streaming request body completed'
236 4 ▶ ) if $tx->{stream_body} && !$tx->{local_done};
Branch: 1 branch
BranchTrueFalseTotal
if $tx->{"stream_body"} and not $tx->{"local_done"} 0 4 4
Condition33%1/3
$tx->{"stream_body"} and not $tx->{"local_done"}
!ll&&!rl&&r
400
MC/DC0%0/2
$tx->{"stream_body"} and not $tx->{"local_done"}
$tx->{"stream_body"} not $tx->{"local_done"}
Truth table33%1/3
A and not(B)
A= $tx->{"stream_body"}B= not $tx->{"local_done"}
ABresult
0X0
100
111
237 4 $tx->_finish_receive($response);
238 4 $response->mark_complete->freeze;
239 4 $tx->_mark_remote_done;
240 4 $tx->_mark_complete;
241 4 $self->{rx} = undef;
242 4 $self->_mark_switched;
243 4 $self->_fail_queued('HTTP/1 connection switched protocols');
244 4 $self->{active} = undef;
245 4 ▶ if ($self->{transport_attached}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"transport_attached"}) 0 4 4
246 0 $self->{switch_notice} = [ $tx, $response ];
247 0 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 0 0 0
248 0 return;
249 }
250 4 return $self->_deliver_switch_notice($tx, $response);
251 }
252  
253 43 ▶ if ($plan->{mode} eq 'none') {
Branch: 1 branch
BranchTrueFalseTotal
if ($plan->{"mode"} eq "none") 7 36 43
254 $self->_complete_response(
255 $tx, $response, $plan->{keep_alive},
256 7 );
257 7 next;
258 }
259  
260 36 ▶ if ($fixed_ready) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fixed_ready) 20 16 36
261 20 my $length = $plan->{remaining};
262 20 ▶ if ($length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length) 16 4 20
263 16 my $bytes = $self->_input_take($length);
264 return $self->_connection_error(
265 '205 response must not contain content'
266 16 ▶ ) if $plan->{forbid_content} && length $bytes;
Branch: 1 branch
BranchTrueFalseTotal
if $plan->{"forbid_content"} and length $bytes 0 16 16
Condition33%1/3
$plan->{"forbid_content"} and length $bytes
!ll&&!rl&&r
1600
MC/DC0%0/2
$plan->{"forbid_content"} and length $bytes
$plan->{"forbid_content"} length $bytes
Truth table33%1/3
A and B
A= $plan->{"forbid_content"}B= length $bytes
ABresult
0X0
100
111
267 16 my $body_cb = $tx->_receive_data($response, $bytes);
268 16 ▶ return $self->_connection_error($body_cb)
Branch: 1 branch
BranchTrueFalseTotal
unless $body_cb eq 1 0 16 16
269 unless $body_cb eq '1';
270 16 ▶ return if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 16 16
271 }
272 $self->_complete_response(
273 $tx, $response, $plan->{keep_alive},
274 20 );
275 20 next;
276 }
277 }
278  
279 60 ▶ $rx = $self->{rx} or next;
Branch: 1 branch
BranchTrueFalseTotal
$rx = $self->{"rx"} or next 60 0 60
280 60 ▶ if ($rx->{mode} eq 'content-length') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rx->{"mode"} eq "content-length") 11 49 60
281 11 ▶ return unless $self->_input_length;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_input_length 1 10 11
282 10 my $available = $self->_input_length;
283 my $take = $available < $rx->{remaining}
284 10 ▶ ? $available : $rx->{remaining};
Branch: 1 branch
BranchTrueFalseTotal
$available < $rx->{'remaining'} ? : 6 4 10
285 10 my $bytes = $self->_input_take($take);
286 10 $rx->{remaining} -= $take;
287 return $self->_connection_error('205 response must not contain content')
288 10 ▶ if $rx->{forbid_content} && length $bytes;
Branch: 1 branch
BranchTrueFalseTotal
if $rx->{"forbid_content"} and length $bytes 0 10 10
Condition33%1/3
$rx->{"forbid_content"} and length $bytes
!ll&&!rl&&r
1000
MC/DC0%0/2
$rx->{"forbid_content"} and length $bytes
$rx->{"forbid_content"} length $bytes
Truth table33%1/3
A and B
A= $rx->{"forbid_content"}B= length $bytes
ABresult
0X0
100
111
289 10 my $cb = $tx->_receive_data($rx->{response}, $bytes);
290 10 ▶ return $self->_connection_error($cb) unless $cb eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $cb eq 1 0 10 10
291 10 ▶ return if $tx->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $tx->is_terminal 1 9 10
292 9 ▶ if ($rx->{remaining} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rx->{"remaining"} == 0) 4 5 9
293 4 $self->_finish_response;
294 4 next;
295 }
296 5 return;
297 }
298  
299 49 ▶ if ($rx->{mode} eq 'chunked') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rx->{"mode"} eq "chunked") 26 23 49
300 26 ▶ return unless $self->_input_length;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_input_length 1 25 26
301 25 my ($input, $offset) = $self->_input_window;
302 25 my $available = $self->_input_length;
303 25 my ($done, $decoded, $leftover);
304 25 my $ok = eval {
305 ($done, $decoded, $leftover) =
306 25 $rx->{decoder}->feed($input, 1, $offset);
307 25 1;
308 };
309 25 ▶ return $self->_connection_error("$@") unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 25 25
310 25 $self->_input_discard($available - length($leftover));
311 25 ▶ if (defined($decoded) && length($decoded)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $decoded and length $decoded) 11 14 25
Condition66%2/3
defined $decoded and length $decoded
!ll&&!rl&&r
01411
MC/DC50%1/2
defined $decoded and length $decoded
defined $decoded length $decoded
Truth table66%2/3
A and B
A= defined $decodedB= length $decoded
ABresult
0X0
100
111
312 return $self->_connection_error('205 response must not contain content')
313 11 ▶ if $rx->{forbid_content};
Branch: 1 branch
BranchTrueFalseTotal
if $rx->{"forbid_content"} 1 10 11
314 10 my $cb = $tx->_receive_data($rx->{response}, $decoded);
315 10 ▶ return $self->_connection_error($cb) unless $cb eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $cb eq 1 0 10 10
316 }
317 24 ▶ return if $tx->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $tx->is_terminal 0 24 24
318 24 ▶ return unless $done;
Branch: 1 branch
BranchTrueFalseTotal
unless $done 18 6 24
319 6 $rx->{mode} = 'trailers';
320 6 delete $rx->{decoder};
321 6 next;
322 }
323  
324 23 ▶ if ($rx->{mode} eq 'trailers') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rx->{"mode"} eq "trailers") 21 2 23
325 21 my ($input, $offset) = $self->_input_window;
326 my $trailers = Unblock::HTTP1::_Native->parse_trailers(
327 21 $input, 0, $self->{max_headers}, $offset,
328 );
329 21 ▶ if (!$trailers) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($trailers) 15 6 21
330 return $self->_connection_error('HTTP/1 trailer section exceeds configured limit')
331 15 ▶ if $self->_input_length > $self->{max_head_size};
Branch: 1 branch
BranchTrueFalseTotal
if $self->_input_length > $self->{"max_head_size"} 0 15 15
332 15 return;
333 }
334 6 ▶ return $self->_connection_error($trailers->{error}) unless $trailers->{ok};
Branch: 1 branch
BranchTrueFalseTotal
unless $trailers->{"ok"} 0 6 6
335 return $self->_connection_error('HTTP/1 trailer section exceeds configured limit')
336 6 ▶ if $trailers->{consumed} > $self->{max_head_size};
Branch: 1 branch
BranchTrueFalseTotal
if $trailers->{"consumed"} > $self->{"max_head_size"} 1 5 6
337 5 for my $field (@{ $trailers->{headers} }) {
338 2 my $name = lc $field->[0];
339 2 ▶ return $self->_connection_error('forbidden framing field in HTTP/1 trailers')
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "content-length" or $name eq "transfer-encoding" or $name eq "host" or $name eq "connection" or $name eq "trailer" 0 2 2
Condition33%4/12
$name eq "content-length" or $name eq "transfer-encoding" or $name eq "host" or $name eq "connection" or $name eq "trailer"
l!l&&r!l&&!r
002
$name eq "content-length" or $name eq "transfer-encoding" or $name eq "host" or $name eq "connection"
l!l&&r!l&&!r
002
$name eq "content-length" or $name eq "transfer-encoding" or $name eq "host"
l!l&&r!l&&!r
002
$name eq "content-length" or $name eq "transfer-encoding"
l!l&&r!l&&!r
002
MC/DC0%0/5
$name eq "content-length" or $name eq "transfer-encoding" or $name eq "host" or $name eq "connection" or $name eq "trailer"
$name eq "content-length" $name eq "transfer-encoding" $name eq "host" $name eq "connection" $name eq "trailer"
Truth table16%1/6
A or B or C or D or E
A= $name eq "content-length"B= $name eq "transfer-encoding"C= $name eq "host"D= $name eq "connection"E= $name eq "trailer"
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
340 if $name eq 'content-length' || $name eq 'transfer-encoding'
341 || $name eq 'host' || $name eq 'connection' || $name eq 'trailer';
342 2 $rx->{response}->add_trailer(@$field);
343 }
344 5 $self->_input_discard($trailers->{consumed});
345 5 $self->_finish_response;
346 5 next;
347 }
348  
349 2 ▶ if ($rx->{mode} eq 'close') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rx->{"mode"} eq "close") 2 0 2
350 2 ▶ return unless $self->_input_length;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_input_length 0 2 2
351 2 my $bytes = $self->_input_take($self->_input_length);
352 return $self->_connection_error('205 response must not contain content')
353 2 ▶ if $rx->{forbid_content} && length $bytes;
Branch: 1 branch
BranchTrueFalseTotal
if $rx->{"forbid_content"} and length $bytes 0 2 2
Condition33%1/3
$rx->{"forbid_content"} and length $bytes
!ll&&!rl&&r
200
MC/DC0%0/2
$rx->{"forbid_content"} and length $bytes
$rx->{"forbid_content"} length $bytes
Truth table33%1/3
A and B
A= $rx->{"forbid_content"}B= length $bytes
ABresult
0X0
100
111
354 2 my $cb = $tx->_receive_data($rx->{response}, $bytes);
355 2 ▶ return $self->_connection_error($cb) unless $cb eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $cb eq 1 0 2 2
356 2 return;
357 }
358  
359 0 return $self->_connection_error('invalid HTTP/1 client receive state');
360 }
361 32 return;
362 }
363  
364 6 ▶sub _borrowed_native_head_ready {
Subroutine _borrowed_native_head_ready: called CC=6 SCAR=18.0
365 6 my ($self) = @_;
366 6 ▶ return 0 if $self->{closed} || $self->{switched};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} or $self->{"switched"} 1 5 6
Condition66%2/3
$self->{"closed"} or $self->{"switched"}
l!l&&r!l&&!r
015
MC/DC50%1/2
$self->{"closed"} or $self->{"switched"}
$self->{"closed"} $self->{"switched"}
Truth table66%2/3
A or B
A= $self->{"closed"}B= $self->{"switched"}
ABresult
1X1
011
000
367 5 ▶ return 0 unless $self->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"active"} 3 2 5
368 2 ▶ return 0 if $self->{rx};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"rx"} 1 1 2
369 1 ▶ return 0 if length $self->{input};
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"input"} 0 1 1
370 1 return 1;
371 }
372  
373 11 ▶sub _finish_response {
Subroutine _finish_response: called CC=3 SCAR=11.4
374 11 my ($self) = @_;
375 11 ▶ my $tx = $self->{active} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $tx = $self->{"active"} or return 11 0 11
376 11 ▶ my $rx = delete $self->{rx} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $rx = delete $self->{"rx"} or return 11 0 11
377 return $self->_complete_response(
378 $tx, $rx->{response}, $rx->{keep_alive},
379 11 );
380 }
381  
382 38 ▶sub _complete_response {
Subroutine _complete_response: called CC=5 SCAR=16.1
383 38 my ($self, $tx, $response, $keep_alive) = @_;
384 38 ▶ return if $tx->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $tx->is_terminal 0 38 38
385 38 $tx->_finish_receive($response);
386 38 $response->mark_complete->freeze;
387 38 $tx->_mark_remote_done;
388 38 ▶ $tx->{keep_alive} = $keep_alive ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$keep_alive ? : 34 4 38
389  
390 # A final response can arrive before an incremental request body has
391 # finished. The peer has already ended this HTTP exchange, so no further
392 # request-body bytes may be sent and the connection cannot be reused.
393 38 ▶ if ($tx->{stream_body} && !$tx->{local_done}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx->{"stream_body"} and not $tx->{"local_done"}) 1 37 38
Condition100%3/3
$tx->{"stream_body"} and not $tx->{"local_done"}
!ll&&!rl&&r
3611
MC/DC100%2/2
$tx->{"stream_body"} and not $tx->{"local_done"}
$tx->{"stream_body"} not $tx->{"local_done"}
Truth table100%3/3
A and not(B)
A= $tx->{"stream_body"}B= not $tx->{"local_done"}
ABresult
0X0
100
111
394 1 $tx->{request_body_cancelled} = 1;
395 1 $tx->_mark_local_done;
396 1 $tx->{keep_alive} = 0;
397 1 $self->{output} = '';
398 }
399  
400 38 $self->_retire_if_done;
401 38 return;
402 }
403  
404 40 ▶sub _retire_if_done {
Subroutine _retire_if_done: called CC=12 SCAR=25.1
405 40 my ($self) = @_;
406 40 ▶ my $tx = $self->{active} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $tx = $self->{"active"} or return 40 0 40
407 40 ▶ return unless $tx->{local_done} && $tx->{remote_done};
Branch: 1 branch
BranchTrueFalseTotal
unless $tx->{"local_done"} and $tx->{"remote_done"} 2 38 40
Condition66%2/3
$tx->{"local_done"} and $tx->{"remote_done"}
!ll&&!rl&&r
0238
MC/DC50%1/2
$tx->{"local_done"} and $tx->{"remote_done"}
$tx->{"local_done"} $tx->{"remote_done"}
Truth table66%2/3
A and B
A= $tx->{"local_done"}B= $tx->{"remote_done"}
ABresult
0X0
100
111
408 38 ▶ $tx->_mark_complete unless $tx->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $tx->is_terminal 38 0 38
409 38 my $cb = $tx->_invoke('on_complete');
410 38 $tx->_notify_finish;
411 38 ▶ return $self->_connection_error($cb) unless $cb eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $cb eq 1 1 37 38
412  
413 37 ▶ my $keep = $tx->{keep_alive} && $tx->{send_plan}{keep_alive};
Condition66%2/3
$tx->{'keep_alive'} && $tx->{'send_plan'}{'keep_alive'}
!ll&&!rl&&r
4033
MC/DC50%1/2
$tx->{'keep_alive'} && $tx->{'send_plan'}{'keep_alive'}
$tx->{'keep_alive'} $tx->{'send_plan'}{'keep_alive'}
Truth table66%2/3
A && B
A= $tx->{'keep_alive'}B= $tx->{'send_plan'}{'keep_alive'}
ABresult
0X0
100
111
414 37 ▶ my $extra = $self->_input_length ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_input_length ? : 2 35 37
415 37 $self->{active} = undef;
416  
417 # This client serializes requests and never pipelines them. Therefore,
418 # bytes already received beyond a final response boundary cannot belong to
419 # a later response. Do not retain them for a future request: doing so would
420 # allow an unsolicited response to poison the response queue.
421 37 ▶ if ($extra) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extra) 2 35 37
422 2 $self->_input_clear;
423 2 $self->{closed} = 1;
424 2 $self->_fail_queued('unexpected bytes after final HTTP/1 response');
425 2 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 0 2 2
426 2 return;
427 }
428  
429 35 ▶ if (!$keep) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($keep) 4 31 35
430 4 $self->{closed} = 1;
431 4 $self->_fail_queued('HTTP/1 connection is not reusable');
432 4 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 0 4 4
433 4 return;
434 }
435 31 $self->_start_next;
436 31 return;
437 }
438  
439 8 ▶sub _transaction_write {
Subroutine _transaction_write: called CC=15 SCAR=29.3
440 8 my ($self, $tx, $bytes, $final) = @_;
441 croak 'write(): Transaction is not active on this HTTP/1 connection'
442 8 ▶ unless $self->{active} && $self->{active} == $tx;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"active"} and $self->{"active"} == $tx 0 8 8
Condition33%1/3
$self->{"active"} and $self->{"active"} == $tx
!ll&&!rl&&r
008
MC/DC0%0/2
$self->{"active"} and $self->{"active"} == $tx
$self->{"active"} $self->{"active"} == $tx
Truth table33%1/3
A and B
A= $self->{"active"}B= $self->{"active"} == $tx
ABresult
0X0
100
111
443 8 my $plan = $tx->{send_plan};
444 8 ▶ croak 'write(): request does not have a streaming body' unless $tx->{stream_body};
Branch: 1 branch
BranchTrueFalseTotal
unless $tx->{"stream_body"} 0 8 8
445 8 ▶ croak 'write(): streaming request body is already complete' if $tx->{local_done};
Branch: 1 branch
BranchTrueFalseTotal
if $tx->{"local_done"} 0 8 8
446 8 $bytes = Unblock::HTTP1::_Wire::_bytes('request body chunk', $bytes);
447  
448 8 ▶ if ($plan->{mode} eq 'chunked') {
Branch: 2 branches
BranchTrueFalseTotal
if ($plan->{'mode'} eq 'chunked') { } 6 2 8
elsif ($plan->{'mode'} eq 'content-length') { } 2 0 2
449 6 $self->_queue_output(Unblock::HTTP1::_Wire::chunk($bytes));
450 6 ▶ if ($final) {
Branch: 1 branch
BranchTrueFalseTotal
if ($final) 2 4 6
451 2 my $trailers = Unblock::HTTP1::_Wire::_fields($tx->request, 'trailer');
452 2 $self->_queue_output(Unblock::HTTP1::_Wire::final_chunk($trailers));
453 2 $tx->_mark_local_done;
454 }
455 } elsif ($plan->{mode} eq 'content-length') {
456 2 my $remaining = $plan->{remaining};
457 2 ▶ croak 'write(): body exceeds declared Content-Length' if length($bytes) > $remaining;
Branch: 1 branch
BranchTrueFalseTotal
if length $bytes > $remaining 1 1 2
458 1 $self->_queue_output($bytes);
459 1 $remaining -= length($bytes);
460 1 $plan->{remaining} = $remaining;
461 1 ▶ croak 'end(): body ended before declared Content-Length' if $final && $remaining;
Branch: 1 branch
BranchTrueFalseTotal
if $final and $remaining 1 0 1
Condition33%1/3
$final and $remaining
!ll&&!rl&&r
001
MC/DC0%0/2
$final and $remaining
$final $remaining
Truth table33%1/3
A and B
A= $finalB= $remaining
ABresult
0X0
100
111
462 0 ▶ $tx->_mark_local_done if $remaining == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $remaining == 0 0 0 0
463 } else {
464 0 croak 'write(): invalid streaming request framing mode';
465 }
466  
467 6 ▶ $self->_retire_if_done if $tx->{local_done};
Branch: 1 branch
BranchTrueFalseTotal
if $tx->{"local_done"} 2 4 6
468 6 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 0 6 6
469 6 my $ok = $self->_stream_ok;
470 6 ▶ $tx->{blocked} = 1 unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 5 6
471 6 return $ok;
472 }
473  
474 4 ▶sub _deliver_switch_notice {
Subroutine _deliver_switch_notice: called CC=2 SCAR=7.0
475 4 my ($self, $tx, $response) = @_;
476 4 my $result = $tx->_invoke('on_switch', $response);
477 4 $tx->_notify_finish;
478 4 ▶ $self->_connection_error($result) unless $result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 0 4 4
479 4 return;
480 }
481  
482 0 ▶sub _transaction_respond { croak 'respond(): client Transactions cannot send responses' }
Subroutine _transaction_respond: not called CC=1 SCAR=6.9
483 0 ▶sub _transaction_informational { croak 'send_informational(): client Transactions cannot send responses' }
Subroutine _transaction_informational: not called CC=1 SCAR=6.9
484  
485 5 ▶sub _transaction_cancel {
Subroutine _transaction_cancel: called CC=5 SCAR=16.3
486 5 my ($self, $tx) = @_;
487 5 ▶ return if $tx->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $tx->is_terminal 0 5 5
488 5 $tx->_mark_cancelled;
489 5 $self->{rx} = undef;
490 5 ▶ $self->{active} = undef if $self->{active} && $self->{active} == $tx;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"active"} and $self->{"active"} == $tx 4 1 5
Condition66%2/3
$self->{"active"} and $self->{"active"} == $tx
!ll&&!rl&&r
014
MC/DC50%1/2
$self->{"active"} and $self->{"active"} == $tx
$self->{"active"} $self->{"active"} == $tx
Truth table66%2/3
A and B
A= $self->{"active"}B= $self->{"active"} == $tx
ABresult
0X0
100
111
491 5 $self->{closed} = 1;
492 5 $self->_fail_all('HTTP/1 connection closed after cancellation');
493 $self->_transport_abort('HTTP/1 transaction cancelled')
494 5 ▶ if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 0 5 5
495 5 $tx->_notify_finish;
496 5 return;
497 }
498  
499 66 ▶sub _maybe_drain {
Subroutine _maybe_drain: called CC=4 SCAR=14.0
500 66 my ($self) = @_;
501 66 ▶ my $tx = $self->{active} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $tx = $self->{"active"} or return 66 0 66
502 66 ▶ return unless $tx->{blocked};
Branch: 1 branch
BranchTrueFalseTotal
unless $tx->{"blocked"} 65 1 66
503 1 $tx->{blocked} = 0;
504 1 my $cb = $tx->_invoke('on_drain');
505 1 ▶ $self->_connection_error($cb) unless $cb eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $cb eq 1 0 1 1
506 1 return;
507 }
508  
509 5 ▶sub _on_eof {
Subroutine _on_eof: called CC=7 SCAR=21.6
510 5 my ($self) = @_;
511 5 ▶ return if $self->{switched};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"switched"} 0 5 5
512 5 my $tx = $self->{active};
513 5 ▶ if (!$tx) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tx) 0 5 5
514 0 $self->{closed} = 1;
515 0 return;
516 }
517 5 my $rx = $self->{rx};
518 5 ▶ if ($rx && $rx->{mode} eq 'close') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rx and $rx->{"mode"} eq "close") 2 3 5
Condition100%3/3
$rx and $rx->{"mode"} eq "close"
!ll&&!rl&&r
122
MC/DC100%2/2
$rx and $rx->{"mode"} eq "close"
$rx $rx->{"mode"} eq "close"
Truth table100%3/3
A and B
A= $rxB= $rx->{"mode"} eq "close"
ABresult
0X0
100
111
519 2 ▶ if (length $self->{input}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"input"}) 0 2 2
520 0 my $bytes = substr($self->{input}, 0, length($self->{input}), '');
521 0 my $cb = $tx->_receive_data($rx->{response}, $bytes);
522 0 ▶ return $self->_connection_error($cb) unless $cb eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $cb eq 1 0 0 0
523 }
524 2 $rx->{keep_alive} = 0;
525 2 $self->_finish_response;
526 2 $self->{closed} = 1;
527 2 return;
528 }
529 3 $self->_connection_error('unexpected EOF in HTTP/1 response');
530 3 return;
531 }
532  
533 19 ▶sub _connection_error {
Subroutine _connection_error: called CC=6 SCAR=18.2
534 19 my ($self, $error) = @_;
535 19 ▶ $error = 'HTTP/1 client protocol error' unless defined($error) && length($error);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $error and length $error 0 19 19
Condition33%1/3
defined $error and length $error
!ll&&!rl&&r
0019
MC/DC0%0/2
defined $error and length $error
defined $error length $error
Truth table33%1/3
A and B
A= defined $errorB= length $error
ABresult
0X0
100
111
536 19 my $tx = delete $self->{active};
537 19 $self->{rx} = undef;
538 19 $self->{closed} = 1;
539 19 $self->_input_clear;
540 19 ▶ if ($tx && !$tx->is_terminal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx and not $tx->is_terminal) 17 2 19
Condition100%3/3
$tx and not $tx->is_terminal
!ll&&!rl&&r
1117
MC/DC100%2/2
$tx and not $tx->is_terminal
$tx not $tx->is_terminal
Truth table100%3/3
A and not(B)
A= $txB= not $tx->is_terminal
ABresult
0X0
100
111
541 17 $tx->_fail($error);
542 17 $tx->_invoke('on_error', $error);
543 17 $tx->_notify_finish;
544 }
545 19 $self->_fail_queued($error);
546 19 ▶ $self->_transport_abort($error) if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 0 19 19
547 19 return;
548 }
549  
550 34 ▶sub _fail_queued {
Subroutine _fail_queued: called CC=4 SCAR=13.9
551 34 my ($self, $error) = @_;
552 34 ▶ for my $tx (@{ delete($self->{queue}) || [] }) {
Condition50%1/2
delete $self->{'queue'} || []
l!l
340
MC/DC0%0/1
delete $self->{'queue'} || []
delete $self->{'queue'}
Truth table50%1/2
A
A= delete $self->{'queue'}
Aresult
11
00
553 3 ▶ next if $tx->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $tx->is_terminal 1 2 3
554 2 $tx->_fail($error);
555 2 eval { $tx->_invoke('on_error', $error) };
556 2 $tx->_notify_finish;
557 }
558 34 $self->{queue} = [];
559 34 return;
560 }
561  
562 5 ▶sub _fail_all {
Subroutine _fail_all: called CC=3 SCAR=11.0
563 5 my ($self, $error) = @_;
564 5 ▶ if (my $tx = delete $self->{active}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tx = delete $self->{"active"}) 1 4 5
565 1 ▶ if (!$tx->is_terminal) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tx->is_terminal) 1 0 1
566 1 $tx->_fail($error);
567 1 eval { $tx->_invoke('on_error', $error) };
568 1 $tx->_notify_finish;
569 }
570 }
571 5 $self->{rx} = undef;
572 5 $self->_fail_queued($error);
573 5 return;
574 }
575  
576 29 1;
577  
578 __END__
« blib/lib/Unblock/HTTP1/_Wire.pm ↑ Summary blib/lib/Unblock/HTTP1/Server.pm »