blib/lib/Unblock/HTTP2/Client.pm

filter: Statementstmt 87.2% 260 / 298 Branchbran 69.2% 151 / 218 Conditioncond 55.2% 58 / 105 MC/DCmcdc 25.8% 15 / 58 Subroutinesub 88.5% 31 / 35 Podpod 0.0% 0 / 7 totaltotal 71.4% 515 / 721 CC 152 SCAR 33.1
CC
152
Cov
76%
request
50.6
_on_frame_recv
50.2
_stream_failure
42.0
CRAP 27.3
↑ Summary blib/lib/Unblock/HTTP2/_Headers.pm »
1 package Unblock::HTTP2::Client;
2  
3 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 28 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 28 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 28 ▶use parent 'Unblock::HTTP2::_Connection';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 28 ▶use Unblock::HTTP2::_Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 28 ▶use Unblock::HTTP2::Transaction;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 28 ▶use Uniform::HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 28 our $VERSION = '0.11';
14  
15 28 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
16 28 H2_DATA => 0,
17 H2_HEADERS => 1,
18 H2_GOAWAY => 7,
19 H2_END_STREAM => 0x1,
20 H2_PROTOCOL_ERROR => 1,
21 H2_INTERNAL_ERROR => 2,
22 H2_CANCEL => 8,
23 H2_ENHANCE_YOUR_CALM => 11,
24 28 };
25  
26 28 my $BODY_HIGH_WATER = 65_536;
27 28 my $BODY_LOW_WATER = 32_768;
28  
29 45 ▶sub new {
Subroutine new: called CC=21 SCAR=34.8
Pod undocumented
30 45 my ($class, %option) = @_;
31 45 my $transport = delete $option{transport};
32  
33 45 my %callbacks;
34 45 for my $name (qw(
35 on_settings on_settings_ack on_ping on_ping_ack on_invalid_frame
36 )) {
37 225 ▶ next unless exists $option{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $option{$name} 218 7 225
38 7 my $callback = delete $option{$name};
39 7 ▶ croak "new(): $name must be a coderef"
Branch: 1 branch
BranchTrueFalseTotal
if defined $callback and ref $callback ne "CODE" 0 7 7
Condition33%1/3
defined $callback and ref $callback ne "CODE"
!ll&&!rl&&r
070
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
40 if defined($callback) && ref($callback) ne 'CODE';
41 7 ▶ $callbacks{$name} = $callback if $callback;
Branch: 1 branch
BranchTrueFalseTotal
if $callback 7 0 7
42 }
43  
44 my $settings = exists($option{settings})
45 ? delete($option{settings})
46 45 ▶ : {};
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'settings'} ? : 1 44 45
47 45 ▶ croak 'new(): settings must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $settings eq "HASH" 0 45 45
48 unless ref($settings) eq 'HASH';
49  
50 my $max_active_transactions = exists($option{max_active_transactions})
51 ? delete($option{max_active_transactions})
52 45 ▶ : 100;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'max_active_transactions'} ? : 1 44 45
53 my $max_header_list_size = exists($option{max_header_list_size})
54 ? delete($option{max_header_list_size})
55 45 ▶ : 65_536;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'max_header_list_size'} ? : 0 45 45
56  
57 45 ▶ croak 'new(): max_active_transactions must be a positive integer'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $max_active_transactions and not ref $max_active_transactions and $max_active_transactions =~ /\A[0-9]+\z/ and $max_active_transactions > 0 0 45 45
Condition33%3/9
defined $max_active_transactions and not ref $max_active_transactions and $max_active_transactions =~ /\A[0-9]+\z/ and $max_active_transactions > 0
!ll&&!rl&&r
0045
defined $max_active_transactions and not ref $max_active_transactions and $max_active_transactions =~ /\A[0-9]+\z/
!ll&&!rl&&r
0045
defined $max_active_transactions and not ref $max_active_transactions
!ll&&!rl&&r
0045
MC/DC0%0/4
defined $max_active_transactions and not ref $max_active_transactions and $max_active_transactions =~ /\A[0-9]+\z/ and $max_active_transactions > 0
defined $max_active_transactions not ref $max_active_transactions $max_active_transactions =~ /\A[0-9]+\z/ $max_active_transactions > 0
Truth table20%1/5
A and not(B) and C and D
A= defined $max_active_transactionsB= not ref $max_active_transactionsC= $max_active_transactions =~ /\A[0-9]+\z/D= $max_active_transactions > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
58 unless defined($max_active_transactions) && !ref($max_active_transactions)
59 && $max_active_transactions =~ /\A[0-9]+\z/
60 && $max_active_transactions > 0;
61 45 ▶ 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 45 45
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
0045
defined $max_header_list_size and not ref $max_header_list_size and $max_header_list_size =~ /\A[0-9]+\z/
!ll&&!rl&&r
0045
defined $max_header_list_size and not ref $max_header_list_size
!ll&&!rl&&r
0045
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
62 unless defined($max_header_list_size) && !ref($max_header_list_size)
63 && $max_header_list_size =~ /\A[0-9]+\z/
64 && $max_header_list_size > 0;
65 45 ▶ croak 'new(): unknown options: ' . join(', ', sort keys %option)
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 45 45
66 if %option;
67  
68 45 require Unblock::HTTP2::_nghttp2;
69 45 ▶ croak 'new(): nghttp2 library is unavailable'
Branch: 1 branch
BranchTrueFalseTotal
unless "Unblock::HTTP2::_nghttp2"->available 0 45 45
70 unless Unblock::HTTP2::_nghttp2->available;
71  
72 45 my $self = bless {
73 draining => 0,
74 max_active_transactions => 0 + $max_active_transactions,
75 max_header_list_size => 0 + $max_header_list_size,
76 receive => {},
77 providers => {},
78 peer_goaway => undef,
79 }, $class;
80  
81 45 my $weak = $self;
82 45 weaken($weak);
83  
84 my $session = Unblock::HTTP2::_nghttp2::Session->new_client(
85 max_header_list_size => $self->{max_header_list_size},
86 callbacks => {
87 30 ▶ on_begin_headers => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
88 30 ▶ my $self = $weak or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $self = $weak or return 0 30 0 30
89 30 return $self->_on_begin_headers(@_);
90 },
91 158 ▶ on_frame_recv => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
92 158 ▶ my $self = $weak or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $self = $weak or return 0 158 0 158
93 158 return $self->_on_frame_recv(@_);
94 },
95 35 ▶ on_data_chunk_recv => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
96 35 ▶ my $self = $weak or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $self = $weak or return 0 35 0 35
97 35 return $self->_on_data_chunk_recv(@_);
98 },
99 30 ▶ on_stream_close => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
100 30 ▶ my $self = $weak or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $self = $weak or return 0 30 0 30
101 30 return $self->_on_stream_close(@_);
102 },
103 1 ▶ on_invalid_frame => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
104 1 ▶ my $self = $weak or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $self = $weak or return 0 1 0 1
105 1 return $self->_on_invalid_frame(@_);
106 },
107 },
108 45 );
109  
110 45 $self->_initialize_connection(
111 $session,
112 role => 'client',
113 callbacks => \%callbacks,
114 transport => $transport,
115 );
116  
117 my %initial_settings = (
118 max_concurrent_streams => 100,
119 max_header_list_size => $self->{max_header_list_size},
120 45 enable_push => 0,
121 no_rfc7540_priorities => 1,
122 %$settings,
123 );
124 45 $self->_submit_settings('new()', \%initial_settings);
125 45 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 10 35 45
126  
127 45 return $self;
128 }
129  
130 2 ▶sub draining {
Subroutine draining: called CC=2 SCAR=7.6
Pod undocumented
131 2 ▶ return $_[0]{draining} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'draining'} ? : 2 0 2
132 }
133  
134 3 ▶sub peer_goaway {
Subroutine peer_goaway: called CC=2 SCAR=7.0
Pod undocumented
135 3 my ($self) = @_;
136 3 ▶ return unless $self->{peer_goaway};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"peer_goaway"} 0 3 3
137 3 return { %{ $self->{peer_goaway} } };
138 }
139  
140 1 ▶sub drain {
Subroutine drain: called CC=3 SCAR=12.5
Pod undocumented
141 1 my ($self) = @_;
142 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
143 1 return $self->goaway(error_code => 0);
144 }
145  
146 46 ▶sub can_open_transaction {
Subroutine can_open_transaction: called CC=5 SCAR=16.1
Pod undocumented
147 46 my ($self) = @_;
148 46 ▶ return 0 if $self->is_closed || $self->{draining};
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_closed or $self->{"draining"} 3 43 46
Condition66%2/3
$self->is_closed or $self->{"draining"}
l!l&&r!l&&!r
0343
MC/DC50%1/2
$self->is_closed or $self->{"draining"}
$self->is_closed $self->{"draining"}
Truth table66%2/3
A or B
A= $self->is_closedB= $self->{"draining"}
ABresult
1X1
011
000
149  
150 43 my $limit = $self->{max_active_transactions};
151 43 my $peer_limit = $self->peer_setting('max_concurrent_streams');
152 43 ▶ $limit = $peer_limit if $peer_limit < $limit;
Branch: 1 branch
BranchTrueFalseTotal
if $peer_limit < $limit 5 38 43
153  
154 43 ▶ return $self->transaction_count < $limit ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->transaction_count < $limit ? : 41 2 43
155 }
156  
157 40 ▶sub request {
Subroutine request: called CC=39 SCAR=39.2
Pod undocumented
158 40 my ($self, @arg) = @_;
159  
160 40 my ($request, %option);
161 40 ▶ if (@arg && ref($arg[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@arg and ref $arg[0]) { } 36 4 40
Condition66%2/3
@arg and ref $arg[0]
!ll&&!rl&&r
0436
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
162 36 $request = shift @arg;
163 36 ▶ croak 'request(): options must be key/value pairs' if @arg % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @arg % 2 0 36 36
164 36 %option = @arg;
165 }
166 else {
167 4 ▶ croak 'request(): fields must be key/value pairs' if @arg % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @arg % 2 0 4 4
168 4 my %field = @arg;
169 4 for my $name (qw(
170 stream_body on_response on_body on_complete on_error
171 on_informational on_drain
172 )) {
173 28 ▶ $option{$name} = delete $field{$name} if exists $field{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $field{$name} 13 15 28
174 }
175 4 $request = Uniform::HTTP::Request->new(%field);
176 }
177  
178 40 ▶ croak 'request(): connection is closed' if $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_closed 0 40 40
179 40 ▶ croak 'request(): connection cannot accept another transaction'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can_open_transaction 2 38 40
180 unless $self->can_open_transaction;
181 38 my $native_message = Unblock::HTTP2::_Headers->native_message($request);
182 38 ▶ croak 'request(): requires the Uniform HTTP request contract'
Branch: 1 branch
BranchTrueFalseTotal
unless $native_message or Unblock::HTTP2::_Headers::_request_contract($request) 0 38 38
Condition33%1/3
$native_message or Unblock::HTTP2::_Headers::_request_contract($request)
l!l&&r!l&&!r
3800
MC/DC0%0/2
$native_message or Unblock::HTTP2::_Headers::_request_contract($request)
$native_message Unblock::HTTP2::_Headers::_request_contract($request)
Truth table33%1/3
A or B
A= $native_messageB= Unblock::HTTP2::_Headers::_request_contract($request)
ABresult
1X1
011
000
183 unless $native_message
184 || Unblock::HTTP2::_Headers::_request_contract($request);
185  
186 38 ▶ if (defined($request->protocol) && length($request->protocol)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $request->protocol and length $request->protocol) 2 36 38
Condition66%2/3
defined $request->protocol and length $request->protocol
!ll&&!rl&&r
3602
MC/DC50%1/2
defined $request->protocol and length $request->protocol
defined $request->protocol length $request->protocol
Truth table66%2/3
A and B
A= defined $request->protocolB= length $request->protocol
ABresult
0X0
100
111
187 2 my $enabled = $self->peer_setting('enable_connect_protocol');
188 2 ▶ croak 'request(): peer has not enabled Extended CONNECT'
Branch: 1 branch
BranchTrueFalseTotal
unless $enabled == 1 1 1 2
189 unless $enabled == 1;
190 }
191  
192 my $stream_body = exists($option{stream_body})
193 ? delete($option{stream_body})
194 37 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'stream_body'} ? : 7 30 37
195 37 ▶ croak 'request(): 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 37 37
Condition33%2/6
not defined $stream_body or ref $stream_body or not "$stream_body" =~ /\A[01]\z/
l!l&&r!l&&!r
0037
not defined $stream_body or ref $stream_body
l!l&&r!l&&!r
0037
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
196 if !defined($stream_body) || ref($stream_body)
197 || "$stream_body" !~ /\A[01]\z/;
198 37 ▶ $stream_body = $stream_body ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$stream_body ? : 7 30 37
199  
200 37 my %callbacks;
201 37 for my $name (qw(
202 on_response on_body on_complete on_error on_informational on_drain
203 )) {
204 222 ▶ next unless exists $option{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $option{$name} 143 79 222
205 79 my $callback = delete $option{$name};
206 79 ▶ croak "request(): $name must be a coderef"
Branch: 1 branch
BranchTrueFalseTotal
if defined $callback and ref $callback ne "CODE" 0 79 79
Condition33%1/3
defined $callback and ref $callback ne "CODE"
!ll&&!rl&&r
0790
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
207 if defined($callback) && ref($callback) ne 'CODE';
208 79 ▶ $callbacks{$name} = $callback if $callback;
Branch: 1 branch
BranchTrueFalseTotal
if $callback 79 0 79
209 }
210  
211 37 ▶ croak 'request(): unknown options: ' . join(', ', sort keys %option)
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 37 37
212 if %option;
213 croak 'request(): on_drain requires stream_body'
214 37 ▶ if $callbacks{on_drain} && !$stream_body;
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks{"on_drain"} and not $stream_body 0 37 37
Condition66%2/3
$callbacks{"on_drain"} and not $stream_body
!ll&&!rl&&r
3520
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
215 37 ▶ croak 'request(): stream_body cannot be combined with a buffered body'
Branch: 1 branch
BranchTrueFalseTotal
if $stream_body and $request->has_buffered_body 0 37 37
Condition66%2/3
$stream_body and $request->has_buffered_body
!ll&&!rl&&r
3070
MC/DC0%0/2
$stream_body and $request->has_buffered_body
$stream_body $request->has_buffered_body
Truth table66%2/3
A and B
A= $stream_bodyB= $request->has_buffered_body
ABresult
0X0
100
111
216 if $stream_body && $request->has_buffered_body;
217  
218 37 ▶ my $block = $native_message
Branch: 1 branch
BranchTrueFalseTotal
$native_message ? : 37 0 37
219 ? undef
220 : Unblock::HTTP2::_Headers->request_headers($request);
221 37 my $trailers = Unblock::HTTP2::_Headers->trailer_fields(
222 'request()', $request,
223 );
224  
225 37 my ($provider, $body);
226 37 ▶ if ($stream_body || @$trailers) {
Branch: 2 branches
BranchTrueFalseTotal
if ($stream_body or @$trailers) { } 8 29 37
elsif ($request->has_buffered_body) { } 2 27 29
Condition100%3/3
$stream_body or @$trailers
l!l&&r!l&&!r
7129
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
227 8 $provider = {
228 queue => '',
229 eof => 0,
230 blocked => 0,
231 stream_id => undef,
232 trailers => undef,
233 trailer_submitted => 0,
234 };
235  
236 8 ▶ if (!$stream_body) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stream_body) 1 7 8
237 1 ▶ $provider->{queue} = $request->has_buffered_body
Branch: 1 branch
BranchTrueFalseTotal
$request->has_buffered_body ? : 1 0 1
238 ? $request->body
239 : '';
240 1 $provider->{eof} = 1;
241 1 ▶ $provider->{trailers} = $trailers if @$trailers;
Branch: 1 branch
BranchTrueFalseTotal
if @$trailers 1 0 1
242 }
243  
244 8 my $weak_self = $self;
245 8 weaken($weak_self);
246  
247 21 ▶ $body = sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
248 21 ▶ my $self = $weak_self or return ('', 1);
Branch: 1 branch
BranchTrueFalseTotal
my $self = $weak_self or return "", 1 21 0 21
249 21 return $self->_provide_body($provider, @_);
250 8 };
251 }
252 elsif ($request->has_buffered_body) {
253 2 $body = $request->body;
254 }
255  
256 my $stream_id = $native_message
257 ? $self->{session}->_submit_request_uniform_xs($native_message, $body)
258 37 ▶ : $self->{session}->_submit_request_xs($block, $body);
Branch: 1 branch
BranchTrueFalseTotal
$native_message ? : 37 0 37
259  
260 37 my $transaction = Unblock::HTTP2::Transaction->_new(
261 connection => $self,
262 stream_id => $stream_id,
263 request => $request,
264 callbacks => \%callbacks,
265 );
266  
267 37 $self->_register_transaction($transaction);
268 37 $self->{receive}{$stream_id} = {
269 response => undef,
270 response_done => 0,
271 };
272  
273 37 ▶ if ($provider) {
Branch: 1 branch
BranchTrueFalseTotal
if ($provider) 8 29 37
274 8 $provider->{stream_id} = $stream_id;
275 8 $self->{providers}{$stream_id} = $provider;
276 }
277  
278 37 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 4 33 37
279 37 return $transaction;
280 }
281 21 ▶sub _provide_body {
Subroutine _provide_body: called CC=14 SCAR=26.6
282 21 my ($self, $provider, $stream_id, $max_length) = @_;
283  
284 21 ▶ if (!length($provider->{queue})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $provider->{"queue"}) 3 18 21
285 3 ▶ if ($provider->{eof}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($provider->{"eof"}) 1 2 3
286 1 ▶ if ($provider->{trailers}
Branch: 1 branch
BranchTrueFalseTotal
if ($provider->{"trailers"} and not $provider->{"trailer_submitted"}) 0 1 1
Condition33%1/3
$provider->{"trailers"} and not $provider->{"trailer_submitted"}
!ll&&!rl&&r
100
MC/DC0%0/2
$provider->{"trailers"} and not $provider->{"trailer_submitted"}
$provider->{"trailers"} not $provider->{"trailer_submitted"}
Truth table33%1/3
A and not(B)
A= $provider->{"trailers"}B= not $provider->{"trailer_submitted"}
ABresult
0X0
100
111
287 && !$provider->{trailer_submitted}) {
288 0 $self->_submit_provider_trailers($provider);
289 0 return ('', 1, 1);
290 }
291 1 return ('', 1);
292 }
293 2 return;
294 }
295  
296 my $take = length($provider->{queue}) < $max_length
297 ? length($provider->{queue})
298 18 ▶ : $max_length;
Branch: 1 branch
BranchTrueFalseTotal
length $provider->{'queue'} < $max_length ? : 6 12 18
299 18 my $chunk = substr($provider->{queue}, 0, $take, '');
300 18 ▶ my $eof = $provider->{eof} && !length($provider->{queue}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$provider->{'eof'} && !length($provider->{'queue'}) ? : 6 12 18
Condition100%3/3
$provider->{"eof"} and not length $provider->{"queue"}
!ll&&!rl&&r
576
MC/DC100%2/2
$provider->{"eof"} and not length $provider->{"queue"}
$provider->{"eof"} not length $provider->{"queue"}
Truth table100%3/3
A and not(B)
A= $provider->{"eof"}B= not length $provider->{"queue"}
ABresult
0X0
100
111
301 18 my $no_end_stream = 0;
302  
303 18 ▶ if ($eof && $provider->{trailers}
Branch: 1 branch
BranchTrueFalseTotal
if ($eof and $provider->{"trailers"} and not $provider->{"trailer_submitted"}) 2 16 18
Condition83%5/6
$eof and $provider->{"trailers"} and not $provider->{"trailer_submitted"}
!ll&&!rl&&r
1602
$eof and $provider->{"trailers"}
!ll&&!rl&&r
1242
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
304 && !$provider->{trailer_submitted}) {
305 2 $self->_submit_provider_trailers($provider);
306 2 $no_end_stream = 1;
307 }
308  
309 18 ▶ if ($provider->{blocked}
Branch: 1 branch
BranchTrueFalseTotal
if ($provider->{"blocked"} and length $provider->{"queue"} < $BODY_LOW_WATER) 2 16 18
Condition100%3/3
$provider->{"blocked"} and length $provider->{"queue"} < $BODY_LOW_WATER
!ll&&!rl&&r
1422
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
310 && length($provider->{queue}) < $BODY_LOW_WATER) {
311 2 $provider->{blocked} = 0;
312 2 $self->_queue_drain($provider->{stream_id});
313 }
314  
315 18 ▶ return $no_end_stream
Branch: 1 branch
BranchTrueFalseTotal
$no_end_stream ? : 2 16 18
316 ? ($chunk, $eof, 1)
317 : ($chunk, $eof);
318 }
319  
320 2 ▶sub _submit_provider_trailers {
Subroutine _submit_provider_trailers: called CC=3 SCAR=11.3
321 2 my ($self, $provider) = @_;
322 2 ▶ return if $provider->{trailer_submitted};
Branch: 1 branch
BranchTrueFalseTotal
if $provider->{"trailer_submitted"} 0 2 2
323  
324 $self->{session}->submit_trailer(
325 $provider->{stream_id},
326 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
327 );
328 2 $provider->{trailer_submitted} = 1;
329 2 return;
330 }
331 30 ▶sub _on_begin_headers {
Subroutine _on_begin_headers: called CC=1 SCAR=0.0
332 30 return 0;
333 }
334  
335 1 ▶sub _on_invalid_frame {
Subroutine _on_invalid_frame: called CC=3 SCAR=11.4
336 1 my ($self, $frame, $lib_error_code) = @_;
337  
338 1 ▶ my $copy = ref($frame) eq 'HASH' ? { %$frame } : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $frame eq 'HASH' ? : 1 0 1
339 1 ▶ $self->_invoke_control_callback(
Condition50%1/2
$lib_error_code || 0
l!l
10
MC/DC0%0/1
$lib_error_code || 0
$lib_error_code
Truth table50%1/2
A
A= $lib_error_code
Aresult
11
00
340 'on_invalid_frame',
341 $copy,
342 0 + ($lib_error_code || 0),
343 );
344 1 return 0;
345 }
346  
347 158 ▶sub _on_frame_recv {
Subroutine _on_frame_recv: called CC=32 SCAR=39.2
348 158 my ($self, $frame) = @_;
349  
350 158 ▶ return 0 if $self->_handle_settings_frame($frame);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_handle_settings_frame($frame) 73 85 158
351 85 ▶ return 0 if $self->_handle_ping_frame($frame);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_handle_ping_frame($frame) 3 82 85
352  
353 82 ▶ if (($frame->{type} // -1) == H2_GOAWAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (($frame->{"type"} // -1) == 7) 3 79 82
Condition50%1/2
$frame->{"type"} // -1
l!l
820
MC/DC0%0/1
$frame->{"type"} // -1
$frame->{"type"}
Truth table50%1/2
A
A= $frame->{"type"}
Aresult
11
00
354 3 $self->{draining} = 1;
355 $self->{peer_goaway} = {
356 last_stream_id => 0 + ($frame->{last_stream_id} // 0),
357 error_code => 0 + ($frame->{error_code} // 0),
358 debug_data => defined($frame->{debug_data})
359 3 ▶ ? "$frame->{debug_data}"
Branch: 1 branch
BranchTrueFalseTotal
defined $frame->{'debug_data'} ? : 3 0 3
Condition50%2/4
$frame->{"last_stream_id"} // 0
l!l
30
$frame->{"error_code"} // 0
l!l
30
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
360 : '',
361 };
362 3 return 0;
363 }
364  
365 79 ▶ my $stream_id = $frame->{stream_id} || 0;
Condition100%2/2
$frame->{'stream_id'} || 0
l!l
772
MC/DC100%1/1
$frame->{'stream_id'} || 0
$frame->{'stream_id'}
Truth table100%2/2
A
A= $frame->{'stream_id'}
Aresult
11
00
366 79 ▶ return 0 unless $stream_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $stream_id 2 77 79
367  
368 77 ▶ my $state = $self->{receive}{$stream_id} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $state = $self->{"receive"}{$stream_id} or return 0 76 1 77
369 76 ▶ 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 76 0 76
370  
371 76 ▶ if (($frame->{type} // -1) == H2_HEADERS) {
Branch: 1 branch
BranchTrueFalseTotal
if (($frame->{"type"} // -1) == 1) 30 46 76
Condition50%1/2
$frame->{"type"} // -1
l!l
760
MC/DC0%0/1
$frame->{"type"} // -1
$frame->{"type"}
Truth table50%1/2
A
A= $frame->{"type"}
Aresult
11
00
372 30 ▶ if (defined $frame->{header_error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $frame->{"header_error"}) 0 30 30
373 $self->_stream_failure(
374 $stream_id,
375 "$frame->{header_error}",
376 $frame->{header_error_code},
377 0 );
378 0 return 0;
379 }
380  
381 30 ▶ if (!$state->{response}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($state->{"response"}) 28 2 30
382 28 my $response = $frame->{uniform_message};
383 28 ▶ if (!$response) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response) 0 28 28
384 0 $self->_stream_failure(
385 $stream_id,
386 'HTTP/2 response header block did not produce a Uniform response',
387 );
388 0 return 0;
389 }
390  
391 28 my $status = $response->status;
392 28 ▶ if ($status >= 100 && $status < 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status >= 100 and $status < 200) 3 25 28
Condition66%2/3
$status >= 100 and $status < 200
!ll&&!rl&&r
0253
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
393 3 my $result = $transaction->_invoke(
394 'on_informational', $response,
395 );
396 3 ▶ $self->_stream_failure($stream_id, "$result")
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 0 3 3
397 unless $result eq '1';
398 3 return 0;
399 }
400  
401 25 $state->{response} = $response;
402 25 $transaction->_set_response($response);
403  
404 25 my $result = $transaction->_invoke('on_response', $response);
405 25 ▶ if ($result ne '1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($result ne 1) 0 25 25
406 0 $self->_stream_failure($stream_id, "$result");
407 0 return 0;
408 }
409  
410 25 ▶ if (($frame->{flags} || 0) & H2_END_STREAM) {
Branch: 1 branch
BranchTrueFalseTotal
if (($frame->{"flags"} || 0) & 1) 1 24 25
Condition50%1/2
$frame->{'flags'} || 0
l!l
250
MC/DC0%0/1
$frame->{'flags'} || 0
$frame->{'flags'}
Truth table50%1/2
A
A= $frame->{'flags'}
Aresult
11
00
411 1 $self->_finish_response($stream_id);
412 }
413  
414 25 return 0;
415 }
416  
417 2 ▶ if ($frame->{uniform_message}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($frame->{"uniform_message"}) 0 2 2
418 0 $self->_stream_failure(
419 $stream_id,
420 'HTTP/2 trailing HEADERS must not contain :status',
421 H2_PROTOCOL_ERROR,
422 );
423 0 return 0;
424 }
425  
426 2 ▶ if (!(($frame->{flags} || 0) & H2_END_STREAM)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (($frame->{"flags"} || 0) & 1) 0 2 2
Condition50%1/2
$frame->{'flags'} || 0
l!l
20
MC/DC0%0/1
$frame->{'flags'} || 0
$frame->{'flags'}
Truth table50%1/2
A
A= $frame->{'flags'}
Aresult
11
00
427 0 $self->_stream_failure(
428 $stream_id,
429 'HTTP/2 trailing HEADERS must end the stream',
430 );
431 0 return 0;
432 }
433  
434 2 my $ok = eval {
435 Unblock::HTTP2::_Headers->apply_trailers(
436 $state->{response},
437 2 ▶ $frame->{native_headers} || [],
Condition50%1/2
$frame->{'native_headers'} || []
l!l
20
MC/DC0%0/1
$frame->{'native_headers'} || []
$frame->{'native_headers'}
Truth table50%1/2
A
A= $frame->{'native_headers'}
Aresult
11
00
438 );
439 2 1;
440 };
441 2 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 2 2
442 0 $self->_stream_failure($stream_id, "$@");
443 0 return 0;
444 }
445  
446 2 $self->_finish_response($stream_id);
447 2 return 0;
448 }
449  
450 46 ▶ if (($frame->{type} // -1) == H2_DATA
Branch: 1 branch
BranchTrueFalseTotal
if (($frame->{"type"} // -1) == 0 and ($frame->{"flags"} || 0) & 1) 21 25 46
Condition85%6/7
($frame->{"type"} // -1) == 0 and ($frame->{"flags"} || 0) & 1
!ll&&!rl&&r
121321
$frame->{"type"} // -1
l!l
460
$frame->{'flags'} || 0
l!l
2113
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
451 && (($frame->{flags} || 0) & H2_END_STREAM)) {
452 21 $self->_finish_response($stream_id);
453 }
454  
455 46 return 0;
456 }
457  
458 35 ▶sub _on_data_chunk_recv {
Subroutine _on_data_chunk_recv: called CC=5 SCAR=17.6
459 35 my ($self, $stream_id, $data, $flags) = @_;
460 35 ▶ my $state = $self->{receive}{$stream_id} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $state = $self->{"receive"}{$stream_id} or return 0 34 1 35
461 34 ▶ 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 34 0 34
462 34 my $response = $state->{response};
463  
464 34 ▶ if (!$response) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response) 0 34 34
465 0 $self->_stream_failure(
466 $stream_id,
467 'HTTP/2 DATA arrived before final Response headers',
468 );
469 0 return 0;
470 }
471  
472 34 $transaction->_receive_body_bytes(length $data);
473  
474 34 my $result = $transaction->_invoke('on_body', $response, $data);
475 34 ▶ if ($result ne '1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($result ne 1) 0 34 34
476 0 $self->_stream_failure($stream_id, "$result");
477 0 return 0;
478 }
479  
480 34 $transaction->_auto_consume_body;
481 34 return 0;
482 }
483  
484 24 ▶sub _finish_response {
Subroutine _finish_response: called CC=6 SCAR=19.7
485 24 my ($self, $stream_id) = @_;
486 24 ▶ my $state = $self->{receive}{$stream_id} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $state = $self->{"receive"}{$stream_id} or return 24 0 24
487 24 ▶ return if $state->{response_done}++;
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"response_done"}++ 0 24 24
488  
489 24 ▶ 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 24 0 24
490 24 my $response = $state->{response};
491  
492 24 ▶ if (!$response) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response) 0 24 24
493 0 $self->_stream_failure(
494 $stream_id,
495 'HTTP/2 stream ended before final Response headers',
496 );
497 0 return;
498 }
499  
500 24 $response->mark_complete->freeze;
501  
502 24 my $result = $transaction->_invoke('on_complete');
503 24 ▶ $self->_invoke_stream_error($transaction, "$result")
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 0 24 24
504 unless $result eq '1';
505 24 return;
506 }
507 30 ▶sub _on_stream_close {
Subroutine _on_stream_close: called CC=8 SCAR=21.5
508 30 my ($self, $stream_id, $error_code) = @_;
509 30 my $state = delete $self->{receive}{$stream_id};
510 30 delete $self->{providers}{$stream_id};
511  
512 30 ▶ my $transaction = $self->_remove_transaction($stream_id) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $transaction = $self->_remove_transaction($stream_id) or return 0 30 0 30
513 30 ▶ return 0 if $transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal 2 28 30
514  
515 28 ▶ if ($error_code) {
Branch: 2 branches
BranchTrueFalseTotal
if ($error_code) { } 3 25 28
elsif ($state and $state->{'response'}) { } 24 1 25
516 3 my $error = "HTTP/2 stream closed with error $error_code";
517 3 $transaction->_fail($error, $error_code, 1);
518 3 $self->_invoke_stream_error($transaction, $error, $error_code);
519 }
520 ▶ elsif ($state && $state->{response}) {
Condition66%2/3
$state and $state->{"response"}
!ll&&!rl&&r
1024
MC/DC50%1/2
$state and $state->{"response"}
$state $state->{"response"}
Truth table66%2/3
A and B
A= $stateB= $state->{"response"}
ABresult
0X0
100
111
521 24 $state->{response}->mark_complete->freeze;
522 24 ▶ if (!$state->{response_done}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($state->{"response_done"}) 0 24 24
523 0 my $result = $transaction->_invoke('on_complete');
524 0 ▶ $self->_invoke_stream_error($transaction, "$result")
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 0 0 0
525 unless $result eq '1';
526 }
527 24 $transaction->_mark_complete;
528 }
529 else {
530 1 my $error = 'HTTP/2 stream closed before final Response';
531 1 $transaction->_fail($error);
532 1 $self->_invoke_stream_error($transaction, $error);
533 }
534  
535 28 return 0;
536 }
537 0 ▶sub _stream_failure {
Subroutine _stream_failure: not called CC=6 SCAR=37.4
538 0 my ($self, $stream_id, $error, $code) = @_;
539 0 ▶ $code = H2_INTERNAL_ERROR unless defined $code;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code 0 0 0
540 0 ▶ $error = 'HTTP/2 stream failure'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $error and length $error 0 0 0
Condition0%0/3
defined $error and length $error
!ll&&!rl&&r
000
MC/DC0%0/2
defined $error and length $error
defined $error length $error
Truth table0%0/3
A and B
A= defined $errorB= length $error
ABresult
0X0
100
111
541 unless defined($error) && length($error);
542  
543 0 ▶ 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 0 0 0
544 0 ▶ return if $transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal 0 0 0
545  
546 0 $transaction->_fail($error, $code, 0);
547 0 eval { $self->{session}->submit_rst_stream($stream_id, $code) };
548 0 $self->_invoke_stream_error($transaction, $error, $code);
549 0 return;
550 }
551  
552 12 ▶sub _write_stream_body {
Subroutine _write_stream_body: called CC=10 SCAR=23.0
553 12 my ($self, $transaction, $bytes, $final, $operation) = @_;
554  
555 12 ▶ 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 Request body") 12 0 12
556 or croak "$operation(): Transaction has no streaming Request body";
557  
558 12 $bytes = $self->_body_bytes("$operation()", $bytes);
559 croak "$operation(): streaming Request body is already complete"
560 12 ▶ if $provider->{eof};
Branch: 1 branch
BranchTrueFalseTotal
if $provider->{"eof"} 0 12 12
561  
562 12 $provider->{queue} .= $bytes;
563  
564 12 ▶ if ($final) {
Branch: 1 branch
BranchTrueFalseTotal
if ($final) 6 6 12
565 6 my $trailers = Unblock::HTTP2::_Headers->trailer_fields(
566 "$operation()", $transaction->request,
567 );
568 6 ▶ $provider->{trailers} = $trailers if @$trailers;
Branch: 1 branch
BranchTrueFalseTotal
if @$trailers 1 5 6
569 6 $provider->{eof} = 1;
570 }
571  
572 12 ▶ if ($self->{session}->is_stream_deferred($transaction->stream_id)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"session"}->is_stream_deferred($transaction->stream_id)) 1 11 12
573 1 $self->{session}->resume_stream($transaction->stream_id);
574 }
575  
576 12 my $blocked = length($provider->{queue}) >= $BODY_HIGH_WATER;
577 12 ▶ $provider->{blocked} = 1 if $blocked;
Branch: 1 branch
BranchTrueFalseTotal
if $blocked 1 11 12
578 12 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 1 11 12
579 12 ▶ if ($self->{transport_blocked}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"transport_blocked"}) 1 11 12
580 1 $provider->{blocked} = 1;
581 1 return 0;
582 }
583 11 ▶ return $blocked ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$blocked ? : 1 10 11
584 }
585 0 ▶sub _send_informational_stream {
Subroutine _send_informational_stream: not called CC=1 SCAR=6.9
586 0 croak 'send_informational(): client-side streams cannot send Responses';
587 }
588  
589 0 ▶sub _respond_stream {
Subroutine _respond_stream: not called CC=1 SCAR=6.9
590 0 croak 'respond(): client-side streams cannot send Responses';
591 }
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 8 ▶sub close {
Subroutine close: called CC=1 SCAR=0.0
Pod undocumented
601 8 my ($self, @args) = @_;
602 8 $self->SUPER::close(@args);
603 8 $self->{receive} = {};
604 8 $self->{providers} = {};
605 8 return $self;
606 }
607  
608 28 1;
609  
610 __END__
↑ Summary blib/lib/Unblock/HTTP2/_Headers.pm »