blib/lib/Unblock/HTTP2/Server.pm

filter: Statementstmt 88.7% 277 / 312 Branchbran 69.3% 158 / 228 Conditioncond 50.4% 63 / 125 MC/DCmcdc 16.6% 11 / 66 Subroutinesub 97.0% 33 / 34 Podpod 0.0% 0 / 5 totaltotal 70.3% 542 / 770 CC 162 SCAR 32.0
CC
162
Cov
75%
_respond_stream
48.4
new
42.4
_on_frame_recv
36.6
CRAP 24.5
« blib/lib/Unblock/HTTP2/_Headers.pm ↑ Summary blib/lib/Unblock/HTTP2/_nghttp2.pm »
1 package Unblock::HTTP2::Server;
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 Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 29 ▶use parent 'Unblock::HTTP2::_Connection';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 29 ▶use Unblock::HTTP2::_Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 29 ▶use Unblock::HTTP2::Transaction;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 29 our $VERSION = '0.12';
13  
14 29 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
15 29 H2_DATA => 0,
16 H2_HEADERS => 1,
17 H2_GOAWAY => 7,
18 H2_END_STREAM => 0x1,
19 H2_INTERNAL_ERROR => 2,
20 H2_CANCEL => 8,
21 H2_ENHANCE_YOUR_CALM => 11,
22 29 };
23  
24 29 my $BODY_HIGH_WATER = 65_536;
25 29 my $BODY_LOW_WATER = 32_768;
26  
27 42 ▶sub new {
Subroutine new: called CC=26 SCAR=37.5
Pod undocumented
28 42 my ($class, %option) = @_;
29 42 my $transport = delete $option{transport};
30 42 my %receive = $class->_receive_options(\%option);
31  
32 42 my %callbacks;
33 42 for my $name (qw(
34 on_request on_body on_request_end on_error
35 on_settings on_settings_ack on_ping on_ping_ack on_priority
36 on_invalid_frame
37 )) {
38 420 ▶ next unless exists $option{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $option{$name} 340 80 420
39 80 my $callback = delete $option{$name};
40 80 ▶ croak "new(): $name must be a coderef"
Branch: 1 branch
BranchTrueFalseTotal
if defined $callback and ref $callback ne "CODE" 0 80 80
Condition33%1/3
defined $callback and ref $callback ne "CODE"
!ll&&!rl&&r
0800
MC/DC0%0/2
defined $callback and ref $callback ne "CODE"
defined $callback ref $callback ne "CODE"
Truth table33%1/3
A and B
A= defined $callbackB= ref $callback ne "CODE"
ABresult
0X0
100
111
41 if defined($callback) && ref($callback) ne 'CODE';
42 80 ▶ $callbacks{$name} = $callback if $callback;
Branch: 1 branch
BranchTrueFalseTotal
if $callback 80 0 80
43 }
44  
45 my $settings = exists($option{settings})
46 ? delete($option{settings})
47 42 ▶ : {};
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'settings'} ? : 2 40 42
48 42 ▶ croak 'new(): settings must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $settings eq "HASH" 0 42 42
49 unless ref($settings) eq 'HASH';
50  
51 my $max_concurrent_streams = exists($option{max_concurrent_streams})
52 ? delete($option{max_concurrent_streams})
53 42 ▶ : 100;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'max_concurrent_streams'} ? : 1 41 42
54 my $max_header_list_size = exists($option{max_header_list_size})
55 ? delete($option{max_header_list_size})
56 42 ▶ : 65_536;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'max_header_list_size'} ? : 1 41 42
57 my $enable_connect_protocol = exists($option{enable_connect_protocol})
58 ? delete($option{enable_connect_protocol})
59 42 ▶ : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'enable_connect_protocol'} ? : 1 41 42
60  
61 42 ▶ croak 'new(): max_concurrent_streams must be a positive integer'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $max_concurrent_streams and not ref $max_concurrent_streams and $max_concurrent_streams =~ /\A[0-9]+\z/ and $max_concurrent_streams > 0 0 42 42
Condition33%3/9
defined $max_concurrent_streams and not ref $max_concurrent_streams and $max_concurrent_streams =~ /\A[0-9]+\z/ and $max_concurrent_streams > 0
!ll&&!rl&&r
0042
defined $max_concurrent_streams and not ref $max_concurrent_streams and $max_concurrent_streams =~ /\A[0-9]+\z/
!ll&&!rl&&r
0042
defined $max_concurrent_streams and not ref $max_concurrent_streams
!ll&&!rl&&r
0042
MC/DC0%0/4
defined $max_concurrent_streams and not ref $max_concurrent_streams and $max_concurrent_streams =~ /\A[0-9]+\z/ and $max_concurrent_streams > 0
defined $max_concurrent_streams not ref $max_concurrent_streams $max_concurrent_streams =~ /\A[0-9]+\z/ $max_concurrent_streams > 0
Truth table20%1/5
A and not(B) and C and D
A= defined $max_concurrent_streamsB= not ref $max_concurrent_streamsC= $max_concurrent_streams =~ /\A[0-9]+\z/D= $max_concurrent_streams > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
62 unless defined($max_concurrent_streams)
63 && !ref($max_concurrent_streams)
64 && $max_concurrent_streams =~ /\A[0-9]+\z/
65 && $max_concurrent_streams > 0;
66 42 ▶ croak 'new(): max_header_list_size must be a positive integer'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $max_header_list_size and not ref $max_header_list_size and $max_header_list_size =~ /\A[0-9]+\z/ and $max_header_list_size > 0 0 42 42
Condition33%3/9
defined $max_header_list_size and not ref $max_header_list_size and $max_header_list_size =~ /\A[0-9]+\z/ and $max_header_list_size > 0
!ll&&!rl&&r
0042
defined $max_header_list_size and not ref $max_header_list_size and $max_header_list_size =~ /\A[0-9]+\z/
!ll&&!rl&&r
0042
defined $max_header_list_size and not ref $max_header_list_size
!ll&&!rl&&r
0042
MC/DC0%0/4
defined $max_header_list_size and not ref $max_header_list_size and $max_header_list_size =~ /\A[0-9]+\z/ and $max_header_list_size > 0
defined $max_header_list_size not ref $max_header_list_size $max_header_list_size =~ /\A[0-9]+\z/ $max_header_list_size > 0
Truth table20%1/5
A and not(B) and C and D
A= defined $max_header_list_sizeB= not ref $max_header_list_sizeC= $max_header_list_size =~ /\A[0-9]+\z/D= $max_header_list_size > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
67 unless defined($max_header_list_size)
68 && !ref($max_header_list_size)
69 && $max_header_list_size =~ /\A[0-9]+\z/
70 && $max_header_list_size > 0;
71 42 ▶ croak 'new(): enable_connect_protocol must be zero or one'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $enable_connect_protocol or ref $enable_connect_protocol or not "$enable_connect_protocol" =~ /\A[01]\z/ 0 42 42
Condition33%2/6
not defined $enable_connect_protocol or ref $enable_connect_protocol or not "$enable_connect_protocol" =~ /\A[01]\z/
l!l&&r!l&&!r
0042
not defined $enable_connect_protocol or ref $enable_connect_protocol
l!l&&r!l&&!r
0042
MC/DC0%0/3
not defined $enable_connect_protocol or ref $enable_connect_protocol or not "$enable_connect_protocol" =~ /\A[01]\z/
not defined $enable_connect_protocol ref $enable_connect_protocol not "$enable_connect_protocol" =~ /\A[01]\z/
Truth table25%1/4
not(A) or B or not(C)
A= not defined $enable_connect_protocolB= ref $enable_connect_protocolC= not "$enable_connect_protocol" =~ /\A[01]\z/
ABCresult
1XX1
01X1
0011
0000
72 if !defined($enable_connect_protocol)
73 || ref($enable_connect_protocol)
74 || "$enable_connect_protocol" !~ /\A[01]\z/;
75 42 ▶ $enable_connect_protocol = $enable_connect_protocol ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$enable_connect_protocol ? : 41 1 42
76  
77 42 ▶ croak 'new(): unknown options: ' . join(', ', sort keys %option)
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 42 42
78 if %option;
79  
80 42 require Unblock::HTTP2::_nghttp2;
81 42 ▶ croak 'new(): nghttp2 library is unavailable'
Branch: 1 branch
BranchTrueFalseTotal
unless "Unblock::HTTP2::_nghttp2"->available 0 42 42
82 unless Unblock::HTTP2::_nghttp2->available;
83  
84 42 my $self = bless {
85 callbacks => \%callbacks,
86 draining => 0,
87 max_concurrent_streams => 0 + $max_concurrent_streams,
88 max_header_list_size => 0 + $max_header_list_size,
89 enable_connect_protocol => $enable_connect_protocol,
90 last_peer_stream_id => 0,
91 receive => {},
92 providers => {},
93 peer_goaway => undef,
94 }, $class;
95  
96 42 my $weak = $self;
97 42 weaken($weak);
98  
99 my $session = Unblock::HTTP2::_nghttp2::Session->new_server(
100 max_header_list_size => $self->{max_header_list_size},
101 callbacks => {
102 48 ▶ on_begin_headers => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
103 48 ▶ my $self = $weak or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $self = $weak or return 0 48 0 48
104 48 return $self->_on_begin_headers(@_);
105 },
106 170 ▶ on_frame_recv => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
107 170 ▶ my $self = $weak or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $self = $weak or return 0 170 0 170
108 170 return $self->_on_frame_recv(@_);
109 },
110 29 ▶ on_data_chunk_recv => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
111 29 ▶ my $self = $weak or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $self = $weak or return 0 29 0 29
112 29 return $self->_on_data_chunk_recv(@_);
113 },
114 42 ▶ on_stream_close => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
115 42 ▶ my $self = $weak or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $self = $weak or return 0 42 0 42
116 42 return $self->_on_stream_close(@_);
117 },
118 2 ▶ on_invalid_frame => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
119 2 ▶ my $self = $weak or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $self = $weak or return 0 2 0 2
120 2 return $self->_on_invalid_frame(@_);
121 },
122 },
123 42 );
124  
125 42 $self->_initialize_connection(
126 $session,
127 %receive,
128 role => 'server',
129 callbacks => \%callbacks,
130 transport => $transport,
131 );
132  
133 my %initial_settings = (
134 max_concurrent_streams => $self->{max_concurrent_streams},
135 max_header_list_size => $self->{max_header_list_size},
136 enable_connect_protocol => $self->{enable_connect_protocol},
137 42 no_rfc7540_priorities => 1,
138 %$settings,
139 );
140 42 $self->_submit_settings('new()', \%initial_settings);
141 42 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 2 40 42
142  
143 42 return $self;
144 }
145 3 ▶sub draining {
Subroutine draining: called CC=2 SCAR=7.6
Pod undocumented
146 3 ▶ return $_[0]{draining} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'draining'} ? : 3 0 3
147 }
148  
149 2 ▶sub peer_goaway {
Subroutine peer_goaway: called CC=2 SCAR=7.0
Pod undocumented
150 2 my ($self) = @_;
151 2 ▶ return unless $self->{peer_goaway};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"peer_goaway"} 0 2 2
152 2 return { %{ $self->{peer_goaway} } };
153 }
154  
155 1 ▶sub drain {
Subroutine drain: called CC=3 SCAR=12.5
Pod undocumented
156 1 my ($self) = @_;
157 1 ▶ return $self if $self->is_closed || $self->{draining};
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_closed or $self->{"draining"} 0 1 1
Condition33%1/3
$self->is_closed or $self->{"draining"}
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->is_closed or $self->{"draining"}
$self->is_closed $self->{"draining"}
Truth table33%1/3
A or B
A= $self->is_closedB= $self->{"draining"}
ABresult
1X1
011
000
158 1 return $self->goaway(error_code => 0);
159 }
160  
161 48 ▶sub _on_begin_headers {
Subroutine _on_begin_headers: called CC=3 SCAR=11.0
162 48 my ($self, $stream_id) = @_;
163  
164 $self->{last_peer_stream_id} = $stream_id
165 48 ▶ if $stream_id > $self->{last_peer_stream_id};
Branch: 1 branch
BranchTrueFalseTotal
if $stream_id > $self->{"last_peer_stream_id"} 45 3 48
166  
167 48 ▶ $self->{receive}{$stream_id} ||= {
Condition100%2/2
$self->{"receive"}{$stream_id} ||= {"request_end_called", 0}
l!l
345
MC/DC100%1/1
$self->{"receive"}{$stream_id} ||= {"request_end_called", 0}
$self->{"receive"}{$stream_id}
Truth table100%2/2
A
A= $self->{"receive"}{$stream_id}
Aresult
11
00
168 request_end_called => 0,
169 };
170  
171 48 return 0;
172 }
173  
174 170 ▶sub _on_frame_recv {
Subroutine _on_frame_recv: called CC=28 SCAR=36.0
175 170 my ($self, $frame) = @_;
176  
177 170 ▶ return 0 if $self->_handle_settings_frame($frame);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_handle_settings_frame($frame) 76 94 170
178 94 ▶ return 0 if $self->_handle_ping_frame($frame);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_handle_ping_frame($frame) 3 91 94
179 91 ▶ return 0 if $self->_handle_priority_update_frame($frame);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_handle_priority_update_frame($frame) 1 90 91
180  
181 90 ▶ if (($frame->{type} // -1) == H2_GOAWAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (($frame->{"type"} // -1) == 7) 2 88 90
Condition50%1/2
$frame->{"type"} // -1
l!l
900
MC/DC0%0/1
$frame->{"type"} // -1
$frame->{"type"}
Truth table50%1/2
A
A= $frame->{"type"}
Aresult
11
00
182 2 $self->{draining} = 1;
183 $self->{peer_goaway} = {
184 last_stream_id => 0 + ($frame->{last_stream_id} // 0),
185 error_code => 0 + ($frame->{error_code} // 0),
186 debug_data => defined($frame->{debug_data})
187 2 ▶ ? "$frame->{debug_data}"
Branch: 1 branch
BranchTrueFalseTotal
defined $frame->{'debug_data'} ? : 2 0 2
Condition50%2/4
$frame->{"last_stream_id"} // 0
l!l
20
$frame->{"error_code"} // 0
l!l
20
MC/DC0%0/1
$frame->{"last_stream_id"} // 0
$frame->{"last_stream_id"}
MC/DC0%0/1
$frame->{"error_code"} // 0
$frame->{"error_code"}
Truth table50%1/2
A
A= $frame->{"last_stream_id"}
Aresult
11
00
Truth table50%1/2
A
A= $frame->{"error_code"}
Aresult
11
00
188 : '',
189 };
190 2 return 0;
191 }
192  
193 88 ▶ my $stream_id = $frame->{stream_id} || 0;
Condition100%2/2
$frame->{'stream_id'} || 0
l!l
862
MC/DC100%1/1
$frame->{'stream_id'} || 0
$frame->{'stream_id'}
Truth table100%2/2
A
A= $frame->{'stream_id'}
Aresult
11
00
194 88 ▶ return 0 unless $stream_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $stream_id 2 86 88
195  
196 86 ▶ my $state = $self->{receive}{$stream_id} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $state = $self->{"receive"}{$stream_id} or return 0 86 0 86
197  
198 86 ▶ if (($frame->{type} // -1) == H2_HEADERS) {
Branch: 1 branch
BranchTrueFalseTotal
if (($frame->{"type"} // -1) == 1) 48 38 86
Condition50%1/2
$frame->{"type"} // -1
l!l
860
MC/DC0%0/1
$frame->{"type"} // -1
$frame->{"type"}
Truth table50%1/2
A
A= $frame->{"type"}
Aresult
11
00
199 48 ▶ if (defined $frame->{header_error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $frame->{"header_error"}) 1 47 48
200 $self->_stream_failure(
201 $stream_id,
202 "$frame->{header_error}",
203 $frame->{header_error_code},
204 1 );
205 1 return 0;
206 }
207  
208 47 my $transaction = $self->transaction_for_stream_id($stream_id);
209  
210 47 ▶ if (!$transaction) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($transaction) 44 3 47
211 44 my $request = $frame->{uniform_message};
212 44 ▶ if (!$request) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($request) 0 44 44
213 0 $self->_stream_failure(
214 $stream_id,
215 'HTTP/2 request header block did not produce a Uniform request',
216 );
217 0 return 0;
218 }
219  
220 44 $transaction = Unblock::HTTP2::Transaction->_new(
221 connection => $self,
222 stream_id => $stream_id,
223 request => $request,
224 callbacks => {},
225 );
226 44 $self->_register_transaction($transaction);
227  
228 44 my $result = $self->_invoke_callback(
229 'on_request', $transaction, $request,
230 );
231 44 ▶ if ($result ne '1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($result ne 1) 0 44 44
232 0 $self->_stream_failure($stream_id, "$result");
233 0 return 0;
234 }
235  
236 44 ▶ if (($frame->{flags} || 0) & H2_END_STREAM) {
Branch: 1 branch
BranchTrueFalseTotal
if (($frame->{"flags"} || 0) & 1) 24 20 44
Condition50%1/2
$frame->{'flags'} || 0
l!l
440
MC/DC0%0/1
$frame->{'flags'} || 0
$frame->{'flags'}
Truth table50%1/2
A
A= $frame->{'flags'}
Aresult
11
00
237 24 $self->_request_end($stream_id);
238 }
239  
240 44 return 0;
241 }
242  
243 3 ▶ if (!(($frame->{flags} || 0) & H2_END_STREAM)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (($frame->{"flags"} || 0) & 1) 0 3 3
Condition50%1/2
$frame->{'flags'} || 0
l!l
30
MC/DC0%0/1
$frame->{'flags'} || 0
$frame->{'flags'}
Truth table50%1/2
A
A= $frame->{'flags'}
Aresult
11
00
244 0 $self->_stream_failure(
245 $stream_id,
246 'HTTP/2 trailing HEADERS must end the stream',
247 );
248 0 return 0;
249 }
250  
251 3 my $ok = eval {
252 Unblock::HTTP2::_Headers->apply_trailers(
253 $transaction->request,
254 3 ▶ $frame->{native_headers} || [],
Condition50%1/2
$frame->{'native_headers'} || []
l!l
30
MC/DC0%0/1
$frame->{'native_headers'} || []
$frame->{'native_headers'}
Truth table50%1/2
A
A= $frame->{'native_headers'}
Aresult
11
00
255 );
256 3 1;
257 };
258 3 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 3 3
259 0 $self->_stream_failure($stream_id, "$@");
260 0 return 0;
261 }
262  
263 3 $self->_request_end($stream_id);
264 3 return 0;
265 }
266  
267 38 ▶ if (($frame->{type} // -1) == H2_DATA
Branch: 1 branch
BranchTrueFalseTotal
if (($frame->{"type"} // -1) == 0 and ($frame->{"flags"} || 0) & 1) 11 27 38
Condition85%6/7
($frame->{"type"} // -1) == 0 and ($frame->{"flags"} || 0) & 1
!ll&&!rl&&r
111611
$frame->{"type"} // -1
l!l
380
$frame->{'flags'} || 0
l!l
1116
MC/DC50%1/2
($frame->{"type"} // -1) == 0 and ($frame->{"flags"} || 0) & 1
$frame->{"type"} $frame->{'flags'}
Truth table66%2/3
A and B
A= $frame->{"type"}B= $frame->{'flags'}
ABresult
0X0
100
111
268 && (($frame->{flags} || 0) & H2_END_STREAM)) {
269 11 $self->_request_end($stream_id);
270 }
271  
272 38 return 0;
273 }
274  
275 29 ▶sub _on_data_chunk_recv {
Subroutine _on_data_chunk_recv: called CC=3 SCAR=11.0
276 29 my ($self, $stream_id, $data, $flags) = @_;
277 29 ▶ my $transaction = $self->transaction_for_stream_id($stream_id) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $transaction = $self->transaction_for_stream_id($stream_id) or return 0 29 0 29
278  
279 29 $transaction->_receive_body_bytes(length $data);
280  
281 29 my $result = $transaction->_receive_data($transaction->request, $data);
282  
283 29 ▶ if ($result ne '1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($result ne 1) 2 27 29
284 2 $self->_stream_failure($stream_id, "$result");
285 2 return 0;
286 }
287  
288 27 $transaction->_auto_consume_body;
289 27 return 0;
290 }
291  
292 38 ▶sub _request_end {
Subroutine _request_end: called CC=6 SCAR=18.1
293 38 my ($self, $stream_id) = @_;
294 38 ▶ my $state = $self->{receive}{$stream_id} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $state = $self->{"receive"}{$stream_id} or return 37 1 38
295 37 ▶ return if $state->{request_end_called}++;
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"request_end_called"}++ 0 37 37
296  
297 37 ▶ my $transaction = $self->transaction_for_stream_id($stream_id) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $transaction = $self->transaction_for_stream_id($stream_id) or return 37 0 37
298 37 ▶ return if $transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal 1 36 37
299 36 $transaction->_finish_receive($transaction->request);
300 36 $transaction->request->mark_complete->freeze;
301  
302 36 my $result = $self->_invoke_callback(
303 'on_request_end', $transaction, $transaction->request,
304 );
305 36 ▶ $self->_stream_failure($stream_id, "$result")
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 0 36 36
306 unless $result eq '1';
307 36 return;
308 }
309 99 ▶sub _invoke_callback {
Subroutine _invoke_callback: called CC=6 SCAR=18.1
310 99 my ($self, $name, @args) = @_;
311 99 ▶ my $callback = $self->{callbacks}{$name} or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $callback = $self->{"callbacks"}{$name} or return 1 78 21 99
312  
313 78 my $tx = $args[0];
314 78 ▶ $tx->{callback_depth}++ if $tx;
Branch: 1 branch
BranchTrueFalseTotal
if $tx 78 0 78
315 78 my $ok = eval {
316 78 $callback->(@args);
317 78 1;
318 };
319  
320 78 my $error = "$@";
321 78 ▶ if ($tx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx) 78 0 78
322 78 $tx->{callback_depth}--;
323 78 ▶ $tx->_notify_finish if $tx->{finish_pending};
Branch: 1 branch
BranchTrueFalseTotal
if $tx->{"finish_pending"} 3 75 78
324 }
325 78 ▶ return $ok ? 1 : $error;
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 78 0 78
326 }
327  
328 2 ▶sub _on_invalid_frame {
Subroutine _on_invalid_frame: called CC=3 SCAR=11.4
329 2 my ($self, $frame, $lib_error_code) = @_;
330  
331 2 ▶ my $copy = ref($frame) eq 'HASH' ? { %$frame } : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $frame eq 'HASH' ? : 2 0 2
332 2 ▶ $self->_invoke_control_callback(
Condition50%1/2
$lib_error_code || 0
l!l
20
MC/DC0%0/1
$lib_error_code || 0
$lib_error_code
Truth table50%1/2
A
A= $lib_error_code
Aresult
11
00
333 'on_invalid_frame',
334 $copy,
335 0 + ($lib_error_code || 0),
336 );
337 2 return 0;
338 }
339  
340 3 ▶sub _send_informational_stream {
Subroutine _send_informational_stream: called CC=14 SCAR=33.7
341 3 my ($self, $transaction, $response) = @_;
342  
343 3 my $native_message = Unblock::HTTP2::_Headers->native_message($response);
344 3 ▶ croak 'send_informational(): requires the Uniform HTTP response contract'
Branch: 1 branch
BranchTrueFalseTotal
unless $native_message or Unblock::HTTP2::_Headers::_response_contract($response) 0 3 3
Condition33%1/3
$native_message or Unblock::HTTP2::_Headers::_response_contract($response)
l!l&&r!l&&!r
300
MC/DC0%0/2
$native_message or Unblock::HTTP2::_Headers::_response_contract($response)
$native_message Unblock::HTTP2::_Headers::_response_contract($response)
Truth table33%1/3
A or B
A= $native_messageB= Unblock::HTTP2::_Headers::_response_contract($response)
ABresult
1X1
011
000
345 unless $native_message
346 || Unblock::HTTP2::_Headers::_response_contract($response);
347 3 ▶ croak 'send_informational(): final Response already submitted'
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->response 0 3 3
348 if $transaction->response;
349  
350 3 my $status = $response->status;
351 3 ▶ croak 'send_informational(): status must be informational (100-199, excluding 101)'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status and not ref $status and $status =~ /\A[0-9]+\z/ and $status >= 100 and $status < 200 and $status != 101 0 3 3
Condition33%5/15
defined $status and not ref $status and $status =~ /\A[0-9]+\z/ and $status >= 100 and $status < 200 and $status != 101
!ll&&!rl&&r
003
defined $status and not ref $status and $status =~ /\A[0-9]+\z/ and $status >= 100 and $status < 200
!ll&&!rl&&r
003
defined $status and not ref $status and $status =~ /\A[0-9]+\z/ and $status >= 100
!ll&&!rl&&r
003
defined $status and not ref $status and $status =~ /\A[0-9]+\z/
!ll&&!rl&&r
003
defined $status and not ref $status
!ll&&!rl&&r
003
MC/DC0%0/6
defined $status and not ref $status and $status =~ /\A[0-9]+\z/ and $status >= 100 and $status < 200 and $status != 101
defined $status not ref $status $status =~ /\A[0-9]+\z/ $status >= 100 $status < 200 $status != 101
Truth table14%1/7
A and not(B) and C and D and E and F
A= defined $statusB= not ref $statusC= $status =~ /\A[0-9]+\z/D= $status >= 100E= $status < 200F= $status != 101
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
352 unless defined($status) && !ref($status)
353 && $status =~ /\A[0-9]+\z/
354 && $status >= 100 && $status < 200 && $status != 101;
355 3 ▶ croak 'send_informational(): informational Response must not have a buffered body'
Branch: 1 branch
BranchTrueFalseTotal
if $response->has_buffered_body 0 3 3
356 if $response->has_buffered_body;
357  
358 3 my $trailers = Unblock::HTTP2::_Headers->trailer_fields(
359 'send_informational()', $response,
360 );
361 3 ▶ croak 'send_informational(): informational Response must not have trailers'
Branch: 1 branch
BranchTrueFalseTotal
if @$trailers 0 3 3
362 if @$trailers;
363  
364 3 ▶ if ($native_message) {
Branch: 1 branch
BranchTrueFalseTotal
if ($native_message) { } 3 0 3
365 $self->{session}->submit_response_headers_uniform(
366 3 $transaction->stream_id,
367 $native_message,
368 );
369 }
370 else {
371 0 my $block = Unblock::HTTP2::_Headers->response_headers($response);
372 $self->{session}->submit_headers(
373 0 $transaction->stream_id,
374 headers => $block,
375 );
376 }
377  
378 3 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 1 2 3
379 3 return $transaction;
380 }
381  
382 32 ▶sub _respond_stream {
Subroutine _respond_stream: called CC=32 SCAR=38.8
383 32 my ($self, $transaction, $response, %option) = @_;
384  
385 32 my $native_message = Unblock::HTTP2::_Headers->native_message($response);
386 32 ▶ croak 'respond(): requires the Uniform HTTP response contract'
Branch: 1 branch
BranchTrueFalseTotal
unless $native_message or Unblock::HTTP2::_Headers::_response_contract($response) 0 32 32
Condition33%1/3
$native_message or Unblock::HTTP2::_Headers::_response_contract($response)
l!l&&r!l&&!r
3200
MC/DC0%0/2
$native_message or Unblock::HTTP2::_Headers::_response_contract($response)
$native_message Unblock::HTTP2::_Headers::_response_contract($response)
Truth table33%1/3
A or B
A= $native_messageB= Unblock::HTTP2::_Headers::_response_contract($response)
ABresult
1X1
011
000
387 unless $native_message
388 || Unblock::HTTP2::_Headers::_response_contract($response);
389 32 ▶ croak 'respond(): Transaction already has a Response'
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->response 0 32 32
390 if $transaction->response;
391  
392 my $stream_body = exists($option{stream_body})
393 ? delete($option{stream_body})
394 32 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'stream_body'} ? : 2 30 32
395 32 ▶ croak 'respond(): stream_body must be zero or one'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $stream_body or ref $stream_body or not "$stream_body" =~ /\A[01]\z/ 0 32 32
Condition33%2/6
not defined $stream_body or ref $stream_body or not "$stream_body" =~ /\A[01]\z/
l!l&&r!l&&!r
0032
not defined $stream_body or ref $stream_body
l!l&&r!l&&!r
0032
MC/DC0%0/3
not defined $stream_body or ref $stream_body or not "$stream_body" =~ /\A[01]\z/
not defined $stream_body ref $stream_body not "$stream_body" =~ /\A[01]\z/
Truth table25%1/4
not(A) or B or not(C)
A= not defined $stream_bodyB= ref $stream_bodyC= not "$stream_body" =~ /\A[01]\z/
ABCresult
1XX1
01X1
0011
0000
396 if !defined($stream_body) || ref($stream_body)
397 || "$stream_body" !~ /\A[01]\z/;
398 32 ▶ $stream_body = $stream_body ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$stream_body ? : 2 30 32
399  
400 32 my $on_drain = delete $option{on_drain};
401 32 my $on_error = delete $option{on_error};
402  
403 32 ▶ croak 'respond(): on_drain must be a coderef'
Branch: 1 branch
BranchTrueFalseTotal
if defined $on_drain and ref $on_drain ne "CODE" 0 32 32
Condition66%2/3
defined $on_drain and ref $on_drain ne "CODE"
!ll&&!rl&&r
3110
MC/DC0%0/2
defined $on_drain and ref $on_drain ne "CODE"
defined $on_drain ref $on_drain ne "CODE"
Truth table66%2/3
A and B
A= defined $on_drainB= ref $on_drain ne "CODE"
ABresult
0X0
100
111
404 if defined($on_drain) && ref($on_drain) ne 'CODE';
405 32 ▶ croak 'respond(): on_error must be a coderef'
Branch: 1 branch
BranchTrueFalseTotal
if defined $on_error and ref $on_error ne "CODE" 0 32 32
Condition66%2/3
defined $on_error and ref $on_error ne "CODE"
!ll&&!rl&&r
3110
MC/DC0%0/2
defined $on_error and ref $on_error ne "CODE"
defined $on_error ref $on_error ne "CODE"
Truth table66%2/3
A and B
A= defined $on_errorB= ref $on_error ne "CODE"
ABresult
0X0
100
111
406 if defined($on_error) && ref($on_error) ne 'CODE';
407 32 ▶ croak 'respond(): unknown options: ' . join(', ', sort keys %option)
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 32 32
408 if %option;
409 32 ▶ croak 'respond(): on_drain requires stream_body'
Branch: 1 branch
BranchTrueFalseTotal
if $on_drain and not $stream_body 0 32 32
Condition66%2/3
$on_drain and not $stream_body
!ll&&!rl&&r
3110
MC/DC0%0/2
$on_drain and not $stream_body
$on_drain not $stream_body
Truth table66%2/3
A and not(B)
A= $on_drainB= not $stream_body
ABresult
0X0
100
111
410 if $on_drain && !$stream_body;
411 32 ▶ croak 'respond(): stream_body cannot be combined with a buffered body'
Branch: 1 branch
BranchTrueFalseTotal
if $stream_body and $response->has_buffered_body 0 32 32
Condition66%2/3
$stream_body and $response->has_buffered_body
!ll&&!rl&&r
3020
MC/DC0%0/2
$stream_body and $response->has_buffered_body
$stream_body $response->has_buffered_body
Truth table66%2/3
A and B
A= $stream_bodyB= $response->has_buffered_body
ABresult
0X0
100
111
412 if $stream_body && $response->has_buffered_body;
413  
414 32 my ($block, @headers);
415 32 ▶ if (!$native_message) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($native_message) 0 32 32
416 0 $block = Unblock::HTTP2::_Headers->response_headers($response);
417 0 @headers = @$block[1 .. $#$block];
418 }
419 32 my $trailers = Unblock::HTTP2::_Headers->trailer_fields(
420 'respond()', $response,
421 );
422  
423 32 my $provider;
424 32 ▶ if ($stream_body || @$trailers) {
Branch: 2 branches
BranchTrueFalseTotal
if ($stream_body or @$trailers) { } 3 29 32
elsif ($response->has_buffered_body) { } 27 2 29
Condition100%3/3
$stream_body or @$trailers
l!l&&r!l&&!r
2129
MC/DC100%2/2
$stream_body or @$trailers
$stream_body @$trailers
Truth table100%3/3
A or B
A= $stream_bodyB= @$trailers
ABresult
1X1
011
000
425 3 $provider = {
426 queue => '',
427 eof => 0,
428 blocked => 0,
429 stream_id => $transaction->stream_id,
430 trailers => undef,
431 trailer_submitted => 0,
432 };
433  
434 3 ▶ if (!$stream_body) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stream_body) 1 2 3
435 1 ▶ $provider->{queue} = $response->has_buffered_body
Branch: 1 branch
BranchTrueFalseTotal
$response->has_buffered_body ? : 1 0 1
436 ? $response->body
437 : '';
438 1 $provider->{eof} = 1;
439 1 ▶ $provider->{trailers} = $trailers if @$trailers;
Branch: 1 branch
BranchTrueFalseTotal
if @$trailers 1 0 1
440 }
441  
442 3 my $weak_self = $self;
443 3 weaken($weak_self);
444  
445 7 ▶ my $data_callback = sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
446 7 ▶ my $self = $weak_self or return ('', 1);
Branch: 1 branch
BranchTrueFalseTotal
my $self = $weak_self or return "", 1 7 0 7
447 7 return $self->_provide_body($provider, @_);
448 3 };
449  
450 3 ▶ if ($native_message) {
Branch: 1 branch
BranchTrueFalseTotal
if ($native_message) { } 3 0 3
451 $self->{session}->submit_response_uniform(
452 3 $transaction->stream_id,
453 $native_message,
454 data_callback => $data_callback,
455 );
456 }
457 else {
458 $self->{session}->submit_response(
459 0 $transaction->stream_id,
460 status => $response->status,
461 headers => \@headers,
462 data_callback => $data_callback,
463 );
464 }
465 }
466 elsif ($response->has_buffered_body) {
467 27 ▶ if ($native_message) {
Branch: 1 branch
BranchTrueFalseTotal
if ($native_message) { } 27 0 27
468 $self->{session}->submit_response_uniform(
469 27 $transaction->stream_id,
470 $native_message,
471 body => $response->body,
472 );
473 }
474 else {
475 $self->{session}->submit_response(
476 0 $transaction->stream_id,
477 status => $response->status,
478 headers => \@headers,
479 body => $response->body,
480 );
481 }
482 }
483 else {
484 2 ▶ if ($native_message) {
Branch: 1 branch
BranchTrueFalseTotal
if ($native_message) { } 2 0 2
485 $self->{session}->submit_response_uniform(
486 2 $transaction->stream_id,
487 $native_message,
488 );
489 }
490 else {
491 $self->{session}->submit_response(
492 0 $transaction->stream_id,
493 status => $response->status,
494 headers => \@headers,
495 );
496 }
497 }
498  
499 32 $transaction->_set_response($response);
500 32 ▶ $transaction->_set_callback('on_drain', $on_drain) if $on_drain;
Branch: 1 branch
BranchTrueFalseTotal
if $on_drain 1 31 32
501 32 ▶ $transaction->_set_callback('on_error', $on_error) if $on_error;
Branch: 1 branch
BranchTrueFalseTotal
if $on_error 1 31 32
502  
503 32 ▶ if ($provider) {
Branch: 1 branch
BranchTrueFalseTotal
if ($provider) 3 29 32
504 3 $self->{providers}{ $transaction->stream_id } = $provider;
505 }
506  
507 32 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 2 30 32
508 32 return $transaction;
509 }
510 7 ▶sub _provide_body {
Subroutine _provide_body: called CC=14 SCAR=30.2
511 7 my ($self, $provider, $stream_id, $max_length) = @_;
512  
513 7 ▶ if (!length($provider->{queue})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $provider->{"queue"}) 0 7 7
514 0 ▶ if ($provider->{eof}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($provider->{"eof"}) 0 0 0
515 0 ▶ if ($provider->{trailers}
Branch: 1 branch
BranchTrueFalseTotal
if ($provider->{"trailers"} and not $provider->{"trailer_submitted"}) 0 0 0
Condition0%0/3
$provider->{"trailers"} and not $provider->{"trailer_submitted"}
!ll&&!rl&&r
000
MC/DC0%0/2
$provider->{"trailers"} and not $provider->{"trailer_submitted"}
$provider->{"trailers"} not $provider->{"trailer_submitted"}
Truth table0%0/3
A and not(B)
A= $provider->{"trailers"}B= not $provider->{"trailer_submitted"}
ABresult
0X0
100
111
516 && !$provider->{trailer_submitted}) {
517 0 $self->_submit_provider_trailers($provider);
518 0 return ('', 1, 1);
519 }
520 0 return ('', 1);
521 }
522 0 return;
523 }
524  
525 my $take = length($provider->{queue}) < $max_length
526 ? length($provider->{queue})
527 7 ▶ : $max_length;
Branch: 1 branch
BranchTrueFalseTotal
length $provider->{'queue'} < $max_length ? : 3 4 7
528 7 my $chunk = substr($provider->{queue}, 0, $take, '');
529 7 ▶ my $eof = $provider->{eof} && !length($provider->{queue}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$provider->{'eof'} && !length($provider->{'queue'}) ? : 3 4 7
Condition66%2/3
$provider->{"eof"} and not length $provider->{"queue"}
!ll&&!rl&&r
403
MC/DC50%1/2
$provider->{"eof"} and not length $provider->{"queue"}
$provider->{"eof"} not length $provider->{"queue"}
Truth table66%2/3
A and not(B)
A= $provider->{"eof"}B= not length $provider->{"queue"}
ABresult
0X0
100
111
530 7 my $no_end_stream = 0;
531  
532 7 ▶ if ($eof && $provider->{trailers}
Branch: 1 branch
BranchTrueFalseTotal
if ($eof and $provider->{"trailers"} and not $provider->{"trailer_submitted"}) 2 5 7
Condition83%5/6
$eof and $provider->{"trailers"} and not $provider->{"trailer_submitted"}
!ll&&!rl&&r
502
$eof and $provider->{"trailers"}
!ll&&!rl&&r
412
MC/DC66%2/3
$eof and $provider->{"trailers"} and not $provider->{"trailer_submitted"}
$eof $provider->{"trailers"} not $provider->{"trailer_submitted"}
Truth table75%3/4
A and B and not(C)
A= $eofB= $provider->{"trailers"}C= not $provider->{"trailer_submitted"}
ABCresult
0XX0
10X0
1100
1111
533 && !$provider->{trailer_submitted}) {
534 2 $self->_submit_provider_trailers($provider);
535 2 $no_end_stream = 1;
536 }
537  
538 7 ▶ if ($provider->{blocked}
Branch: 1 branch
BranchTrueFalseTotal
if ($provider->{"blocked"} and length $provider->{"queue"} < $BODY_LOW_WATER) 1 6 7
Condition100%3/3
$provider->{"blocked"} and length $provider->{"queue"} < $BODY_LOW_WATER
!ll&&!rl&&r
421
MC/DC100%2/2
$provider->{"blocked"} and length $provider->{"queue"} < $BODY_LOW_WATER
$provider->{"blocked"} length $provider->{"queue"} < $BODY_LOW_WATER
Truth table100%3/3
A and B
A= $provider->{"blocked"}B= length $provider->{"queue"} < $BODY_LOW_WATER
ABresult
0X0
100
111
539 && length($provider->{queue}) < $BODY_LOW_WATER) {
540 1 $provider->{blocked} = 0;
541 1 $self->_queue_drain($provider->{stream_id});
542 }
543  
544 7 ▶ return $no_end_stream
Branch: 1 branch
BranchTrueFalseTotal
$no_end_stream ? : 2 5 7
545 ? ($chunk, $eof, 1)
546 : ($chunk, $eof);
547 }
548  
549 2 ▶sub _submit_provider_trailers {
Subroutine _submit_provider_trailers: called CC=3 SCAR=11.3
550 2 my ($self, $provider) = @_;
551 2 ▶ return if $provider->{trailer_submitted};
Branch: 1 branch
BranchTrueFalseTotal
if $provider->{"trailer_submitted"} 0 2 2
552  
553 $self->{session}->submit_trailer(
554 $provider->{stream_id},
555 2 ▶ headers => $provider->{trailers} || [],
Condition50%1/2
$provider->{'trailers'} || []
l!l
20
MC/DC0%0/1
$provider->{'trailers'} || []
$provider->{'trailers'}
Truth table50%1/2
A
A= $provider->{'trailers'}
Aresult
11
00
556 );
557 2 $provider->{trailer_submitted} = 1;
558 2 return;
559 }
560 4 ▶sub _write_stream_body {
Subroutine _write_stream_body: called CC=10 SCAR=24.1
561 4 my ($self, $transaction, $bytes, $final, $operation) = @_;
562  
563 4 ▶ my $provider = $self->{providers}{ $transaction->stream_id }
Branch: 1 branch
BranchTrueFalseTotal
my $provider = $self->{"providers"}{$transaction->stream_id} or croak("$operation(): Transaction has no streaming Response body") 4 0 4
564 or croak "$operation(): Transaction has no streaming Response body";
565  
566 4 $bytes = $self->_body_bytes("$operation()", $bytes);
567 croak "$operation(): streaming Response body is already complete"
568 4 ▶ if $provider->{eof};
Branch: 1 branch
BranchTrueFalseTotal
if $provider->{"eof"} 0 4 4
569  
570 4 $provider->{queue} .= $bytes;
571  
572 4 ▶ if ($final) {
Branch: 1 branch
BranchTrueFalseTotal
if ($final) 2 2 4
573 2 my $trailers = Unblock::HTTP2::_Headers->trailer_fields(
574 "$operation()", $transaction->response,
575 );
576 2 ▶ $provider->{trailers} = $trailers if @$trailers;
Branch: 1 branch
BranchTrueFalseTotal
if @$trailers 1 1 2
577 2 $provider->{eof} = 1;
578 }
579  
580 4 ▶ if ($self->{session}->is_stream_deferred($transaction->stream_id)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"session"}->is_stream_deferred($transaction->stream_id)) 0 4 4
581 0 $self->{session}->resume_stream($transaction->stream_id);
582 }
583  
584 4 my $blocked = length($provider->{queue}) >= $BODY_HIGH_WATER;
585 4 ▶ $provider->{blocked} = 1 if $blocked;
Branch: 1 branch
BranchTrueFalseTotal
if $blocked 1 3 4
586 4 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 0 4 4
587 4 ▶ if ($self->{transport_blocked}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"transport_blocked"}) 0 4 4
588 0 $provider->{blocked} = 1;
589 0 return 0;
590 }
591 4 ▶ return $blocked ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$blocked ? : 1 3 4
592 }
593 0 ▶sub _cancel_stream {
Subroutine _cancel_stream: not called CC=2 SCAR=17.9
594 0 my ($self, $transaction) = @_;
595 0 ▶ return if $transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal 0 0 0
596 0 $self->_reset_stream($transaction, H2_CANCEL);
597 0 return;
598 }
599  
600 3 ▶sub _stream_failure {
Subroutine _stream_failure: called CC=8 SCAR=21.9
601 3 my ($self, $stream_id, $error, $code) = @_;
602 3 ▶ $code = H2_INTERNAL_ERROR unless defined $code;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code 2 1 3
603 3 ▶ $error = 'HTTP/2 stream failure'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $error and length $error 0 3 3
Condition33%1/3
defined $error and length $error
!ll&&!rl&&r
003
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
604 unless defined($error) && length($error);
605  
606 3 my $transaction = $self->transaction_for_stream_id($stream_id);
607  
608 3 ▶ if ($transaction && !$transaction->is_terminal) {
Branch: 2 branches
BranchTrueFalseTotal
if ($transaction and not $transaction->is_terminal) { } 2 1 3
elsif (not $transaction and my $callback = $self->{'callbacks'}{'on_error'}) { } 1 0 1
Condition66%2/3
$transaction and not $transaction->is_terminal
!ll&&!rl&&r
102
MC/DC50%1/2
$transaction and not $transaction->is_terminal
$transaction not $transaction->is_terminal
Truth table66%2/3
A and not(B)
A= $transactionB= not $transaction->is_terminal
ABresult
0X0
100
111
609 2 $transaction->_fail($error, $code, 0);
610 2 $self->_invoke_stream_error($transaction, $error, $code);
611 }
612 ▶ elsif (!$transaction && (my $callback = $self->{callbacks}{on_error})) {
Condition33%1/3
not $transaction and my $callback = $self->{"callbacks"}{"on_error"}
!ll&&!rl&&r
001
MC/DC0%0/2
not $transaction and my $callback = $self->{"callbacks"}{"on_error"}
not $transaction my $callback = $self->{"callbacks"}{"on_error"}
Truth table33%1/3
not(A) and B
A= not $transactionB= my $callback = $self->{"callbacks"}{"on_error"}
ABresult
0X0
100
111
613 1 eval { $callback->(undef, $error, $code) };
614 }
615  
616 3 eval { $self->{session}->submit_rst_stream($stream_id, $code) };
617 3 return;
618 }
619  
620 7 ▶sub _invoke_stream_error {
Subroutine _invoke_stream_error: called CC=4 SCAR=16.5
621 7 my ($self, $transaction, $error, $error_code) = @_;
622  
623 7 my $result = $transaction->_invoke('on_error', $error, $error_code);
624 7 ▶ if ($result ne '1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($result ne 1) 0 7 7
625 0 my $callback = $self->{callbacks}{on_error};
626 0 ▶ eval { $callback->($transaction, "$result", $error_code) } if $callback;
Branch: 1 branch
BranchTrueFalseTotal
if $callback 0 0 0
627 0 $transaction->_notify_finish;
628 0 return;
629 }
630  
631 7 my $callback = $self->{callbacks}{on_error};
632 7 ▶ eval { $callback->($transaction, $error, $error_code) } if $callback;
Branch: 1 branch
BranchTrueFalseTotal
if $callback 6 1 7
633 7 $transaction->_notify_finish;
634 7 return;
635 }
636  
637 42 ▶sub _on_stream_close {
Subroutine _on_stream_close: called CC=5 SCAR=16.2
638 42 my ($self, $stream_id, $error_code) = @_;
639 42 delete $self->{receive}{$stream_id};
640 42 delete $self->{providers}{$stream_id};
641  
642 42 ▶ my $transaction = $self->_remove_transaction($stream_id) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $transaction = $self->_remove_transaction($stream_id) or return 0 41 1 42
643  
644 41 ▶ if (!$transaction->is_terminal) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($transaction->is_terminal) 35 6 41
645 35 ▶ if ($error_code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error_code) { } 3 32 35
646 3 my $error = "HTTP/2 stream closed with error $error_code";
647 3 $transaction->_fail($error, $error_code, 1);
648 3 $self->_invoke_stream_error($transaction, $error, $error_code);
649 }
650 else {
651 32 ▶ if (!$transaction->request->is_complete) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($transaction->request->is_complete) 0 32 32
652 0 $transaction->_finish_receive($transaction->request);
653 0 $transaction->request->mark_complete->freeze;
654 }
655 32 $transaction->_mark_complete;
656 32 $transaction->_notify_finish;
657 }
658 }
659  
660 41 return 0;
661 }
662 1 ▶sub close {
Subroutine close: called CC=1 SCAR=0.0
Pod undocumented
663 1 my ($self, @args) = @_;
664 1 $self->SUPER::close(@args);
665 1 $self->{receive} = {};
666 1 $self->{providers} = {};
667 1 return $self;
668 }
669  
670 29 1;
671  
672 __END__
« blib/lib/Unblock/HTTP2/_Headers.pm ↑ Summary blib/lib/Unblock/HTTP2/_nghttp2.pm »