blib/lib/Unblock/HTTP3/Connection.pm

filter: Statementstmt 87.5% 1785 / 2039 Branchbran 66.7% 1039 / 1556 Conditioncond 54.1% 420 / 776 MC/DCmcdc 25.0% 108 / 431 Subroutinesub 86.4% 140 / 162 Podpod 0.0% 0 / 42 totaltotal 69.7% 3492 / 5006 CC 1075 SCAR 43.2
CC
1075
Cov
74%
_new
403.3
_drain_events
271.7
request
155.4
CRAP 75.2
↑ Summary blib/lib/Unblock/HTTP3/Capsule/Stream.pm »
1 package Unblock::HTTP3::Connection;
2  
3 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 22 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 22 ▶use Uniform::HTTP::Request 0.06 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 22 ▶use Uniform::HTTP::Response 0.06 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 22 ▶use Scalar::Util qw(blessed isweak weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 22 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 22 ▶use Unblock::HTTP3 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 22 ▶use Unblock::HTTP3::_Native ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 22 ▶use Unblock::HTTP3::Transaction ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 22 ▶use Net::QUIC::Connection ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 22 our $VERSION = '0.14';
17  
18 22 my $H3_DATAGRAM_ERROR = 0x33;
19 22 my $H3_CLOSED_CRITICAL_STREAM = 0x0104;
20 22 my $H3_EXCESSIVE_LOAD = 0x0107;
21 22 my $H3_ID_ERROR = 0x0108;
22 22 my $H3_SETTINGS_ERROR = 0x0109;
23 22 my $QPACK_DECODER_STREAM_ERROR = 0x0202;
24 22 my $H3_REQUEST_CANCELLED = 0x010c;
25 22 my $H3_MESSAGE_ERROR = 0x010e;
26 22 my $HTTP3_MAX_VARINT = '4611686018427387903';
27 22 my $HTTP3_MAX_QUARTER_STREAM_ID = '1152921504606846975';
28 22 my $SETTINGS_STATE_MAGIC = "UH3S";
29 22 my $SETTINGS_STATE_VERSION = 1;
30  
31 22 my %SETTING_DEFAULT = (
32 1 => '0',
33 6 => $HTTP3_MAX_VARINT,
34 7 => '0',
35 8 => '0',
36 51 => '0',
37 );
38  
39 22 my %CORE_SETTING_ID = map { $_ => 1 } qw(1 6 7 8 51);
40 22 my %RESERVED_SETTING_ID = map { $_ => 1 } qw(0 2 3 4 5);
41 22 my %CORE_STREAM_TYPE = map { $_ => 1 } qw(0 1 2 3);
42 22 my %CONNECTION_SPECIFIC_FIELD = map { $_ => 1 } qw(
43 connection
44 keep-alive
45 proxy-connection
46 transfer-encoding
47 upgrade
48 );
49  
50 44 ▶sub _decimal_mod {
Subroutine _decimal_mod: called CC=2 SCAR=6.9
51 44 my ($value, $divisor) = @_;
52  
53 44 my $remainder = 0;
54  
55 44 for my $digit (split //, "$value") {
56 108 $remainder = ($remainder * 10 + ord($digit) - 48) % $divisor;
57 }
58  
59 44 return $remainder;
60 }
61  
62 35 ▶sub _is_grease_setting_id {
Subroutine _is_grease_setting_id: called CC=5 SCAR=16.7
63 35 my ($id) = @_;
64  
65 35 ▶ return 0 if length($id) < 2;
Branch: 1 branch
BranchTrueFalseTotal
if length $id < 2 0 35 35
66 35 ▶ return 0 if length($id) == 2 && $id lt '33';
Branch: 1 branch
BranchTrueFalseTotal
if length $id == 2 and $id lt 33 0 35 35
Condition66%2/3
length $id == 2 and $id lt 33
!ll&&!rl&&r
10250
MC/DC0%0/2
length $id == 2 and $id lt 33
length $id == 2 $id lt 33
Truth table66%2/3
A and B
A= length $id == 2B= $id lt 33
ABresult
0X0
100
111
67  
68 35 ▶ return _decimal_mod($id, 31) == 2 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
_decimal_mod($id, 31) == 2 ? : 4 31 35
69 }
70  
71 22 ▶sub _assert_extension_setting_id {
Subroutine _assert_extension_setting_id: called CC=4 SCAR=13.9
72 22 my ($id) = @_;
73  
74 croak "HTTP/3 setting $id is reserved for dedicated Unblock::HTTP3 support"
75 22 ▶ if $CORE_SETTING_ID{$id};
Branch: 1 branch
BranchTrueFalseTotal
if $CORE_SETTING_ID{$id} 3 19 22
76 croak "HTTP/3 setting $id is reserved"
77 19 ▶ if $RESERVED_SETTING_ID{$id};
Branch: 1 branch
BranchTrueFalseTotal
if $RESERVED_SETTING_ID{$id} 5 14 19
78 14 ▶ croak "HTTP/3 setting $id is reserved for greasing"
Branch: 1 branch
BranchTrueFalseTotal
if _is_grease_setting_id($id) 3 11 14
79 if _is_grease_setting_id($id);
80  
81 11 return;
82 }
83  
84 125 ▶sub _is_peer_extension_setting_id {
Subroutine _is_peer_extension_setting_id: called CC=4 SCAR=13.9
85 125 my ($id) = @_;
86  
87 125 ▶ return 0 if $CORE_SETTING_ID{$id};
Branch: 1 branch
BranchTrueFalseTotal
if $CORE_SETTING_ID{$id} 104 21 125
88 21 ▶ return 0 if $RESERVED_SETTING_ID{$id};
Branch: 1 branch
BranchTrueFalseTotal
if $RESERVED_SETTING_ID{$id} 0 21 21
89 21 ▶ return 0 if _is_grease_setting_id($id);
Branch: 1 branch
BranchTrueFalseTotal
if _is_grease_setting_id($id) 1 20 21
90  
91 20 return 1;
92 }
93  
94 9 ▶sub _is_grease_stream_type {
Subroutine _is_grease_stream_type: called CC=5 SCAR=17.5
95 9 my ($type) = @_;
96  
97 9 ▶ return 0 if length($type) < 2;
Branch: 1 branch
BranchTrueFalseTotal
if length $type < 2 0 9 9
98 9 ▶ return 0 if length($type) == 2 && $type lt '33';
Branch: 1 branch
BranchTrueFalseTotal
if length $type == 2 and $type lt 33 0 9 9
Condition33%1/3
length $type == 2 and $type lt 33
!ll&&!rl&&r
090
MC/DC0%0/2
length $type == 2 and $type lt 33
length $type == 2 $type lt 33
Truth table33%1/3
A and B
A= length $type == 2B= $type lt 33
ABresult
0X0
100
111
99  
100 9 ▶ return _decimal_mod($type, 31) == 2 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
_decimal_mod($type, 31) == 2 ? : 1 8 9
101 }
102  
103 7 ▶sub _assert_extension_stream_type {
Subroutine _assert_extension_stream_type: called CC=3 SCAR=11.0
104 7 my ($type) = @_;
105  
106 croak "HTTP/3 stream type $type is managed by Unblock::HTTP3"
107 7 ▶ if $CORE_STREAM_TYPE{$type};
Branch: 1 branch
BranchTrueFalseTotal
if $CORE_STREAM_TYPE{$type} 1 6 7
108 6 ▶ croak "HTTP/3 stream type $type is reserved for greasing"
Branch: 1 branch
BranchTrueFalseTotal
if _is_grease_stream_type($type) 1 5 6
109 if _is_grease_stream_type($type);
110  
111 5 return;
112 }
113  
114 31 ▶sub _normalize_extension_stream_handlers {
Subroutine _normalize_extension_stream_handlers: called CC=6 SCAR=18.1
115 31 my ($handlers) = @_;
116  
117 31 ▶ return {} unless defined $handlers;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $handlers 29 2 31
118  
119 2 ▶ croak 'extension_stream_handlers must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $handlers eq "HASH" 0 2 2
120 unless ref($handlers) eq 'HASH';
121  
122 2 my %normalized;
123  
124 2 for my $raw_type (keys %$handlers) {
125 2 my $type = _normalize_http3_varint(
126 $raw_type,
127 'extension stream type',
128 );
129  
130 2 _assert_extension_stream_type($type);
131  
132 2 my $callback = $handlers->{$raw_type};
133  
134 2 ▶ croak "extension stream handler for type $type must be a code reference"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $callback eq "CODE" 0 2 2
135 unless ref($callback) eq 'CODE';
136 croak "duplicate extension stream type $type"
137 2 ▶ if exists $normalized{$type};
Branch: 1 branch
BranchTrueFalseTotal
if exists $normalized{$type} 0 2 2
138  
139 2 $normalized{$type} = $callback;
140 }
141  
142 2 return \%normalized;
143 }
144  
145 175 ▶sub _exceeds_http3_varint {
Subroutine _exceeds_http3_varint: called CC=5 SCAR=16.2
146 175 my ($value) = @_;
147  
148 175 my $text = "$value";
149 175 $text =~ s/\A0+//;
150 175 ▶ $text = '0' if $text eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $text eq "" 4 171 175
151  
152 175 ▶ return 1 if length($text) > length($HTTP3_MAX_VARINT);
Branch: 1 branch
BranchTrueFalseTotal
if length $text > length $HTTP3_MAX_VARINT 0 175 175
153 175 ▶ return 0 if length($text) < length($HTTP3_MAX_VARINT);
Branch: 1 branch
BranchTrueFalseTotal
if length $text < length $HTTP3_MAX_VARINT 173 2 175
154  
155 2 ▶ return $text gt $HTTP3_MAX_VARINT ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$text gt $HTTP3_MAX_VARINT ? : 2 0 2
156 }
157  
158 89 ▶sub _normalize_http3_varint {
Subroutine _normalize_http3_varint: called CC=6 SCAR=19.6
159 89 my ($value, $name) = @_;
160  
161 89 ▶ $name ||= 'HTTP/3 varint';
Condition50%1/2
$name ||= "HTTP/3 varint"
l!l
890
MC/DC0%0/1
$name ||= "HTTP/3 varint"
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
162  
163 89 ▶ croak "$name must be a non-negative integer"
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or ref $value or not "$value" =~ /\A[0-9]+\z/ 0 89 89
Condition33%2/6
not defined $value or ref $value or not "$value" =~ /\A[0-9]+\z/
l!l&&r!l&&!r
0089
not defined $value or ref $value
l!l&&r!l&&!r
0089
MC/DC0%0/3
not defined $value or ref $value or not "$value" =~ /\A[0-9]+\z/
not defined $value ref $value not "$value" =~ /\A[0-9]+\z/
Truth table25%1/4
not(A) or B or not(C)
A= not defined $valueB= ref $valueC= not "$value" =~ /\A[0-9]+\z/
ABCresult
1XX1
01X1
0011
0000
164 if !defined($value)
165 || ref($value)
166 || "$value" !~ /\A[0-9]+\z/;
167  
168 89 my $text = "$value";
169 89 $text =~ s/\A0+(?=[0-9])//;
170  
171 89 ▶ croak "$name exceeds the HTTP/3 varint maximum"
Branch: 1 branch
BranchTrueFalseTotal
if _exceeds_http3_varint($text) 1 88 89
172 if _exceeds_http3_varint($text);
173  
174 88 return $text;
175 }
176  
177 138 ▶sub _encode_http3_varint {
Subroutine _encode_http3_varint: called CC=4 SCAR=13.9
178 138 my ($value) = @_;
179 138 $value = 0 + $value;
180  
181 138 ▶ return pack('C', $value)
Branch: 1 branch
BranchTrueFalseTotal
if $value <= 63 97 41 138
182 if $value <= 63;
183 41 ▶ return pack('n', $value | 0x4000)
Branch: 1 branch
BranchTrueFalseTotal
if $value <= 16383 32 9 41
184 if $value <= 16_383;
185 9 ▶ return pack('N', $value | 0x80000000)
Branch: 1 branch
BranchTrueFalseTotal
if $value <= 1073741823 7 2 9
186 if $value <= 1_073_741_823;
187  
188 2 my $high = (($value >> 32) & 0x3fffffff) | 0xc0000000;
189 2 my $low = $value & 0xffffffff;
190  
191 2 return pack('NN', $high, $low);
192 }
193  
194 591 ▶sub _decode_http3_varint {
Subroutine _decode_http3_varint: called CC=7 SCAR=19.5
195 591 my ($bytes, $offset) = @_;
196 591 ▶ $offset ||= 0;
Condition100%2/2
$offset ||= 0
l!l
166425
MC/DC100%1/1
$offset ||= 0
$offset
Truth table100%2/2
A
A= $offset
Aresult
11
00
197  
198 591 ▶ return if $offset >= length($bytes);
Branch: 1 branch
BranchTrueFalseTotal
if $offset >= length $bytes 70 521 591
199  
200 521 my $first = ord(substr($bytes, $offset, 1));
201 521 my $length = (1, 2, 4, 8)[ $first >> 6 ];
202  
203 521 ▶ return if length($bytes) - $offset < $length;
Branch: 1 branch
BranchTrueFalseTotal
if length($bytes) - $offset < $length 8 513 521
204  
205 513 my $value;
206  
207 513 ▶ if ($length == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($length == 1) { } 388 125 513
elsif ($length == 2) { } 90 35 125
elsif ($length == 4) { } 33 2 35
208 388 $value = $first & 0x3f;
209 } elsif ($length == 2) {
210 90 $value = unpack('n', substr($bytes, $offset, 2)) & 0x3fff;
211 } elsif ($length == 4) {
212 33 $value = unpack('N', substr($bytes, $offset, 4)) & 0x3fffffff;
213 } else {
214 2 my ($high, $low) = unpack('NN', substr($bytes, $offset, 8));
215 2 $high &= 0x3fffffff;
216 2 $value = ($high << 32) | $low;
217 }
218  
219 513 return ("$value", $length);
220 }
221  
222 4 ▶sub _encode_settings_state {
Subroutine _encode_settings_state: called CC=4 SCAR=13.9
223 4 my ($settings) = @_;
224  
225 4 ▶ croak 'HTTP/3 settings state requires a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $settings eq "HASH" 0 4 4
226 unless ref($settings) eq 'HASH';
227  
228 my @ids = sort {
229 4 ▶ length($a) <=> length($b)
Condition66%2/3
length $a <=> length $b || $a cmp $b
l!l&&r!l&&!r
20200
MC/DC0%0/2
length $a <=> length $b || $a cmp $b
length $a <=> length $b $a cmp $b
Truth table66%2/3
A || B
A= length $a <=> length $bB= $a cmp $b
ABresult
1X1
011
000
230 || $a cmp $b
231 } keys %$settings;
232  
233 4 my $out = $SETTINGS_STATE_MAGIC
234 . pack('C', $SETTINGS_STATE_VERSION)
235 . _encode_http3_varint(scalar @ids);
236  
237 4 for my $id (@ids) {
238 23 my $normalized_id = _normalize_http3_varint(
239 $id,
240 'settings state identifier',
241 );
242 my $value = _normalize_http3_varint(
243 23 $settings->{$id},
244 "settings state value for $normalized_id",
245 );
246  
247 23 $out .= _encode_http3_varint($normalized_id);
248 23 $out .= _encode_http3_varint($value);
249 }
250  
251 4 return $out;
252 }
253  
254 7 ▶sub _decode_settings_state {
Subroutine _decode_settings_state: called CC=13 SCAR=27.3
255 7 my ($state, $name) = @_;
256 7 ▶ $name ||= 'HTTP/3 settings state';
Condition50%1/2
$name ||= "HTTP/3 settings state"
l!l
70
MC/DC0%0/1
$name ||= "HTTP/3 settings state"
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
257  
258 7 ▶ croak "$name must be an opaque byte string returned by Unblock::HTTP3"
Branch: 1 branch
BranchTrueFalseTotal
if not defined $state or ref $state 0 7 7
Condition33%1/3
not defined $state or ref $state
l!l&&r!l&&!r
007
MC/DC0%0/2
not defined $state or ref $state
not defined $state ref $state
Truth table33%1/3
not(A) or B
A= not defined $stateB= ref $state
ABresult
1X1
011
000
259 if !defined($state) || ref($state);
260  
261 7 my $header_length = length($SETTINGS_STATE_MAGIC) + 1;
262 7 ▶ croak "invalid $name"
Branch: 1 branch
BranchTrueFalseTotal
if length $state < $header_length or substr($state, 0, length $SETTINGS_STATE_MAGIC) ne $SETTINGS_STATE_MAGIC or ord substr($state, length $SETTINGS_STATE_MAGIC, 1) != $SETTINGS_STATE_VERSION 1 6 7
Condition66%4/6
length $state < $header_length or substr($state, 0, length $SETTINGS_STATE_MAGIC) ne $SETTINGS_STATE_MAGIC or ord substr($state, length $SETTINGS_STATE_MAGIC, 1) != $SETTINGS_STATE_VERSION
l!l&&r!l&&!r
106
length $state < $header_length or substr($state, 0, length $SETTINGS_STATE_MAGIC) ne $SETTINGS_STATE_MAGIC
l!l&&r!l&&!r
016
MC/DC33%1/3
length $state < $header_length or substr($state, 0, length $SETTINGS_STATE_MAGIC) ne $SETTINGS_STATE_MAGIC or ord substr($state, length $SETTINGS_STATE_MAGIC, 1) != $SETTINGS_STATE_VERSION
length $state < $header_length substr($state, 0, length $SETTINGS_STATE_MAGIC) ne $SETTINGS_STATE_MAGIC ord substr($state, length $SETTINGS_STATE_MAGIC, 1) != $SETTINGS_STATE_VERSION
Truth table50%2/4
A or B or C
A= length $state < $header_lengthB= substr($state, 0, length $SETTINGS_STATE_MAGIC) ne $SETTINGS_STATE_MAGICC= ord substr($state, length $SETTINGS_STATE_MAGIC, 1) != $SETTINGS_STATE_VERSION
ABCresult
1XX1
01X1
0011
0000
263 if length($state) < $header_length
264 || substr($state, 0, length($SETTINGS_STATE_MAGIC))
265 ne $SETTINGS_STATE_MAGIC
266 || ord(substr($state, length($SETTINGS_STATE_MAGIC), 1))
267 != $SETTINGS_STATE_VERSION;
268  
269 6 my $offset = $header_length;
270 6 my ($count, $count_length) = _decode_http3_varint($state, $offset);
271 6 ▶ croak "invalid $name" unless defined $count;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $count 0 6 6
272 6 $offset += $count_length;
273  
274 6 my %settings;
275  
276 6 for (1 .. 0 + $count) {
277 35 my ($id, $id_length) = _decode_http3_varint($state, $offset);
278 35 ▶ croak "invalid $name" unless defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 0 35 35
279 35 $offset += $id_length;
280  
281 35 my ($value, $value_length) = _decode_http3_varint($state, $offset);
282 35 ▶ croak "invalid $name" unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 35 35
283 35 $offset += $value_length;
284  
285 croak "invalid $name: duplicate setting $id"
286 35 ▶ if exists $settings{$id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $settings{$id} 0 35 35
287  
288 35 $settings{$id} = $value;
289 }
290  
291 6 ▶ croak "invalid $name: trailing bytes"
Branch: 1 branch
BranchTrueFalseTotal
if $offset != length $state 0 6 6
292 if $offset != length($state);
293  
294 6 return \%settings;
295 }
296  
297 77 ▶sub _effective_setting {
Subroutine _effective_setting: called CC=3 SCAR=16.5
298 77 my ($settings, $id) = @_;
299  
300 return $settings->{$id}
301 77 ▶ if exists $settings->{$id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $settings->{$id} 77 0 77
302  
303 return $SETTING_DEFAULT{$id}
304 0 ▶ if exists $SETTING_DEFAULT{$id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $SETTING_DEFAULT{$id} 0 0 0
305  
306 0 return;
307 }
308  
309 9 ▶sub _settings_compatibility_error {
Subroutine _settings_compatibility_error: called CC=18 SCAR=31.4
310 9 my ($remembered, $current) = @_;
311  
312 9 my $old_qpack_capacity = _effective_setting($remembered, 1);
313 9 my $new_qpack_capacity = _effective_setting($current, 1);
314  
315 9 ▶ if ($old_qpack_capacity ne '0') {
Branch: 1 branch
BranchTrueFalseTotal
if ($old_qpack_capacity ne 0) 9 0 9
316 9 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $current->{1} or $new_qpack_capacity ne $old_qpack_capacity) 2 7 9
Condition66%2/3
not exists $current->{1} or $new_qpack_capacity ne $old_qpack_capacity
l!l&&r!l&&!r
027
MC/DC50%1/2
not exists $current->{1} or $new_qpack_capacity ne $old_qpack_capacity
not exists $current->{1} $new_qpack_capacity ne $old_qpack_capacity
Truth table66%2/3
not(A) or B
A= not exists $current->{1}B= $new_qpack_capacity ne $old_qpack_capacity
ABresult
1X1
011
000
317 !exists($current->{1})
318 || $new_qpack_capacity ne $old_qpack_capacity
319 ) {
320 2 my $message =
321 "SETTINGS_QPACK_MAX_TABLE_CAPACITY changed from "
322 . "$old_qpack_capacity to $new_qpack_capacity";
323  
324 return wantarray
325 2 ▶ ? ($QPACK_DECODER_STREAM_ERROR, $message)
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
326 : $message;
327 }
328 }
329  
330 7 for my $id (qw(6 7 8 51)) {
331 25 my $old = _effective_setting($remembered, $id);
332 25 my $new = _effective_setting($current, $id);
333  
334 25 ▶ if (_decimal_less_than($new, $old)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_decimal_less_than($new, $old)) 2 23 25
335 2 ▶ my $message = $id == 6
Branch: 1 branch
BranchTrueFalseTotal
$id == 6 ? : 1 1 2
336 ? "SETTINGS_MAX_FIELD_SECTION_SIZE decreased from $old to $new"
337 : "HTTP/3 setting $id decreased from $old to $new";
338  
339 return wantarray
340 2 ▶ ? ($H3_SETTINGS_ERROR, $message)
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 2 2
341 : $message;
342 }
343  
344 23 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (exists $remembered->{$id} and $remembered->{$id} ne $SETTING_DEFAULT{$id} and not exists $current->{$id}) 0 23 23
Condition33%2/6
exists $remembered->{$id} and $remembered->{$id} ne $SETTING_DEFAULT{$id} and not exists $current->{$id}
!ll&&!rl&&r
0230
exists $remembered->{$id} and $remembered->{$id} ne $SETTING_DEFAULT{$id}
!ll&&!rl&&r
0023
MC/DC0%0/3
exists $remembered->{$id} and $remembered->{$id} ne $SETTING_DEFAULT{$id} and not exists $current->{$id}
exists $remembered->{$id} $remembered->{$id} ne $SETTING_DEFAULT{$id} not exists $current->{$id}
Truth table25%1/4
A and B and not(C)
A= exists $remembered->{$id}B= $remembered->{$id} ne $SETTING_DEFAULT{$id}C= not exists $current->{$id}
ABCresult
0XX0
10X0
1100
1111
345 exists($remembered->{$id})
346 && $remembered->{$id} ne $SETTING_DEFAULT{$id}
347 && !exists($current->{$id})
348 ) {
349 0 my $message =
350 "HTTP/3 setting $id was previously non-default but is now omitted";
351  
352 return wantarray
353 0 ▶ ? ($H3_SETTINGS_ERROR, $message)
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
354 : $message;
355 }
356 }
357  
358 5 for my $id (
359 grep {
360 30 _is_peer_extension_setting_id($_)
361 } keys %$remembered
362 ) {
363 5 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $current->{$id} or $remembered->{$id} ne $current->{$id}) 1 4 5
Condition66%2/3
not exists $current->{$id} or $remembered->{$id} ne $current->{$id}
l!l&&r!l&&!r
014
MC/DC50%1/2
not exists $current->{$id} or $remembered->{$id} ne $current->{$id}
not exists $current->{$id} $remembered->{$id} ne $current->{$id}
Truth table66%2/3
not(A) or B
A= not exists $current->{$id}B= $remembered->{$id} ne $current->{$id}
ABresult
1X1
011
000
364 !exists($current->{$id})
365 || $remembered->{$id} ne $current->{$id}
366 ) {
367 1 my $message = "extension setting $id changed across 0-RTT";
368  
369 return wantarray
370 1 ▶ ? ($H3_SETTINGS_ERROR, $message)
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
371 : $message;
372 }
373 }
374  
375 4 ▶ return wantarray ? () : undef;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 3 4
376 }
377  
378 43 ▶sub _normalize_extension_settings {
Subroutine _normalize_extension_settings: called CC=5 SCAR=16.2
379 43 my ($settings) = @_;
380  
381 43 ▶ return {} unless defined $settings;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $settings 22 21 43
382  
383 21 ▶ croak 'extension_settings must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $settings eq "HASH" 0 21 21
384 unless ref($settings) eq 'HASH';
385  
386 21 my %normalized;
387  
388 21 for my $raw_id (keys %$settings) {
389 22 my $id = _normalize_http3_varint(
390 $raw_id,
391 'extension setting identifier',
392 );
393  
394 22 _assert_extension_setting_id($id);
395  
396 my $value = _normalize_http3_varint(
397 11 $settings->{$raw_id},
398 "extension setting $id value",
399 );
400  
401 croak "duplicate extension setting identifier $id"
402 10 ▶ if exists $normalized{$id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $normalized{$id} 0 10 10
403  
404 10 $normalized{$id} = $value;
405 }
406  
407 9 return \%normalized;
408 }
409  
410 10 ▶sub _rewrite_control_settings {
Subroutine _rewrite_control_settings: called CC=15 SCAR=29.0
411 10 my ($bytes, $extension_settings) = @_;
412  
413 10 my ($stream_type, $stream_type_length) =
414 _decode_http3_varint($bytes, 0);
415  
416 10 ▶ croak 'libnghttp3 split the initial HTTP/3 control stream type'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stream_type 0 10 10
417 unless defined $stream_type;
418 10 ▶ croak 'libnghttp3 produced an unexpected initial control stream type'
Branch: 1 branch
BranchTrueFalseTotal
unless $stream_type eq 0 0 10 10
419 unless $stream_type eq '0';
420  
421 10 my $frame_type_offset = $stream_type_length;
422 10 my ($frame_type, $frame_type_length) =
423 _decode_http3_varint($bytes, $frame_type_offset);
424  
425 10 ▶ croak 'libnghttp3 split the initial HTTP/3 SETTINGS frame type'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $frame_type 0 10 10
426 unless defined $frame_type;
427 10 ▶ croak 'libnghttp3 did not emit SETTINGS first on the control stream'
Branch: 1 branch
BranchTrueFalseTotal
unless $frame_type eq 4 0 10 10
428 unless $frame_type eq '4';
429  
430 10 my $frame_length_offset = $frame_type_offset + $frame_type_length;
431 10 my ($frame_length, $frame_length_length) =
432 _decode_http3_varint($bytes, $frame_length_offset);
433  
434 10 ▶ croak 'libnghttp3 split the initial HTTP/3 SETTINGS frame length'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $frame_length 0 10 10
435 unless defined $frame_length;
436  
437 10 my $payload_offset = $frame_length_offset + $frame_length_length;
438 10 my $payload_length = 0 + $frame_length;
439  
440 10 ▶ croak 'libnghttp3 split the initial HTTP/3 SETTINGS frame payload'
Branch: 1 branch
BranchTrueFalseTotal
if length($bytes) - $payload_offset < $payload_length 0 10 10
441 if length($bytes) - $payload_offset < $payload_length;
442  
443 10 my $payload = substr($bytes, $payload_offset, $payload_length);
444 10 my %existing;
445 10 my $offset = 0;
446  
447 10 ▶ while ($offset < length($payload)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset < length $payload) 40 10 50
448 40 my ($id, $id_length) = _decode_http3_varint($payload, $offset);
449 40 ▶ croak 'libnghttp3 produced a malformed SETTINGS identifier'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 0 40 40
450 unless defined $id;
451 40 $offset += $id_length;
452  
453 40 my ($value, $value_length) =
454 _decode_http3_varint($payload, $offset);
455 40 ▶ croak 'libnghttp3 produced a malformed SETTINGS value'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 40 40
456 unless defined $value;
457 40 $offset += $value_length;
458  
459 croak "libnghttp3 produced duplicate SETTINGS identifier $id"
460 40 ▶ if exists $existing{$id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $existing{$id} 0 40 40
461  
462 40 $existing{$id} = $value;
463 }
464  
465 10 my $extra = '';
466  
467 10 for my $id (
468 sort {
469 2 ▶ length($a) <=> length($b)
Condition33%1/3
length $a <=> length $b || $a cmp $b
l!l&&r!l&&!r
020
MC/DC0%0/2
length $a <=> length $b || $a cmp $b
length $a <=> length $b $a cmp $b
Truth table33%1/3
A || B
A= length $a <=> length $bB= $a cmp $b
ABresult
1X1
011
000
470 || $a cmp $b
471 } keys %$extension_settings
472 ) {
473 12 my $value = $extension_settings->{$id};
474  
475 12 ▶ if (exists $existing{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $existing{$id}) 0 12 12
476 croak "extension setting $id conflicts with libnghttp3"
477 0 ▶ if $existing{$id} ne $value;
Branch: 1 branch
BranchTrueFalseTotal
if $existing{$id} ne $value 0 0 0
478 0 next;
479 }
480  
481 12 $extra .= _encode_http3_varint($id);
482 12 $extra .= _encode_http3_varint($value);
483 }
484  
485 10 my $new_payload = $payload . $extra;
486 10 my $payload_end = $payload_offset + $payload_length;
487  
488 10 my $rewritten =
489 substr($bytes, 0, $frame_length_offset)
490 . _encode_http3_varint(length($new_payload))
491 . $new_payload
492 . substr($bytes, $payload_end);
493  
494 10 return ($rewritten, length($bytes), length($rewritten) - length($bytes));
495 }
496  
497 314 ▶sub _inspect_peer_settings_bytes {
Subroutine _inspect_peer_settings_bytes: called CC=25 SCAR=32.6
498 314 my ($self, $id, $bytes) = @_;
499  
500 314 ▶ return unless ($id & 0x2) == 0x2;
Branch: 1 branch
BranchTrueFalseTotal
unless ($id & 2) == 2 164 150 314
501  
502 150 my $state = $self->{peer_settings_parser}{$id};
503  
504 150 ▶ if (!defined $state) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $state) 54 96 150
505 54 $state = {
506 stage => 'stream_type',
507 buffer => '',
508 remaining => undef,
509 settings => {},
510 };
511 54 $self->{peer_settings_parser}{$id} = $state;
512 }
513  
514 return if $state->{stage} eq 'ignore'
515 150 ▶ || $state->{stage} eq 'done';
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"stage"} eq "ignore" or $state->{"stage"} eq "done" 72 78 150
Condition100%3/3
$state->{"stage"} eq "ignore" or $state->{"stage"} eq "done"
l!l&&r!l&&!r
71178
MC/DC100%2/2
$state->{"stage"} eq "ignore" or $state->{"stage"} eq "done"
$state->{"stage"} eq "ignore" $state->{"stage"} eq "done"
Truth table100%3/3
A or B
A= $state->{"stage"} eq "ignore"B= $state->{"stage"} eq "done"
ABresult
1X1
011
000
516  
517 78 $state->{buffer} .= $bytes;
518  
519 78 while (1) {
520 300 ▶ if ($state->{stage} eq 'stream_type') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"stage"} eq "stream_type") 54 246 300
521 my ($value, $length) =
522 54 _decode_http3_varint($state->{buffer}, 0);
523 54 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 54 54
524  
525 54 substr($state->{buffer}, 0, $length, '');
526  
527 54 ▶ if ($value ne '0') {
Branch: 1 branch
BranchTrueFalseTotal
if ($value ne 0) 33 21 54
528 33 $state->{stage} = 'ignore';
529 33 $state->{buffer} = '';
530 33 return;
531 }
532  
533 21 $state->{stage} = 'frame_type';
534 21 next;
535 }
536  
537 246 ▶ if ($state->{stage} eq 'frame_type') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"stage"} eq "frame_type") 23 223 246
538 my ($value, $length) =
539 23 _decode_http3_varint($state->{buffer}, 0);
540 23 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 2 21 23
541  
542 21 substr($state->{buffer}, 0, $length, '');
543  
544 21 ▶ if ($value ne '4') {
Branch: 1 branch
BranchTrueFalseTotal
if ($value ne 4) 0 21 21
545 0 $state->{stage} = 'ignore';
546 0 $state->{buffer} = '';
547 0 return;
548 }
549  
550 21 $state->{stage} = 'frame_length';
551 21 next;
552 }
553  
554 223 ▶ if ($state->{stage} eq 'frame_length') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"stage"} eq "frame_length") 23 200 223
555 my ($value, $length) =
556 23 _decode_http3_varint($state->{buffer}, 0);
557 23 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 2 21 23
558  
559 21 substr($state->{buffer}, 0, $length, '');
560 21 $state->{remaining} = 0 + $value;
561 21 $state->{stage} = 'setting_id';
562 21 next;
563 }
564  
565 200 ▶ if ($state->{stage} eq 'setting_id') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"stage"} eq "setting_id") 108 92 200
566 108 ▶ if ($state->{remaining} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"remaining"} == 0) 18 90 108
567 my %extension = map {
568 12 $_ => $state->{settings}{$_}
569 } grep {
570 77 _is_peer_extension_setting_id($_)
571 18 } keys %{ $state->{settings} };
572  
573 $self->{pending_peer_settings} = {
574 18 %{ $state->{settings} },
575 };
576 18 $self->{pending_peer_extension_settings} = \%extension;
577 18 $state->{stage} = 'done';
578 18 $state->{buffer} = '';
579 18 return;
580 }
581  
582 my ($value, $length) =
583 90 _decode_http3_varint($state->{buffer}, 0);
584 90 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 9 81 90
585  
586 81 ▶ if ($length > $state->{remaining}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > $state->{"remaining"}) 0 81 81
587 0 $state->{stage} = 'ignore';
588 0 $state->{buffer} = '';
589 0 return;
590 }
591  
592 81 substr($state->{buffer}, 0, $length, '');
593 81 $state->{remaining} -= $length;
594 81 $state->{setting_id} = $value;
595 81 $state->{stage} = 'setting_value';
596 81 next;
597 }
598  
599 92 ▶ if ($state->{stage} eq 'setting_value') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"stage"} eq "setting_value") 92 0 92
600 my ($value, $length) =
601 92 _decode_http3_varint($state->{buffer}, 0);
602 92 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 11 81 92
603  
604 81 ▶ if ($length > $state->{remaining}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > $state->{"remaining"}) 0 81 81
605 0 $state->{stage} = 'ignore';
606 0 $state->{buffer} = '';
607 0 return;
608 }
609  
610 81 substr($state->{buffer}, 0, $length, '');
611 81 $state->{remaining} -= $length;
612  
613 81 my $setting_id = delete $state->{setting_id};
614  
615 81 ▶ if (exists $state->{settings}{$setting_id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $state->{"settings"}{$setting_id}) 1 80 81
616 1 $state->{stage} = 'ignore';
617 1 $state->{buffer} = '';
618  
619 1 $self->_fail_connection(
620 $H3_SETTINGS_ERROR,
621 "peer sent duplicate HTTP/3 setting $setting_id",
622 );
623 1 return;
624 }
625  
626 80 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($setting_id eq 8 || $setting_id eq 51 and $value ne 0 and $value ne 1) 2 78 80
Condition88%8/9
$setting_id eq 8 || $setting_id eq 51 and $value ne 0 and $value ne 1
!ll&&!rl&&r
64142
$setting_id eq 8 || $setting_id eq 51 and $value ne 0
!ll&&!rl&&r
64016
$setting_id eq 8 or $setting_id eq 51
l!l&&r!l&&!r
7964
MC/DC75%3/4
$setting_id eq 8 || $setting_id eq 51 and $value ne 0 and $value ne 1
$setting_id eq 8 $setting_id eq 51 $value ne 0 $value ne 1
Truth table71%5/7
A or B and C and D
A= $setting_id eq 8B= $setting_id eq 51C= $value ne 0D= $value ne 1
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
627 ($setting_id eq '8' || $setting_id eq '51')
628 && $value ne '0'
629 && $value ne '1'
630 ) {
631 2 $state->{stage} = 'ignore';
632 2 $state->{buffer} = '';
633  
634 2 $self->_fail_connection(
635 $H3_SETTINGS_ERROR,
636 "peer HTTP/3 setting $setting_id must be 0 or 1",
637 );
638 2 return;
639 }
640  
641 78 $state->{settings}{$setting_id} = $value;
642 78 $state->{stage} = 'setting_id';
643 78 next;
644 }
645  
646 0 croak "unknown peer SETTINGS parser state '$state->{stage}'";
647 }
648 }
649  
650 17 ▶sub _accept_peer_extension_settings {
Subroutine _accept_peer_extension_settings: called CC=10 SCAR=23.4
651 17 my ($self) = @_;
652  
653 17 my $all_settings = delete $self->{pending_peer_settings};
654 17 ▶ $all_settings = {} unless defined $all_settings;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $all_settings 1 16 17
655  
656 17 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"remembered_peer_settings"} and $self->{"quic"}->early_data_status eq "accepted") 1 16 17
Condition100%3/3
defined $self->{"remembered_peer_settings"} and $self->{"quic"}->early_data_status eq "accepted"
!ll&&!rl&&r
1511
MC/DC100%2/2
defined $self->{"remembered_peer_settings"} and $self->{"quic"}->early_data_status eq "accepted"
defined $self->{"remembered_peer_settings"} $self->{"quic"}->early_data_status eq "accepted"
Truth table100%3/3
A and B
A= defined $self->{"remembered_peer_settings"}B= $self->{"quic"}->early_data_status eq "accepted"
ABresult
0X0
100
111
657 defined($self->{remembered_peer_settings})
658 && $self->{quic}->early_data_status eq 'accepted'
659 ) {
660 my ($compatibility_code, $compatibility_error) =
661 _settings_compatibility_error(
662 $self->{remembered_peer_settings},
663 1 $all_settings,
664 );
665  
666 1 ▶ if (defined $compatibility_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $compatibility_error) 0 1 1
667 0 $self->_fail_connection(
668 $compatibility_code,
669 "peer SETTINGS are incompatible with accepted 0-RTT: "
670 . $compatibility_error,
671 );
672 0 return;
673 }
674 }
675  
676 17 my $settings = delete $self->{pending_peer_extension_settings};
677 17 ▶ $settings = {} unless defined $settings;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $settings 0 17 17
678  
679 17 $self->{peer_settings_wire} = { %$all_settings };
680 17 $self->{peer_extension_settings} = { %$settings };
681 17 $self->{peer_settings_received} = 1;
682 17 $self->{peer_settings_initialized} = 1;
683  
684 17 my $callback = $self->{on_extension_settings};
685 17 ▶ return 1 unless defined $callback;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $callback 14 3 17
686  
687 3 my $ok = eval {
688 3 $callback->($self, { %$settings });
689 2 1;
690 };
691  
692 3 ▶ return 1 if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 2 1 3
693  
694 1 my $error = $@;
695 1 ▶ $error = 'extension SETTINGS validation failed'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $error and length $error 0 1 1
Condition33%1/3
defined $error and length $error
!ll&&!rl&&r
001
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
696 unless defined($error) && length($error);
697 1 $error =~ s/\s+\z//;
698  
699 1 $self->_fail_connection(
700 $H3_SETTINGS_ERROR,
701 "peer extension SETTINGS rejected: $error",
702 );
703  
704 1 return;
705 }
706  
707 112 ▶sub _ascii_lc {
Subroutine _ascii_lc: called CC=1 SCAR=0.0
708 112 my ($value) = @_;
709 112 my $copy = "$value";
710 112 $copy =~ tr/A-Z/a-z/;
711 112 return $copy;
712 }
713  
714 14 ▶sub _authority_equal {
Subroutine _authority_equal: called CC=2 SCAR=6.9
715 14 my ($left, $right) = @_;
716 14 ▶ return _ascii_lc($left) eq _ascii_lc($right) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
_ascii_lc($left) eq _ascii_lc($right) ? : 11 3 14
717 }
718  
719 11 ▶sub _connect_authority_error {
Subroutine _connect_authority_error: called CC=8 SCAR=20.9
720 11 my ($authority) = @_;
721  
722 11 ▶ return 'CONNECT authority must not contain userinfo'
Branch: 1 branch
BranchTrueFalseTotal
if $authority =~ /@/ 0 11 11
723 if $authority =~ /@/;
724  
725 11 my $port;
726  
727 11 ▶ if ($authority =~ /\A\[[^\]]+\]:([0-9]+)\z/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($authority =~ /\A\[[^\]]+\]:([0-9]+)\z/) { } 1 10 11
elsif ($authority =~ /\A[^:]+:([0-9]+)\z/) { } 8 2 10
728 1 $port = $1;
729 } elsif ($authority =~ /\A[^:]+:([0-9]+)\z/) {
730 8 $port = $1;
731 } else {
732 2 return 'CONNECT authority must contain a host and explicit port';
733 }
734  
735 9 $port =~ s/\A0+(?=[0-9])//;
736  
737 9 ▶ return 'CONNECT authority port must be between 1 and 65535'
Branch: 1 branch
BranchTrueFalseTotal
if $port eq 0 or length $port > 5 or length $port == 5 and $port gt 65535 2 7 9
Condition77%7/9
$port eq 0 or length $port > 5 or length $port == 5 and $port gt 65535
l!l&&r!l&&!r
117
$port eq 0 or length $port > 5
l!l&&r!l&&!r
108
length $port == 5 and $port gt 65535
!ll&&!rl&&r
701
MC/DC50%2/4
$port eq 0 or length $port > 5 or length $port == 5 and $port gt 65535
$port eq 0 length $port > 5 length $port == 5 $port gt 65535
Truth table60%3/5
A or B or C and D
A= $port eq 0B= length $port > 5C= length $port == 5D= $port gt 65535
ABCDresult
1XXX1
01XX1
00111
000X0
00100
738 if $port eq '0'
739 || length($port) > 5
740 || (length($port) == 5 && $port gt '65535');
741  
742 7 return;
743 }
744  
745 103 ▶sub _request_semantic_error {
Subroutine _request_semantic_error: called CC=29 SCAR=35.5
746 103 my (%args) = @_;
747  
748 103 my $method = $args{method};
749 103 my $scheme = $args{scheme};
750 103 my $authority = $args{authority};
751 103 my $target = $args{target};
752 103 my $protocol = $args{protocol};
753 103 ▶ my $host_values = $args{host_values} || [];
Condition50%1/2
$args{'host_values'} || []
l!l
1030
MC/DC0%0/1
$args{'host_values'} || []
$args{'host_values'}
Truth table50%1/2
A
A= $args{'host_values'}
Aresult
11
00
754  
755 103 ▶ return 'multiple Host fields are not allowed'
Branch: 1 branch
BranchTrueFalseTotal
if @$host_values > 1 0 103 103
756 if @$host_values > 1;
757  
758 103 ▶ my $host = @$host_values ? $host_values->[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@$host_values ? : 4 99 103
759  
760 103 ▶ if (defined($authority) && defined($host)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $authority and defined $host) 4 99 103
Condition66%2/3
defined $authority and defined $host
!ll&&!rl&&r
0994
MC/DC50%1/2
defined $authority and defined $host
defined $authority defined $host
Truth table66%2/3
A and B
A= defined $authorityB= defined $host
ABresult
0X0
100
111
761 4 ▶ return 'Host field must match :authority'
Branch: 1 branch
BranchTrueFalseTotal
unless _authority_equal($authority, $host) 3 1 4
762 unless _authority_equal($authority, $host);
763 }
764  
765 100 ▶ if (defined($protocol) && $method ne 'CONNECT') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $protocol and $method ne "CONNECT") 1 99 100
Condition100%3/3
defined $protocol and $method ne "CONNECT"
!ll&&!rl&&r
80191
MC/DC100%2/2
defined $protocol and $method ne "CONNECT"
defined $protocol $method ne "CONNECT"
Truth table100%3/3
A and B
A= defined $protocolB= $method ne "CONNECT"
ABresult
0X0
100
111
766 1 return ':protocol is only valid with CONNECT';
767 }
768  
769 99 ▶ if ($method eq 'CONNECT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "CONNECT") 30 69 99
770 30 ▶ if (defined $protocol) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $protocol) { } 19 11 30
771 19 ▶ return 'Extended CONNECT :protocol must be an HTTP token'
Branch: 1 branch
BranchTrueFalseTotal
unless $protocol =~ /\A[!\#\$%&'*+\-.\^_\x60|~0-9A-Za-z]+\z/ 0 19 19
772 unless $protocol =~ /\A[!\#\$%&'*+\-.\^_\x60|~0-9A-Za-z]+\z/;
773 19 ▶ return 'Extended CONNECT requires :scheme'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $scheme 2 17 19
774 unless defined $scheme;
775 17 ▶ return 'Extended CONNECT requires :path'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target and length $target 2 15 17
Condition66%2/3
defined $target and length $target
!ll&&!rl&&r
2015
MC/DC50%1/2
defined $target and length $target
defined $target length $target
Truth table66%2/3
A and B
A= defined $targetB= length $target
ABresult
0X0
100
111
776 unless defined $target && length $target;
777 } else {
778 11 ▶ return 'CONNECT requires :authority'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $authority 0 11 11
779 unless defined $authority;
780  
781 11 my $error = _connect_authority_error($authority);
782 11 ▶ return $error if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 4 7 11
783  
784 7 ▶ return 'CONNECT target must match :authority'
Branch: 1 branch
BranchTrueFalseTotal
if defined $target and not _authority_equal($target, $authority) 0 7 7
Condition33%1/3
defined $target and not _authority_equal($target, $authority)
!ll&&!rl&&r
070
MC/DC0%0/2
defined $target and not _authority_equal($target, $authority)
defined $target not _authority_equal($target, $authority)
Truth table33%1/3
A and not(B)
A= defined $targetB= not _authority_equal($target, $authority)
ABresult
0X0
100
111
785 if defined($target) && !_authority_equal($target, $authority);
786  
787 7 return;
788 }
789 }
790  
791 84 ▶ if (defined($scheme) && _ascii_lc($scheme) =~ /\Ahttps?\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $scheme and _ascii_lc($scheme) =~ /\Ahttps?\z/) 84 0 84
Condition33%1/3
defined $scheme and _ascii_lc($scheme) =~ /\Ahttps?\z/
!ll&&!rl&&r
0084
MC/DC0%0/2
defined $scheme and _ascii_lc($scheme) =~ /\Ahttps?\z/
defined $scheme _ascii_lc($scheme) =~ /\Ahttps?\z/
Truth table33%1/3
A and B
A= defined $schemeB= _ascii_lc($scheme) =~ /\Ahttps?\z/
ABresult
0X0
100
111
792 84 ▶ my $effective_authority = defined($authority)
Branch: 1 branch
BranchTrueFalseTotal
defined $authority ? : 84 0 84
793 ? $authority
794 : $host;
795  
796 84 ▶ return 'http and https requests require authority'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $effective_authority and length $effective_authority 0 84 84
Condition33%1/3
defined $effective_authority and length $effective_authority
!ll&&!rl&&r
0084
MC/DC0%0/2
defined $effective_authority and length $effective_authority
defined $effective_authority length $effective_authority
Truth table33%1/3
A and B
A= defined $effective_authorityB= length $effective_authority
ABresult
0X0
100
111
797 unless defined $effective_authority && length $effective_authority;
798  
799 84 ▶ return 'http and https authority must not contain userinfo'
Branch: 1 branch
BranchTrueFalseTotal
if $effective_authority =~ /@/ 1 83 84
800 if $effective_authority =~ /@/;
801  
802 83 ▶ return 'http and https :path must not contain a fragment'
Branch: 1 branch
BranchTrueFalseTotal
if $target =~ /#/ 1 82 83
803 if $target =~ /#/;
804  
805 return
806 82 ▶ if $target =~ m{\A/}
Branch: 1 branch
BranchTrueFalseTotal
if $target =~ m[\A/] or $method eq "OPTIONS" and $target eq "*" 80 2 82
Condition83%5/6
$target =~ m[\A/] or $method eq "OPTIONS" and $target eq "*"
l!l&&r!l&&!r
7912
$method eq "OPTIONS" and $target eq "*"
!ll&&!rl&&r
201
MC/DC66%2/3
$target =~ m[\A/] or $method eq "OPTIONS" and $target eq "*"
$target =~ m[\A/] $method eq "OPTIONS" $target eq "*"
Truth table75%3/4
A or B and C
A= $target =~ m[\A/]B= $method eq "OPTIONS"C= $target eq "*"
ABCresult
1XX1
0111
00X0
0100
807 || ($method eq 'OPTIONS' && $target eq '*');
808  
809 2 return 'http and https :path must start with /, except OPTIONS *';
810 }
811  
812 0 return;
813 }
814  
815 0 ▶sub _request_host_values {
Subroutine _request_host_values: not called CC=1 SCAR=6.9
816 0 my ($headers) = @_;
817  
818 return [
819 0 map { $_->[1] }
820 0 grep { _ascii_lc($_->[0]) eq 'host' }
821 @$headers
822 ];
823 }
824  
825 45 ▶sub _assert_request_semantics {
Subroutine _assert_request_semantics: called CC=2 SCAR=7.0
826 45 my ($self, $request, $operation) = @_;
827  
828 45 my $error = _request_semantic_error(
829 method => $request->method,
830 scheme => $request->scheme,
831 authority => $request->authority,
832 target => $request->target,
833 protocol => $request->protocol,
834 host_values => _message_header_values($request, 'host'),
835 );
836  
837 45 ▶ croak "$operation: $error"
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 45 45
838 if defined $error;
839  
840 45 return;
841 }
842  
843 5 ▶sub _valid_origin_serialization {
Subroutine _valid_origin_serialization: called CC=8 SCAR=22.4
844 5 my ($value) = @_;
845  
846 5 ▶ return 0 unless defined($value) && !ref($value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and not ref $value 0 5 5
Condition33%1/3
defined $value and not ref $value
!ll&&!rl&&r
005
MC/DC0%0/2
defined $value and not ref $value
defined $value not ref $value
Truth table33%1/3
A and not(B)
A= defined $valueB= not ref $value
ABresult
0X0
100
111
847 5 ▶ return 0 if $value =~ /[^\x00-\x7f]/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /[^\x00-\x7f]/ 0 5 5
848 5 ▶ return 0 if $value =~ /[\x00-\x20\x7f]/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /[\x00-\x20\x7f]/ 0 5 5
849 5 ▶ return 0 if length($value) > 65_535;
Branch: 1 branch
BranchTrueFalseTotal
if length $value > 65535 0 5 5
850 5 ▶ return 1 if $value eq 'null';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "null" 0 5 5
851  
852 5 my $scheme = qr/[A-Za-z][A-Za-z0-9+.-]*/;
853 5 my $reg_name =
854 qr/(?:[A-Za-z0-9._~-]|%[0-9A-Fa-f]{2}|[!\$&'()*+,;=])+/;
855 5 my $ip_literal =
856 qr/\[(?:[0-9A-Fa-f:.]+|[vV][0-9A-Fa-f]+\.[A-Za-z0-9._~!\$&'()*+,;=:-]+)\]/;
857  
858 5 ▶ return $value =~ m{\A$scheme://(?:$ip_literal|$reg_name)(?::[0-9]+)?\z}
Branch: 1 branch
BranchTrueFalseTotal
$value =~ m[\A$scheme://(?:$ip_literal|$reg_name)(?::[0-9]+)?\z] ? : 4 1 5
859 ? 1
860 : 0;
861 }
862  
863 32 ▶sub _normalize_origins {
Subroutine _normalize_origins: called CC=8 SCAR=21.5
864 32 my ($origins) = @_;
865  
866 32 ▶ return undef unless defined $origins;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $origins 29 3 32
867  
868 3 ▶ croak 'origins must be an array reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $origins eq "ARRAY" 0 3 3
869 unless ref($origins) eq 'ARRAY';
870  
871 3 my @normalized;
872  
873 3 for my $origin (@$origins) {
874 3 ▶ croak 'each origin must be a defined scalar'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $origin or ref $origin 0 3 3
Condition33%1/3
not defined $origin or ref $origin
l!l&&r!l&&!r
003
MC/DC0%0/2
not defined $origin or ref $origin
not defined $origin ref $origin
Truth table33%1/3
not(A) or B
A= not defined $originB= ref $origin
ABresult
1X1
011
000
875 if !defined($origin) || ref($origin);
876  
877 3 my $value = "$origin";
878  
879 3 ▶ croak 'origin exceeds the RFC 9412 16-bit length limit'
Branch: 1 branch
BranchTrueFalseTotal
if length $value > 65535 0 3 3
880 if length($value) > 65_535;
881 3 ▶ croak 'origin must be an RFC 6454 ASCII serialization'
Branch: 1 branch
BranchTrueFalseTotal
unless _valid_origin_serialization($value) 1 2 3
882 unless _valid_origin_serialization($value);
883  
884 2 push @normalized, $value;
885 }
886  
887 2 return \@normalized;
888 }
889  
890 28 ▶sub _serialize_origins {
Subroutine _serialize_origins: called CC=3 SCAR=11.0
891 28 my ($origins) = @_;
892  
893 28 ▶ return undef unless defined $origins;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $origins 27 1 28
894  
895 1 my $payload = '';
896  
897 1 for my $origin (@$origins) {
898 2 $payload .= pack('n', length($origin));
899 2 $payload .= $origin;
900 }
901  
902 1 return $payload;
903 }
904  
905 32 ▶sub _new {
Subroutine _new: called CC=101 SCAR=60.0
906 32 my ($class, $role, %args) = @_;
907  
908 32 my $quic = delete $args{quic};
909 my $send_buffer_limit = exists $args{send_buffer_limit}
910 ? delete $args{send_buffer_limit}
911 32 ▶ : 4 * 1024 * 1024;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'send_buffer_limit'} ? : 2 30 32
912 my $max_field_section_size = exists $args{max_field_section_size}
913 ? delete $args{max_field_section_size}
914 32 ▶ : 65_536;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'max_field_section_size'} ? : 1 31 32
915 my $max_buffered_body_bytes = exists $args{max_buffered_body_bytes}
916 ? delete $args{max_buffered_body_bytes}
917 32 ▶ : 64 * 1024 * 1024;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'max_buffered_body_bytes'} ? : 2 30 32
918 my $max_streaming_body_bytes = exists $args{max_streaming_body_bytes}
919 ? delete $args{max_streaming_body_bytes}
920 32 ▶ : 4 * 1024 * 1024;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'max_streaming_body_bytes'} ? : 0 32 32
921 my $qpack_max_table_capacity = exists $args{qpack_max_table_capacity}
922 ? delete $args{qpack_max_table_capacity}
923 32 ▶ : 4_096;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'qpack_max_table_capacity'} ? : 2 30 32
924 my $qpack_blocked_streams = exists $args{qpack_blocked_streams}
925 ? delete $args{qpack_blocked_streams}
926 32 ▶ : 100;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'qpack_blocked_streams'} ? : 1 31 32
927 my $receive_body = exists $args{receive_body}
928 ? delete $args{receive_body}
929 32 ▶ : 'buffered';
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'receive_body'} ? : 1 31 32
930 my $enable_extended_connect = exists $args{enable_extended_connect}
931 ? delete $args{enable_extended_connect}
932 32 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'enable_extended_connect'} ? : 6 26 32
933 my $enable_http_datagrams = exists $args{enable_http_datagrams}
934 ? delete $args{enable_http_datagrams}
935 32 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'enable_http_datagrams'} ? : 10 22 32
936 32 my $origins = _normalize_origins(delete $args{origins});
937 31 my $datagram_request = delete $args{datagram_request};
938 my $max_buffered_datagram_bytes =
939 exists $args{max_buffered_datagram_bytes}
940 ? delete $args{max_buffered_datagram_bytes}
941 31 ▶ : 1024 * 1024;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'max_buffered_datagram_bytes'} ? : 0 31 31
942 my $max_buffered_datagrams =
943 exists $args{max_buffered_datagrams}
944 ? delete $args{max_buffered_datagrams}
945 31 ▶ : 1024;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'max_buffered_datagrams'} ? : 1 30 31
946 31 my $has_quic_max_bidi_streams = exists $args{quic_max_bidi_streams};
947 my $quic_max_bidi_streams = $has_quic_max_bidi_streams
948 ? delete $args{quic_max_bidi_streams}
949 31 ▶ : 100;
Branch: 1 branch
BranchTrueFalseTotal
$has_quic_max_bidi_streams ? : 0 31 31
950 my $extension_settings = _normalize_extension_settings(
951 delete $args{extension_settings},
952 31 );
953 my $remembered_peer_settings_state =
954 31 delete $args{remembered_peer_settings};
955 my $remembered_local_settings_state =
956 31 delete $args{remembered_local_settings};
957 31 ▶ my $remembered_peer_settings = defined($remembered_peer_settings_state)
Branch: 1 branch
BranchTrueFalseTotal
defined $remembered_peer_settings_state ? : 3 28 31
958 ? _decode_settings_state(
959 $remembered_peer_settings_state,
960 'remembered_peer_settings',
961 )
962 : undef;
963 31 ▶ my $remembered_local_settings = defined($remembered_local_settings_state)
Branch: 1 branch
BranchTrueFalseTotal
defined $remembered_local_settings_state ? : 1 30 31
964 ? _decode_settings_state(
965 $remembered_local_settings_state,
966 'remembered_local_settings',
967 )
968 : undef;
969 31 my $on_extension_settings = delete $args{on_extension_settings};
970 31 my $on_request_available = delete $args{on_request_available};
971 31 my %callbacks;
972 31 for my $name (qw(on_request on_body on_request_end on_error)) {
973 124 ▶ next unless exists $args{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{$name} 118 6 124
974 6 my $callback = delete $args{$name};
975 6 ▶ croak "new(): $name must be a code reference"
Branch: 1 branch
BranchTrueFalseTotal
if defined $callback and ref $callback ne "CODE" 0 6 6
Condition33%1/3
defined $callback and ref $callback ne "CODE"
!ll&&!rl&&r
060
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
976 if defined($callback) && ref($callback) ne 'CODE';
977 6 ▶ $callbacks{$name} = $callback if defined $callback;
Branch: 1 branch
BranchTrueFalseTotal
if defined $callback 6 0 6
978 }
979  
980 31 ▶ croak 'new(): request callbacks are only valid for a server connection'
Branch: 1 branch
BranchTrueFalseTotal
if $role ne "server" and keys %callbacks 0 31 31
Condition66%2/3
$role ne "server" and keys %callbacks
!ll&&!rl&&r
14170
MC/DC0%0/2
$role ne "server" and keys %callbacks
$role ne "server" keys %callbacks
Truth table66%2/3
A and B
A= $role ne "server"B= keys %callbacks
ABresult
0X0
100
111
981 if $role ne 'server' && keys %callbacks;
982  
983 my $extension_stream_handlers =
984 _normalize_extension_stream_handlers(
985 delete $args{extension_stream_handlers},
986 31 );
987  
988 31 ▶ croak 'remembered_peer_settings is only valid for a client connection'
Branch: 1 branch
BranchTrueFalseTotal
if $role ne "client" and defined $remembered_peer_settings 0 31 31
Condition66%2/3
$role ne "client" and defined $remembered_peer_settings
!ll&&!rl&&r
17140
MC/DC0%0/2
$role ne "client" and defined $remembered_peer_settings
$role ne "client" defined $remembered_peer_settings
Truth table66%2/3
A and B
A= $role ne "client"B= defined $remembered_peer_settings
ABresult
0X0
100
111
989 if $role ne 'client' && defined $remembered_peer_settings;
990 31 ▶ croak 'remembered_local_settings is only valid for a server connection'
Branch: 1 branch
BranchTrueFalseTotal
if $role ne "server" and defined $remembered_local_settings 0 31 31
Condition66%2/3
$role ne "server" and defined $remembered_local_settings
!ll&&!rl&&r
14170
MC/DC0%0/2
$role ne "server" and defined $remembered_local_settings
$role ne "server" defined $remembered_local_settings
Truth table66%2/3
A and B
A= $role ne "server"B= defined $remembered_local_settings
ABresult
0X0
100
111
991 if $role ne 'server' && defined $remembered_local_settings;
992  
993 31 ▶ croak 'on_extension_settings must be a code reference'
Branch: 1 branch
BranchTrueFalseTotal
if defined $on_extension_settings and ref $on_extension_settings ne "CODE" 0 31 31
Condition66%2/3
defined $on_extension_settings and ref $on_extension_settings ne "CODE"
!ll&&!rl&&r
2920
MC/DC0%0/2
defined $on_extension_settings and ref $on_extension_settings ne "CODE"
defined $on_extension_settings ref $on_extension_settings ne "CODE"
Truth table66%2/3
A and B
A= defined $on_extension_settingsB= ref $on_extension_settings ne "CODE"
ABresult
0X0
100
111
994 if defined($on_extension_settings)
995 && ref($on_extension_settings) ne 'CODE';
996 31 ▶ croak 'on_request_available must be a code reference'
Branch: 1 branch
BranchTrueFalseTotal
if defined $on_request_available and ref $on_request_available ne "CODE" 0 31 31
Condition33%1/3
defined $on_request_available and ref $on_request_available ne "CODE"
!ll&&!rl&&r
3100
MC/DC0%0/2
defined $on_request_available and ref $on_request_available ne "CODE"
defined $on_request_available ref $on_request_available ne "CODE"
Truth table33%1/3
A and B
A= defined $on_request_availableB= ref $on_request_available ne "CODE"
ABresult
0X0
100
111
997 if defined($on_request_available)
998 && ref($on_request_available) ne 'CODE';
999 31 ▶ croak 'on_request_available is only valid for a client connection'
Branch: 1 branch
BranchTrueFalseTotal
if $role ne "client" and defined $on_request_available 0 31 31
Condition66%2/3
$role ne "client" and defined $on_request_available
!ll&&!rl&&r
17140
MC/DC0%0/2
$role ne "client" and defined $on_request_available
$role ne "client" defined $on_request_available
Truth table66%2/3
A and B
A= $role ne "client"B= defined $on_request_available
ABresult
0X0
100
111
1000 if $role ne 'client' && defined($on_request_available);
1001  
1002 31 ▶ croak 'enable_extended_connect must be 0 or 1'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $enable_extended_connect or ref $enable_extended_connect or not "$enable_extended_connect" =~ /\A[01]\z/ 0 31 31
Condition33%2/6
not defined $enable_extended_connect or ref $enable_extended_connect or not "$enable_extended_connect" =~ /\A[01]\z/
l!l&&r!l&&!r
0031
not defined $enable_extended_connect or ref $enable_extended_connect
l!l&&r!l&&!r
0031
MC/DC0%0/3
not defined $enable_extended_connect or ref $enable_extended_connect or not "$enable_extended_connect" =~ /\A[01]\z/
not defined $enable_extended_connect ref $enable_extended_connect not "$enable_extended_connect" =~ /\A[01]\z/
Truth table25%1/4
not(A) or B or not(C)
A= not defined $enable_extended_connectB= ref $enable_extended_connectC= not "$enable_extended_connect" =~ /\A[01]\z/
ABCresult
1XX1
01X1
0011
0000
1003 if !defined($enable_extended_connect)
1004 || ref($enable_extended_connect)
1005 || "$enable_extended_connect" !~ /\A[01]\z/;
1006 31 ▶ croak 'enable_extended_connect is only valid for a server connection'
Branch: 1 branch
BranchTrueFalseTotal
if $role ne "server" and $enable_extended_connect 0 31 31
Condition66%2/3
$role ne "server" and $enable_extended_connect
!ll&&!rl&&r
14170
MC/DC0%0/2
$role ne "server" and $enable_extended_connect
$role ne "server" $enable_extended_connect
Truth table66%2/3
A and B
A= $role ne "server"B= $enable_extended_connect
ABresult
0X0
100
111
1007 if $role ne 'server' && $enable_extended_connect;
1008  
1009 31 ▶ croak 'enable_http_datagrams must be 0 or 1'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $enable_http_datagrams or ref $enable_http_datagrams or not "$enable_http_datagrams" =~ /\A[01]\z/ 0 31 31
Condition33%2/6
not defined $enable_http_datagrams or ref $enable_http_datagrams or not "$enable_http_datagrams" =~ /\A[01]\z/
l!l&&r!l&&!r
0031
not defined $enable_http_datagrams or ref $enable_http_datagrams
l!l&&r!l&&!r
0031
MC/DC0%0/3
not defined $enable_http_datagrams or ref $enable_http_datagrams or not "$enable_http_datagrams" =~ /\A[01]\z/
not defined $enable_http_datagrams ref $enable_http_datagrams not "$enable_http_datagrams" =~ /\A[01]\z/
Truth table25%1/4
not(A) or B or not(C)
A= not defined $enable_http_datagramsB= ref $enable_http_datagramsC= not "$enable_http_datagrams" =~ /\A[01]\z/
ABCresult
1XX1
01X1
0011
0000
1010 if !defined($enable_http_datagrams)
1011 || ref($enable_http_datagrams)
1012 || "$enable_http_datagrams" !~ /\A[01]\z/;
1013 31 ▶ croak 'datagram_request must be a code reference'
Branch: 1 branch
BranchTrueFalseTotal
if defined $datagram_request and ref $datagram_request ne "CODE" 0 31 31
Condition66%2/3
defined $datagram_request and ref $datagram_request ne "CODE"
!ll&&!rl&&r
2740
MC/DC0%0/2
defined $datagram_request and ref $datagram_request ne "CODE"
defined $datagram_request ref $datagram_request ne "CODE"
Truth table66%2/3
A and B
A= defined $datagram_requestB= ref $datagram_request ne "CODE"
ABresult
0X0
100
111
1014 if defined($datagram_request) && ref($datagram_request) ne 'CODE';
1015 31 ▶ croak 'datagram_request is only valid for a server connection'
Branch: 1 branch
BranchTrueFalseTotal
if $role ne "server" and defined $datagram_request 0 31 31
Condition66%2/3
$role ne "server" and defined $datagram_request
!ll&&!rl&&r
14170
MC/DC0%0/2
$role ne "server" and defined $datagram_request
$role ne "server" defined $datagram_request
Truth table66%2/3
A and B
A= $role ne "server"B= defined $datagram_request
ABresult
0X0
100
111
1016 if $role ne 'server' && defined($datagram_request);
1017 31 ▶ croak 'origins is only valid for a server connection'
Branch: 1 branch
BranchTrueFalseTotal
if $role ne "server" and defined $origins 1 30 31
Condition100%3/3
$role ne "server" and defined $origins
!ll&&!rl&&r
14161
MC/DC100%2/2
$role ne "server" and defined $origins
$role ne "server" defined $origins
Truth table100%3/3
A and B
A= $role ne "server"B= defined $origins
ABresult
0X0
100
111
1018 if $role ne 'server' && defined($origins);
1019  
1020 30 ▶ croak 'quic_max_bidi_streams must be a non-negative integer'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $quic_max_bidi_streams or ref $quic_max_bidi_streams or not "$quic_max_bidi_streams" =~ /\A[0-9]+\z/ 0 30 30
Condition33%2/6
not defined $quic_max_bidi_streams or ref $quic_max_bidi_streams or not "$quic_max_bidi_streams" =~ /\A[0-9]+\z/
l!l&&r!l&&!r
0030
not defined $quic_max_bidi_streams or ref $quic_max_bidi_streams
l!l&&r!l&&!r
0030
MC/DC0%0/3
not defined $quic_max_bidi_streams or ref $quic_max_bidi_streams or not "$quic_max_bidi_streams" =~ /\A[0-9]+\z/
not defined $quic_max_bidi_streams ref $quic_max_bidi_streams not "$quic_max_bidi_streams" =~ /\A[0-9]+\z/
Truth table25%1/4
not(A) or B or not(C)
A= not defined $quic_max_bidi_streamsB= ref $quic_max_bidi_streamsC= not "$quic_max_bidi_streams" =~ /\A[0-9]+\z/
ABCresult
1XX1
01X1
0011
0000
1021 if !defined($quic_max_bidi_streams)
1022 || ref($quic_max_bidi_streams)
1023 || "$quic_max_bidi_streams" !~ /\A[0-9]+\z/;
1024 30 ▶ croak 'quic_max_bidi_streams is only valid for server connections'
Branch: 1 branch
BranchTrueFalseTotal
if $role ne "server" and $has_quic_max_bidi_streams 0 30 30
Condition66%2/3
$role ne "server" and $has_quic_max_bidi_streams
!ll&&!rl&&r
14160
MC/DC0%0/2
$role ne "server" and $has_quic_max_bidi_streams
$role ne "server" $has_quic_max_bidi_streams
Truth table66%2/3
A and B
A= $role ne "server"B= $has_quic_max_bidi_streams
ABresult
0X0
100
111
1025 if $role ne 'server' && $has_quic_max_bidi_streams;
1026  
1027 30 ▶ croak 'quic is required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $quic 0 30 30
1028 unless defined $quic;
1029 30 ▶ croak 'quic must be a Net::QUIC::Connection object'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($quic) and $quic->isa("Net::QUIC::Connection") 0 30 30
Condition33%1/3
builtin::blessed($quic) and $quic->isa("Net::QUIC::Connection")
!ll&&!rl&&r
0030
MC/DC0%0/2
builtin::blessed($quic) and $quic->isa("Net::QUIC::Connection")
builtin::blessed($quic) $quic->isa("Net::QUIC::Connection")
Truth table33%1/3
A and B
A= builtin::blessed($quic)B= $quic->isa("Net::QUIC::Connection")
ABresult
0X0
100
111
1030 unless blessed($quic) && $quic->isa('Net::QUIC::Connection');
1031 30 ▶ croak 'enable_http_datagrams requires QUIC DATAGRAM receive support'
Branch: 1 branch
BranchTrueFalseTotal
if $enable_http_datagrams and not $quic->can_receive_datagram 1 29 30
Condition100%3/3
$enable_http_datagrams and not $quic->can_receive_datagram
!ll&&!rl&&r
2091
MC/DC100%2/2
$enable_http_datagrams and not $quic->can_receive_datagram
$enable_http_datagrams not $quic->can_receive_datagram
Truth table100%3/3
A and not(B)
A= $enable_http_datagramsB= not $quic->can_receive_datagram
ABresult
0X0
100
111
1032 if $enable_http_datagrams && !$quic->can_receive_datagram;
1033  
1034 29 ▶ croak 'send_buffer_limit must be a positive integer'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $send_buffer_limit and not ref $send_buffer_limit and $send_buffer_limit =~ /\A[0-9]+\z/ and $send_buffer_limit > 0 0 29 29
Condition33%3/9
defined $send_buffer_limit and not ref $send_buffer_limit and $send_buffer_limit =~ /\A[0-9]+\z/ and $send_buffer_limit > 0
!ll&&!rl&&r
0029
defined $send_buffer_limit and not ref $send_buffer_limit and $send_buffer_limit =~ /\A[0-9]+\z/
!ll&&!rl&&r
0029
defined $send_buffer_limit and not ref $send_buffer_limit
!ll&&!rl&&r
0029
MC/DC0%0/4
defined $send_buffer_limit and not ref $send_buffer_limit and $send_buffer_limit =~ /\A[0-9]+\z/ and $send_buffer_limit > 0
defined $send_buffer_limit not ref $send_buffer_limit $send_buffer_limit =~ /\A[0-9]+\z/ $send_buffer_limit > 0
Truth table20%1/5
A and not(B) and C and D
A= defined $send_buffer_limitB= not ref $send_buffer_limitC= $send_buffer_limit =~ /\A[0-9]+\z/D= $send_buffer_limit > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1035 unless defined($send_buffer_limit)
1036 && !ref($send_buffer_limit)
1037 && $send_buffer_limit =~ /\A[0-9]+\z/
1038 && $send_buffer_limit > 0;
1039 29 ▶ croak 'max_buffered_datagram_bytes must be a positive integer'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $max_buffered_datagram_bytes and not ref $max_buffered_datagram_bytes and $max_buffered_datagram_bytes =~ /\A[0-9]+\z/ and $max_buffered_datagram_bytes > 0 0 29 29
Condition33%3/9
defined $max_buffered_datagram_bytes and not ref $max_buffered_datagram_bytes and $max_buffered_datagram_bytes =~ /\A[0-9]+\z/ and $max_buffered_datagram_bytes > 0
!ll&&!rl&&r
0029
defined $max_buffered_datagram_bytes and not ref $max_buffered_datagram_bytes and $max_buffered_datagram_bytes =~ /\A[0-9]+\z/
!ll&&!rl&&r
0029
defined $max_buffered_datagram_bytes and not ref $max_buffered_datagram_bytes
!ll&&!rl&&r
0029
MC/DC0%0/4
defined $max_buffered_datagram_bytes and not ref $max_buffered_datagram_bytes and $max_buffered_datagram_bytes =~ /\A[0-9]+\z/ and $max_buffered_datagram_bytes > 0
defined $max_buffered_datagram_bytes not ref $max_buffered_datagram_bytes $max_buffered_datagram_bytes =~ /\A[0-9]+\z/ $max_buffered_datagram_bytes > 0
Truth table20%1/5
A and not(B) and C and D
A= defined $max_buffered_datagram_bytesB= not ref $max_buffered_datagram_bytesC= $max_buffered_datagram_bytes =~ /\A[0-9]+\z/D= $max_buffered_datagram_bytes > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1040 unless defined($max_buffered_datagram_bytes)
1041 && !ref($max_buffered_datagram_bytes)
1042 && $max_buffered_datagram_bytes =~ /\A[0-9]+\z/
1043 && $max_buffered_datagram_bytes > 0;
1044 29 ▶ croak 'max_buffered_datagrams must be a positive integer'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $max_buffered_datagrams and not ref $max_buffered_datagrams and $max_buffered_datagrams =~ /\A[0-9]+\z/ and $max_buffered_datagrams > 0 0 29 29
Condition33%3/9
defined $max_buffered_datagrams and not ref $max_buffered_datagrams and $max_buffered_datagrams =~ /\A[0-9]+\z/ and $max_buffered_datagrams > 0
!ll&&!rl&&r
0029
defined $max_buffered_datagrams and not ref $max_buffered_datagrams and $max_buffered_datagrams =~ /\A[0-9]+\z/
!ll&&!rl&&r
0029
defined $max_buffered_datagrams and not ref $max_buffered_datagrams
!ll&&!rl&&r
0029
MC/DC0%0/4
defined $max_buffered_datagrams and not ref $max_buffered_datagrams and $max_buffered_datagrams =~ /\A[0-9]+\z/ and $max_buffered_datagrams > 0
defined $max_buffered_datagrams not ref $max_buffered_datagrams $max_buffered_datagrams =~ /\A[0-9]+\z/ $max_buffered_datagrams > 0
Truth table20%1/5
A and not(B) and C and D
A= defined $max_buffered_datagramsB= not ref $max_buffered_datagramsC= $max_buffered_datagrams =~ /\A[0-9]+\z/D= $max_buffered_datagrams > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1045 unless defined($max_buffered_datagrams)
1046 && !ref($max_buffered_datagrams)
1047 && $max_buffered_datagrams =~ /\A[0-9]+\z/
1048 && $max_buffered_datagrams > 0;
1049  
1050 29 for my $limit (
1051 [ max_field_section_size => $max_field_section_size ],
1052 [ max_buffered_body_bytes => $max_buffered_body_bytes ],
1053 [ max_streaming_body_bytes => $max_streaming_body_bytes ],
1054 ) {
1055 87 ▶ croak "$limit->[0] must be a positive integer"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $limit->[1] and not ref $limit->[1] and $limit->[1] =~ /\A[0-9]+\z/ and $limit->[1] > 0 and $limit->[1] <= '18446744073709551615' 0 87 87
Condition33%4/12
defined $limit->[1] and not ref $limit->[1] and $limit->[1] =~ /\A[0-9]+\z/ and $limit->[1] > 0 and $limit->[1] <= '18446744073709551615'
!ll&&!rl&&r
0087
defined $limit->[1] and not ref $limit->[1] and $limit->[1] =~ /\A[0-9]+\z/ and $limit->[1] > 0
!ll&&!rl&&r
0087
defined $limit->[1] and not ref $limit->[1] and $limit->[1] =~ /\A[0-9]+\z/
!ll&&!rl&&r
0087
defined $limit->[1] and not ref $limit->[1]
!ll&&!rl&&r
0087
MC/DC0%0/5
defined $limit->[1] and not ref $limit->[1] and $limit->[1] =~ /\A[0-9]+\z/ and $limit->[1] > 0 and $limit->[1] <= '18446744073709551615'
defined $limit->[1] not ref $limit->[1] $limit->[1] =~ /\A[0-9]+\z/ $limit->[1] > 0 $limit->[1] <= '18446744073709551615'
Truth table16%1/6
A and not(B) and C and D and E
A= defined $limit->[1]B= not ref $limit->[1]C= $limit->[1] =~ /\A[0-9]+\z/D= $limit->[1] > 0E= $limit->[1] <= '18446744073709551615'
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
1056 unless defined($limit->[1])
1057 && !ref($limit->[1])
1058 && $limit->[1] =~ /\A[0-9]+\z/
1059 && $limit->[1] > 0 && $limit->[1] <= (~0);
1060 }
1061  
1062 29 for my $setting (
1063 [ qpack_max_table_capacity => $qpack_max_table_capacity ],
1064 [ qpack_blocked_streams => $qpack_blocked_streams ],
1065 ) {
1066 58 ▶ croak "$setting->[0] must be a non-negative integer"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $setting->[1] and not ref $setting->[1] and $setting->[1] =~ /\A[0-9]+\z/ 0 58 58
Condition33%2/6
defined $setting->[1] and not ref $setting->[1] and $setting->[1] =~ /\A[0-9]+\z/
!ll&&!rl&&r
0058
defined $setting->[1] and not ref $setting->[1]
!ll&&!rl&&r
0058
MC/DC0%0/3
defined $setting->[1] and not ref $setting->[1] and $setting->[1] =~ /\A[0-9]+\z/
defined $setting->[1] not ref $setting->[1] $setting->[1] =~ /\A[0-9]+\z/
Truth table25%1/4
A and not(B) and C
A= defined $setting->[1]B= not ref $setting->[1]C= $setting->[1] =~ /\A[0-9]+\z/
ABCresult
0XX0
10X0
1100
1111
1067 unless defined($setting->[1])
1068 && !ref($setting->[1])
1069 && $setting->[1] =~ /\A[0-9]+\z/;
1070 }
1071  
1072 29 ▶ croak 'max_field_section_size exceeds the HTTP/3 varint maximum'
Branch: 1 branch
BranchTrueFalseTotal
if _exceeds_http3_varint($max_field_section_size) 0 29 29
1073 if _exceeds_http3_varint($max_field_section_size);
1074 29 ▶ croak 'qpack_max_table_capacity exceeds the HTTP/3 varint maximum'
Branch: 1 branch
BranchTrueFalseTotal
if _exceeds_http3_varint($qpack_max_table_capacity) 1 28 29
1075 if _exceeds_http3_varint($qpack_max_table_capacity);
1076 28 ▶ croak 'qpack_blocked_streams exceeds the HTTP/3 varint maximum'
Branch: 1 branch
BranchTrueFalseTotal
if _exceeds_http3_varint($qpack_blocked_streams) 0 28 28
1077 if _exceeds_http3_varint($qpack_blocked_streams);
1078  
1079 28 ▶ croak 'receive_body must be buffered or stream'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $receive_body or ref $receive_body or $receive_body ne "buffered" and $receive_body ne "stream" 0 28 28
Condition33%3/9
not defined $receive_body or ref $receive_body or $receive_body ne "buffered" and $receive_body ne "stream"
l!l&&r!l&&!r
0028
not defined $receive_body or ref $receive_body
l!l&&r!l&&!r
0028
$receive_body ne "buffered" and $receive_body ne "stream"
!ll&&!rl&&r
2800
MC/DC0%0/4
not defined $receive_body or ref $receive_body or $receive_body ne "buffered" and $receive_body ne "stream"
not defined $receive_body ref $receive_body $receive_body ne "buffered" $receive_body ne "stream"
Truth table20%1/5
not(A) or B or C and D
A= not defined $receive_bodyB= ref $receive_bodyC= $receive_body ne "buffered"D= $receive_body ne "stream"
ABCDresult
1XXX1
01XX1
00111
000X0
00100
1080 if !defined($receive_body)
1081 || ref($receive_body)
1082 || ($receive_body ne 'buffered' && $receive_body ne 'stream');
1083  
1084 28 ▶ croak 'unknown connection option: ' . join(', ', sort keys %args)
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 28 28
1085 if %args;
1086  
1087 28 my %local_settings = (
1088 1 => "$qpack_max_table_capacity",
1089 6 => "$max_field_section_size",
1090 7 => "$qpack_blocked_streams",
1091 );
1092 28 ▶ $local_settings{8} = '1' if $enable_extended_connect;
Branch: 1 branch
BranchTrueFalseTotal
if $enable_extended_connect 6 22 28
1093 28 ▶ $local_settings{51} = '1' if $enable_http_datagrams;
Branch: 1 branch
BranchTrueFalseTotal
if $enable_http_datagrams 9 19 28
1094 28 @local_settings{keys %$extension_settings}
1095 = values %$extension_settings;
1096  
1097 28 my $origin_list = _serialize_origins($origins);
1098  
1099 28 ▶ if (defined $remembered_local_settings) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $remembered_local_settings) 1 27 28
1100 1 my $compatibility_error = _settings_compatibility_error(
1101 $remembered_local_settings,
1102 \%local_settings,
1103 );
1104  
1105 1 ▶ croak "remembered_local_settings is incompatible with current HTTP/3 settings: "
Branch: 1 branch
BranchTrueFalseTotal
if defined $compatibility_error 0 1 1
1106 . $compatibility_error
1107 if defined $compatibility_error;
1108 }
1109  
1110 28 ▶ my $native = $role eq 'server'
Branch: 1 branch
BranchTrueFalseTotal
$role eq 'server' ? : 14 14 28
1111 ? Unblock::HTTP3::_Native->server(
1112 $max_field_section_size,
1113 $qpack_max_table_capacity,
1114 $qpack_blocked_streams,
1115 $enable_extended_connect,
1116 $enable_http_datagrams,
1117 $origin_list,
1118 )
1119 : Unblock::HTTP3::_Native->client(
1120 $max_field_section_size,
1121 $qpack_max_table_capacity,
1122 $qpack_blocked_streams,
1123 0,
1124 $enable_http_datagrams,
1125 );
1126  
1127 28 ▶ $native->set_max_client_streams_bidi($quic_max_bidi_streams)
Branch: 1 branch
BranchTrueFalseTotal
if $role eq "server" 14 14 28
1128 if $role eq 'server';
1129  
1130 return bless {
1131 role => $role,
1132 quic => $quic,
1133 native => $native,
1134 send_buffer_limit => 0 + $send_buffer_limit,
1135 max_field_section_size => 0 + $max_field_section_size,
1136 max_buffered_body_bytes => 0 + $max_buffered_body_bytes,
1137 max_streaming_body_bytes => 0 + $max_streaming_body_bytes,
1138 qpack_max_table_capacity => 0 + $qpack_max_table_capacity,
1139 qpack_blocked_streams => 0 + $qpack_blocked_streams,
1140 quic_max_bidi_streams => 0 + $quic_max_bidi_streams,
1141 native_max_client_streams_bidi => 0 + $quic_max_bidi_streams,
1142 local_settings => \%local_settings,
1143 remembered_peer_settings => $remembered_peer_settings,
1144 remembered_local_settings => $remembered_local_settings,
1145 peer_settings_wire => {},
1146 peer_max_field_section_size => defined($remembered_peer_settings)
1147 ? _effective_setting($remembered_peer_settings, 6)
1148 : $HTTP3_MAX_VARINT,
1149 receive_body_mode => $receive_body,
1150 enable_extended_connect => $enable_extended_connect ? 1 : 0,
1151 peer_enable_connect_protocol => defined($remembered_peer_settings)
1152 && _effective_setting($remembered_peer_settings, 8) eq '1'
1153 ? 1 : 0,
1154 enable_http_datagrams => $enable_http_datagrams ? 1 : 0,
1155 origins => $origins,
1156 peer_origins => undef,
1157 peer_origin_pending => [],
1158 peer_h3_datagram => defined($remembered_peer_settings)
1159 && _effective_setting($remembered_peer_settings, 51) eq '1'
1160 ? 1 : 0,
1161 datagram_request => $datagram_request,
1162 max_buffered_datagram_bytes => 0 + $max_buffered_datagram_bytes,
1163 max_buffered_datagrams => 0 + $max_buffered_datagrams,
1164 datagram_buffered_bytes => 0,
1165 datagram_buffered_count => 0,
1166 datagram_receive_drops => 0,
1167 extension_settings => $extension_settings,
1168 peer_extension_settings => defined($remembered_peer_settings)
1169 ? {
1170 map {
1171 3 $_ => $remembered_peer_settings->{$_}
1172 } grep {
1173 28 ▶ _is_peer_extension_setting_id($_)
Branch: 7 branches
BranchTrueFalseTotal
defined $remembered_peer_settings ? : 3 25 28
$enable_extended_connect ? : 6 22 28
defined $remembered_peer_settings && _effective_setting($remembered_peer_settings, 8) eq '1' ? : 3 25 28
$enable_http_datagrams ? : 9 19 28
defined $remembered_peer_settings && _effective_setting($remembered_peer_settings, 51) eq '1' ? : 3 25 28
defined $remembered_peer_settings ? : 3 25 28
defined $remembered_peer_settings ? : 3 25 28
Condition66%4/6
defined $remembered_peer_settings and _effective_setting($remembered_peer_settings, 8) eq 1
!ll&&!rl&&r
2503
defined $remembered_peer_settings and _effective_setting($remembered_peer_settings, 51) eq 1
!ll&&!rl&&r
2503
MC/DC50%1/2
defined $remembered_peer_settings and _effective_setting($remembered_peer_settings, 8) eq 1
defined $remembered_peer_settings _effective_setting($remembered_peer_settings, 8) eq 1
MC/DC50%1/2
defined $remembered_peer_settings and _effective_setting($remembered_peer_settings, 51) eq 1
defined $remembered_peer_settings _effective_setting($remembered_peer_settings, 51) eq 1
Truth table66%2/3
A and B
A= defined $remembered_peer_settingsB= _effective_setting($remembered_peer_settings, 8) eq 1
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= defined $remembered_peer_settingsB= _effective_setting($remembered_peer_settings, 51) eq 1
ABresult
0X0
100
111
1174 } keys %$remembered_peer_settings
1175 }
1176 : {},
1177 peer_settings_received => 0,
1178 peer_settings_initialized => defined($remembered_peer_settings) ? 1 : 0,
1179 peer_settings_parser => {},
1180 on_extension_settings => $on_extension_settings,
1181 on_request_available => $on_request_available,
1182 request_credit_blocked => 0,
1183 callbacks => \%callbacks,
1184 control_settings_rewritten => 0,
1185 control_settings_delta => 0,
1186 control_settings_pending => undef,
1187 extension_stream_handlers => $extension_stream_handlers,
1188 extension_stream_objects => {},
1189 peer_uni_probe => {},
1190 core_uni_streams => {},
1191 ignored_uni_streams => {},
1192 started => 0,
1193 early_data_started => 0,
1194 early_data_status => $quic->early_data_status,
1195 early_data_rollback_done => 0,
1196 failed => 0,
1197 error => undef,
1198 error_code => undef,
1199 shutdown_notice_sent => 0,
1200 shutdown_started => 0,
1201 remote_shutdown_id => undef,
1202 servicing => 0,
1203 service_again => 0,
1204 streams => {},
1205 messages => {},
1206 outgoing => {},
1207 stream_lifecycle => {},
1208 building => {},
1209 transactions => {},
1210 ready_transactions => [],
1211 pending_early_transactions => [],
1212 pending_early_datagrams => {},
1213 ready_informational => [],
1214 output_finished => {},
1215 blocked_output => {},
1216 response_sent => {},
1217 }, $class;
1218 }
1219  
1220 58 ▶sub role {
Subroutine role: called CC=2 SCAR=7.1
Pod undocumented
1221 58 my ($self, @args) = @_;
1222 58 ▶ croak 'role() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 58 58
1223 58 return $self->{role};
1224 }
1225  
1226 1 ▶sub quic {
Subroutine quic: called CC=2 SCAR=7.1
Pod undocumented
1227 1 my ($self, @args) = @_;
1228 1 ▶ croak 'quic() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 1 1
1229 1 return $self->{quic};
1230 }
1231  
1232 0 ▶sub nghttp3_version {
Subroutine nghttp3_version: not called CC=2 SCAR=17.9
Pod undocumented
1233 0 my ($self, @args) = @_;
1234 0 ▶ croak 'nghttp3_version() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 0 0
1235 0 return Unblock::HTTP3::_Native::nghttp3_version();
1236 }
1237  
1238 1 ▶sub early_data_status {
Subroutine early_data_status: called CC=3 SCAR=11.4
Pod undocumented
1239 1 my ($self, @args) = @_;
1240 1 ▶ croak 'early_data_status() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 1 1
1241 1 ▶ $self->_sync_early_data_status if $self->{started};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"started"} 1 0 1
1242 1 return $self->{quic}->early_data_status;
1243 }
1244  
1245 3 ▶sub started {
Subroutine started: called CC=3 SCAR=11.7
Pod undocumented
1246 3 my ($self, @args) = @_;
1247 3 ▶ croak 'started() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 3 3
1248 3 ▶ return $self->{started} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'started'} ? : 3 0 3
1249 }
1250  
1251 36 ▶sub failed {
Subroutine failed: called CC=3 SCAR=11.1
Pod undocumented
1252 36 my ($self, @args) = @_;
1253 36 ▶ croak 'failed() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 36 36
1254 36 ▶ return $self->{failed} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'failed'} ? : 10 26 36
1255 }
1256  
1257 6 ▶sub error {
Subroutine error: called CC=2 SCAR=7.1
Pod undocumented
1258 6 my ($self, @args) = @_;
1259 6 ▶ croak 'error() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 6 6
1260 6 return $self->{error};
1261 }
1262  
1263 10 ▶sub error_code {
Subroutine error_code: called CC=2 SCAR=7.1
Pod undocumented
1264 10 my ($self, @args) = @_;
1265 10 ▶ croak 'error_code() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 10 10
1266 10 return $self->{error_code};
1267 }
1268  
1269 0 ▶sub max_field_section_size {
Subroutine max_field_section_size: not called CC=2 SCAR=17.9
Pod undocumented
1270 0 my ($self, @args) = @_;
1271 0 ▶ croak 'max_field_section_size() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 0 0
1272 0 return $self->{max_field_section_size};
1273 }
1274  
1275 1 ▶sub max_buffered_body_bytes {
Subroutine max_buffered_body_bytes: called CC=2 SCAR=7.1
Pod undocumented
1276 1 my ($self, @args) = @_;
1277 1 ▶ croak 'max_buffered_body_bytes() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 1 1
1278 1 return $self->{max_buffered_body_bytes};
1279 }
1280  
1281 0 ▶sub max_streaming_body_bytes {
Subroutine max_streaming_body_bytes: not called CC=2 SCAR=17.9
Pod undocumented
1282 0 my ($self, @args) = @_;
1283 0 ▶ croak 'max_streaming_body_bytes() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 0 0
1284 0 return $self->{max_streaming_body_bytes};
1285 }
1286  
1287 2 ▶sub qpack_max_table_capacity {
Subroutine qpack_max_table_capacity: called CC=2 SCAR=7.1
Pod undocumented
1288 2 my ($self, @args) = @_;
1289 2 ▶ croak 'qpack_max_table_capacity() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 2 2
1290 2 return $self->{qpack_max_table_capacity};
1291 }
1292  
1293 2 ▶sub qpack_blocked_streams {
Subroutine qpack_blocked_streams: called CC=2 SCAR=7.1
Pod undocumented
1294 2 my ($self, @args) = @_;
1295 2 ▶ croak 'qpack_blocked_streams() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 2 2
1296 2 return $self->{qpack_blocked_streams};
1297 }
1298  
1299 2 ▶sub local_settings_state {
Subroutine local_settings_state: called CC=2 SCAR=7.1
Pod undocumented
1300 2 my ($self, @args) = @_;
1301 2 ▶ croak 'local_settings_state() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 2 2
1302 2 return _encode_settings_state($self->{local_settings});
1303 }
1304  
1305 2 ▶sub peer_settings_state {
Subroutine peer_settings_state: called CC=3 SCAR=11.0
Pod undocumented
1306 2 my ($self, @args) = @_;
1307 2 ▶ croak 'peer_settings_state() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 2 2
1308 2 ▶ return unless $self->{peer_settings_received};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"peer_settings_received"} 1 1 2
1309 1 return _encode_settings_state($self->{peer_settings_wire});
1310 }
1311  
1312 3 ▶sub using_remembered_peer_settings {
Subroutine using_remembered_peer_settings: called CC=4 SCAR=14.2
Pod undocumented
1313 3 my ($self, @args) = @_;
1314 3 ▶ croak 'using_remembered_peer_settings() does not accept arguments'
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 3 3
1315 if @args;
1316  
1317 return defined($self->{remembered_peer_settings})
1318 && !$self->{peer_settings_received}
1319 3 ▶ ? 1
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'remembered_peer_settings'} && !$self->{'peer_settings_received'} ? : 2 1 3
Condition66%2/3
defined $self->{"remembered_peer_settings"} and not $self->{"peer_settings_received"}
!ll&&!rl&&r
012
MC/DC50%1/2
defined $self->{"remembered_peer_settings"} and not $self->{"peer_settings_received"}
defined $self->{"remembered_peer_settings"} not $self->{"peer_settings_received"}
Truth table66%2/3
A and not(B)
A= defined $self->{"remembered_peer_settings"}B= not $self->{"peer_settings_received"}
ABresult
0X0
100
111
1320 : 0;
1321 }
1322  
1323 0 ▶sub extension_settings {
Subroutine extension_settings: not called CC=2 SCAR=17.9
Pod undocumented
1324 0 my ($self, @args) = @_;
1325 0 ▶ croak 'extension_settings() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 0 0
1326 0 return { %{ $self->{extension_settings} } };
1327 }
1328  
1329 0 ▶sub extension_setting {
Subroutine extension_setting: not called CC=4 SCAR=30.0
Pod undocumented
1330 0 my ($self, $id, @args) = @_;
1331  
1332 0 $id = _normalize_http3_varint(
1333 $id,
1334 'extension setting identifier',
1335 );
1336  
1337 0 _assert_extension_setting_id($id);
1338  
1339 0 ▶ return $self->{extension_settings}{$id}
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 0 0
1340 unless @args;
1341  
1342 0 ▶ croak 'extension_setting() accepts at most one value'
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 0 0 0
1343 unless @args == 1;
1344 croak 'extension SETTINGS cannot change after start()'
1345 0 ▶ if $self->{started};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"started"} 0 0 0
1346  
1347 0 my $value = _normalize_http3_varint(
1348 $args[0],
1349 "extension setting $id value",
1350 );
1351  
1352 0 $self->{extension_settings}{$id} = $value;
1353 0 return $self;
1354 }
1355  
1356 2 ▶sub peer_extension_settings {
Subroutine peer_extension_settings: called CC=2 SCAR=7.0
Pod undocumented
1357 2 my ($self, @args) = @_;
1358 2 ▶ croak 'peer_extension_settings() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 2 2
1359 2 return { %{ $self->{peer_extension_settings} } };
1360 }
1361  
1362 3 ▶sub peer_extension_setting {
Subroutine peer_extension_setting: called CC=2 SCAR=7.0
Pod undocumented
1363 3 my ($self, $id, @args) = @_;
1364 3 ▶ croak 'peer_extension_setting() accepts one setting identifier'
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 3 3
1365 if @args;
1366  
1367 3 $id = _normalize_http3_varint(
1368 $id,
1369 'peer extension setting identifier',
1370 );
1371  
1372 3 return $self->{peer_extension_settings}{$id};
1373 }
1374  
1375 29 ▶sub peer_settings_received {
Subroutine peer_settings_received: called CC=3 SCAR=11.1
Pod undocumented
1376 29 my ($self, @args) = @_;
1377 29 ▶ croak 'peer_settings_received() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 29 29
1378 29 ▶ return $self->{peer_settings_received} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'peer_settings_received'} ? : 11 18 29
1379 }
1380  
1381 10 ▶sub peer_origins {
Subroutine peer_origins: called CC=3 SCAR=11.0
Pod undocumented
1382 10 my ($self, @args) = @_;
1383 10 ▶ croak 'peer_origins() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 10 10
1384  
1385 10 ▶ return undef unless defined $self->{peer_origins};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"peer_origins"} 6 4 10
1386 4 return [ @{ $self->{peer_origins} } ];
1387 }
1388  
1389 1 ▶sub extended_connect_enabled {
Subroutine extended_connect_enabled: called CC=3 SCAR=11.7
Pod undocumented
1390 1 my ($self, @args) = @_;
1391 1 ▶ croak 'extended_connect_enabled() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 1 1
1392 1 ▶ return $self->{enable_extended_connect} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'enable_extended_connect'} ? : 1 0 1
1393 }
1394  
1395 4 ▶sub peer_extended_connect_enabled {
Subroutine peer_extended_connect_enabled: called CC=3 SCAR=11.1
Pod undocumented
1396 4 my ($self, @args) = @_;
1397 4 ▶ croak 'peer_extended_connect_enabled() does not accept arguments'
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 4 4
1398 if @args;
1399 4 ▶ return $self->{peer_enable_connect_protocol} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'peer_enable_connect_protocol'} ? : 3 1 4
1400 }
1401  
1402 2 ▶sub http_datagrams_enabled {
Subroutine http_datagrams_enabled: called CC=3 SCAR=11.7
Pod undocumented
1403 2 my ($self, @args) = @_;
1404 2 ▶ croak 'http_datagrams_enabled() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 2 2
1405 2 ▶ return $self->{enable_http_datagrams} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'enable_http_datagrams'} ? : 2 0 2
1406 }
1407  
1408 3 ▶sub peer_http_datagrams_enabled {
Subroutine peer_http_datagrams_enabled: called CC=3 SCAR=11.7
Pod undocumented
1409 3 my ($self, @args) = @_;
1410 3 ▶ croak 'peer_http_datagrams_enabled() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 3 3
1411 3 ▶ return $self->{peer_h3_datagram} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'peer_h3_datagram'} ? : 3 0 3
1412 }
1413  
1414 20 ▶sub can_send_http_datagrams {
Subroutine can_send_http_datagrams: called CC=6 SCAR=19.6
Pod undocumented
1415 20 my ($self, @args) = @_;
1416 20 ▶ croak 'can_send_http_datagrams() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 20 20
1417  
1418 20 ▶ return 0 unless $self->{enable_http_datagrams};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"enable_http_datagrams"} 0 20 20
1419 20 ▶ return 0 unless $self->{peer_settings_initialized};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"peer_settings_initialized"} 0 20 20
1420 20 ▶ return 0 unless $self->{peer_h3_datagram};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"peer_h3_datagram"} 0 20 20
1421  
1422 20 ▶ return $self->{quic}->can_send_datagram ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'quic'}->can_send_datagram ? : 20 0 20
1423 }
1424  
1425 2 ▶sub can_receive_http_datagrams {
Subroutine can_receive_http_datagrams: called CC=6 SCAR=19.6
Pod undocumented
1426 2 my ($self, @args) = @_;
1427 2 ▶ croak 'can_receive_http_datagrams() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 2 2
1428  
1429 2 ▶ return 0 unless $self->{enable_http_datagrams};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"enable_http_datagrams"} 0 2 2
1430 2 ▶ return 0 unless $self->{peer_settings_initialized};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"peer_settings_initialized"} 0 2 2
1431 2 ▶ return 0 unless $self->{peer_h3_datagram};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"peer_h3_datagram"} 0 2 2
1432  
1433 2 ▶ return $self->{quic}->can_receive_datagram ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'quic'}->can_receive_datagram ? : 2 0 2
1434 }
1435  
1436 5 ▶sub datagram_receive_drops {
Subroutine datagram_receive_drops: called CC=2 SCAR=7.1
Pod undocumented
1437 5 my ($self, @args) = @_;
1438 5 ▶ croak 'datagram_receive_drops() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 5 5
1439 5 return 0 + $self->{datagram_receive_drops};
1440 }
1441  
1442 0 ▶sub extension_stream_handler {
Subroutine extension_stream_handler: not called CC=5 SCAR=34.0
Pod undocumented
1443 0 my ($self, $type, @args) = @_;
1444  
1445 0 $type = _normalize_http3_varint(
1446 $type,
1447 'extension stream type',
1448 );
1449  
1450 0 _assert_extension_stream_type($type);
1451  
1452 0 ▶ return $self->{extension_stream_handlers}{$type}
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 0 0
1453 unless @args;
1454  
1455 0 ▶ croak 'extension_stream_handler() accepts at most one callback'
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 0 0 0
1456 unless @args == 1;
1457 croak 'extension stream handlers cannot change after start()'
1458 0 ▶ if $self->{started};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"started"} 0 0 0
1459 0 ▶ croak 'extension stream handler must be a code reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args[0] eq "CODE" 0 0 0
1460 unless ref($args[0]) eq 'CODE';
1461  
1462 0 $self->{extension_stream_handlers}{$type} = $args[0];
1463 0 return $self;
1464 }
1465  
1466 5 ▶sub open_extension_stream {
Subroutine open_extension_stream: called CC=4 SCAR=14.0
Pod undocumented
1467 5 my ($self, $type) = @_;
1468  
1469 croak 'HTTP/3 connection has not been started'
1470 5 ▶ unless $self->{started};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"started"} 0 5 5
1471 croak 'HTTP/3 connection has failed'
1472 5 ▶ if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 0 5 5
1473  
1474 5 $type = _normalize_http3_varint(
1475 $type,
1476 'extension stream type',
1477 );
1478  
1479 5 _assert_extension_stream_type($type);
1480  
1481 3 my $stream = $self->{quic}->open_uni_stream;
1482 3 ▶ return unless defined $stream;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stream 0 3 3
1483  
1484 3 my $header = _encode_http3_varint($type);
1485 3 $stream->send($header);
1486  
1487 3 require Unblock::HTTP3::Extension::Stream;
1488  
1489 3 my $extension = Unblock::HTTP3::Extension::Stream->_new(
1490 connection => $self,
1491 stream => $stream,
1492 type => $type,
1493 header_length => length($header),
1494 incoming => 0,
1495 );
1496  
1497 3 my $id = $stream->id;
1498 3 $self->{streams}{$id} = $stream;
1499 3 $self->{extension_stream_objects}{$id} = $extension;
1500  
1501 3 return $extension;
1502 }
1503  
1504 2 ▶sub receive_body_mode {
Subroutine receive_body_mode: called CC=7 SCAR=22.7
Pod undocumented
1505 2 my ($self, @args) = @_;
1506 2 ▶ return $self->{receive_body_mode} unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 2 2
1507  
1508 2 ▶ croak 'receive_body_mode() accepts at most one value'
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 0 2 2
1509 unless @args == 1;
1510 2 ▶ croak 'receive_body_mode must be buffered or stream'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $args[0] or ref $args[0] or $args[0] ne "buffered" and $args[0] ne "stream" 0 2 2
Condition44%4/9
not defined $args[0] or ref $args[0] or $args[0] ne "buffered" and $args[0] ne "stream"
l!l&&r!l&&!r
002
not defined $args[0] or ref $args[0]
l!l&&r!l&&!r
002
$args[0] ne "buffered" and $args[0] ne "stream"
!ll&&!rl&&r
110
MC/DC0%0/4
not defined $args[0] or ref $args[0] or $args[0] ne "buffered" and $args[0] ne "stream"
not defined $args[0] ref $args[0] $args[0] ne "buffered" $args[0] ne "stream"
Truth table40%2/5
not(A) or B or C and D
A= not defined $args[0]B= ref $args[0]C= $args[0] ne "buffered"D= $args[0] ne "stream"
ABCDresult
1XXX1
01XX1
00111
000X0
00100
1511 if !defined($args[0])
1512 || ref($args[0])
1513 || ($args[0] ne 'buffered' && $args[0] ne 'stream');
1514  
1515 2 $self->{receive_body_mode} = $args[0];
1516 2 return $self;
1517 }
1518  
1519 10 ▶sub _fail_connection {
Subroutine _fail_connection: called CC=7 SCAR=20.3
1520 10 my ($self, $code, $message) = @_;
1521  
1522 10 ▶ return if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 0 10 10
1523  
1524 10 $self->{failed} = 1;
1525 10 $self->{error_code} = 0 + $code;
1526 10 $self->{error} = "$message";
1527  
1528 10 my $callback_error = '';
1529 10 for my $transaction (values %{ $self->{transactions} }) {
1530 2 ▶ next if $transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal 1 1 2
1531 1 ▶ eval { $transaction->_mark_error($message, $code); 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $transaction->_mark_error($message, $code); 1 } } or $callback_error ||= "$@" 1 0 1
Condition0%0/3
$callback_error ||= "$@"
l!l&&r!l&&!r
000
MC/DC0%0/2
$callback_error ||= "$@"
$callback_error "$@"
Truth table0%0/3
A ||= B
A= $callback_errorB= "$@"
ABresult
1X1
011
000
1532 or $callback_error ||= "$@";
1533 }
1534  
1535 10 $self->{quic}->close($code);
1536 10 ▶ die $callback_error if length $callback_error;
Branch: 1 branch
BranchTrueFalseTotal
if length $callback_error 0 10 10
1537 10 return;
1538 }
1539  
1540 47 ▶sub request {
Subroutine request: called CC=70 SCAR=50.5
Pod undocumented
1541 47 my ($self, $request, %option) = @_;
1542  
1543 47 ▶ $self->_sync_early_data_status if $self->{started};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"started"} 40 7 47
1544  
1545 croak 'request() is only available on a client HTTP/3 connection'
1546 47 ▶ unless $self->{role} eq 'client';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "client" 0 47 47
1547 47 ▶ croak 'request() requires the Uniform HTTP request contract'
Branch: 1 branch
BranchTrueFalseTotal
unless _request_contract($request) 0 47 47
1548 unless _request_contract($request);
1549  
1550 47 my %callbacks;
1551 47 for my $name (qw(
1552 on_informational on_response on_body on_data on_finish on_complete on_error on_drain
1553 )) {
1554 376 ▶ next unless exists $option{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $option{$name} 355 21 376
1555 21 my $callback = delete $option{$name};
1556 21 ▶ croak "request(): $name must be a code reference"
Branch: 1 branch
BranchTrueFalseTotal
if defined $callback and ref $callback ne "CODE" 0 21 21
Condition33%1/3
defined $callback and ref $callback ne "CODE"
!ll&&!rl&&r
0210
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
1557 if defined($callback) && ref($callback) ne 'CODE';
1558 21 ▶ $callbacks{$name} = $callback if defined $callback;
Branch: 1 branch
BranchTrueFalseTotal
if defined $callback 21 0 21
1559 }
1560  
1561 47 _assert_http3_version($request, 'request()');
1562  
1563 47 ▶ my $is_connect = $request->method eq 'CONNECT' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$request->method eq 'CONNECT' ? : 11 36 47
1564 47 ▶ my $is_extended_connect =
Branch: 1 branch
BranchTrueFalseTotal
$is_connect && defined $request->protocol ? : 8 39 47
Condition100%3/3
$is_connect and defined $request->protocol
!ll&&!rl&&r
3638
MC/DC100%2/2
$is_connect and defined $request->protocol
$is_connect defined $request->protocol
Truth table100%3/3
A and B
A= $is_connectB= defined $request->protocol
ABresult
0X0
100
111
1565 $is_connect && defined($request->protocol) ? 1 : 0;
1566 47 my $stream_body = 0;
1567 47 my $receive_body = $self->{receive_body_mode};
1568 47 my $receive_options = {};
1569 my $datagrams = exists $option{datagrams}
1570 ? delete $option{datagrams}
1571 47 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'datagrams'} ? : 3 44 47
1572 my $early_data = exists $option{early_data}
1573 ? delete $option{early_data}
1574 47 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'early_data'} ? : 2 45 47
1575  
1576 47 ▶ croak 'request(): early_data must be 0 or 1'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $early_data or ref $early_data or not "$early_data" =~ /\A[01]\z/ 0 47 47
Condition33%2/6
not defined $early_data or ref $early_data or not "$early_data" =~ /\A[01]\z/
l!l&&r!l&&!r
0047
not defined $early_data or ref $early_data
l!l&&r!l&&!r
0047
MC/DC0%0/3
not defined $early_data or ref $early_data or not "$early_data" =~ /\A[01]\z/
not defined $early_data ref $early_data not "$early_data" =~ /\A[01]\z/
Truth table25%1/4
not(A) or B or not(C)
A= not defined $early_dataB= ref $early_dataC= not "$early_data" =~ /\A[01]\z/
ABCresult
1XX1
01X1
0011
0000
1577 if !defined($early_data)
1578 || ref($early_data)
1579 || "$early_data" !~ /\A[01]\z/;
1580 47 ▶ croak 'request(): datagrams must be 0 or 1'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $datagrams or ref $datagrams or not "$datagrams" =~ /\A[01]\z/ 0 47 47
Condition33%2/6
not defined $datagrams or ref $datagrams or not "$datagrams" =~ /\A[01]\z/
l!l&&r!l&&!r
0047
not defined $datagrams or ref $datagrams
l!l&&r!l&&!r
0047
MC/DC0%0/3
not defined $datagrams or ref $datagrams or not "$datagrams" =~ /\A[01]\z/
not defined $datagrams ref $datagrams not "$datagrams" =~ /\A[01]\z/
Truth table25%1/4
not(A) or B or not(C)
A= not defined $datagramsB= ref $datagramsC= not "$datagrams" =~ /\A[01]\z/
ABCresult
1XX1
01X1
0011
0000
1581 if !defined($datagrams)
1582 || ref($datagrams)
1583 || "$datagrams" !~ /\A[01]\z/;
1584  
1585 47 ▶ if ($is_connect) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_connect) 11 36 47
1586 11 ▶ if ($is_extended_connect) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_extended_connect) { } 8 3 11
1587 croak 'request(): peer did not enable Extended CONNECT'
1588 8 ▶ unless $self->{peer_enable_connect_protocol};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"peer_enable_connect_protocol"} 1 7 8
1589 7 ▶ croak 'request(): Extended CONNECT requires scheme'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $request->scheme 0 7 7
1590 unless defined $request->scheme;
1591 7 ▶ croak 'request(): Extended CONNECT requires authority'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $request->authority 0 7 7
1592 unless defined $request->authority;
1593 } else {
1594 3 ▶ croak 'request(): CONNECT requires authority'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $request->authority 0 3 3
1595 unless defined $request->authority;
1596 3 ▶ croak 'request(): CONNECT target must match authority'
Branch: 1 branch
BranchTrueFalseTotal
unless _authority_equal($request->target, $request->authority) 0 3 3
1597 unless _authority_equal(
1598 $request->target,
1599 $request->authority,
1600 );
1601 3 ▶ croak 'request(): CONNECT must not have scheme'
Branch: 1 branch
BranchTrueFalseTotal
if defined $request->scheme 0 3 3
1602 if defined $request->scheme;
1603 }
1604  
1605 10 ▶ croak 'request(): CONNECT cannot use a buffered request body'
Branch: 1 branch
BranchTrueFalseTotal
if $request->has_buffered_body 0 10 10
1606 if $request->has_buffered_body;
1607 10 ▶ croak 'request(): CONNECT cannot use request trailers'
Branch: 1 branch
BranchTrueFalseTotal
if $request->trailer_count 0 10 10
1608 if $request->trailer_count;
1609  
1610 10 $receive_body = 'stream';
1611 10 $stream_body = 1;
1612 }
1613  
1614 46 ▶ if (exists $option{stream_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option{"stream_body"}) 8 38 46
1615 8 my $configured = delete $option{stream_body};
1616  
1617 8 ▶ croak 'request(): stream_body must be zero or one'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $configured or ref $configured or not "$configured" =~ /\A[01]\z/ 1 7 8
Condition66%4/6
not defined $configured or ref $configured or not "$configured" =~ /\A[01]\z/
l!l&&r!l&&!r
107
not defined $configured or ref $configured
l!l&&r!l&&!r
017
MC/DC33%1/3
not defined $configured or ref $configured or not "$configured" =~ /\A[01]\z/
not defined $configured ref $configured not "$configured" =~ /\A[01]\z/
Truth table50%2/4
not(A) or B or not(C)
A= not defined $configuredB= ref $configuredC= not "$configured" =~ /\A[01]\z/
ABCresult
1XX1
01X1
0011
0000
1618 if !defined($configured)
1619 || ref($configured)
1620 || "$configured" !~ /\A[01]\z/;
1621  
1622 7 ▶ $stream_body = $configured ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$configured ? : 7 0 7
1623  
1624 7 ▶ croak 'request(): CONNECT requires stream_body => 1'
Branch: 1 branch
BranchTrueFalseTotal
if $is_connect and not $stream_body 0 7 7
Condition66%2/3
$is_connect and not $stream_body
!ll&&!rl&&r
610
MC/DC0%0/2
$is_connect and not $stream_body
$is_connect not $stream_body
Truth table66%2/3
A and not(B)
A= $is_connectB= not $stream_body
ABresult
0X0
100
111
1625 if $is_connect && !$stream_body;
1626 7 ▶ croak 'request(): stream_body cannot be combined with a buffered body'
Branch: 1 branch
BranchTrueFalseTotal
if $stream_body and $request->has_buffered_body 0 7 7
Condition33%1/3
$stream_body and $request->has_buffered_body
!ll&&!rl&&r
070
MC/DC0%0/2
$stream_body and $request->has_buffered_body
$stream_body $request->has_buffered_body
Truth table33%1/3
A and B
A= $stream_bodyB= $request->has_buffered_body
ABresult
0X0
100
111
1627 if $stream_body && $request->has_buffered_body;
1628 }
1629  
1630 $receive_body = 'stream'
1631 45 ▶ if defined $callbacks{on_body};
Branch: 1 branch
BranchTrueFalseTotal
if defined $callbacks{"on_body"} 1 44 45
1632  
1633 croak 'request(): on_drain requires stream_body'
1634 45 ▶ if defined($callbacks{on_drain}) && !$stream_body;
Branch: 1 branch
BranchTrueFalseTotal
if defined $callbacks{"on_drain"} and not $stream_body 0 45 45
Condition33%1/3
defined $callbacks{"on_drain"} and not $stream_body
!ll&&!rl&&r
4500
MC/DC0%0/2
defined $callbacks{"on_drain"} and not $stream_body
defined $callbacks{"on_drain"} not $stream_body
Truth table33%1/3
A and not(B)
A= defined $callbacks{"on_drain"}B= not $stream_body
ABresult
0X0
100
111
1635  
1636 45 ▶ if (exists $option{receive_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option{"receive_body"}) 2 43 45
1637 2 my $value = delete $option{receive_body};
1638  
1639 2 ▶ if (ref($value) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'HASH') { } 1 1 2
1640 1 $receive_body = 'stream';
1641 1 $receive_options = { %$value };
1642 } else {
1643 1 ▶ croak 'request(): receive_body must be buffered, stream, or a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or ref $value or $value ne "buffered" and $value ne "stream" 0 1 1
Condition33%3/9
not defined $value or ref $value or $value ne "buffered" and $value ne "stream"
l!l&&r!l&&!r
001
not defined $value or ref $value
l!l&&r!l&&!r
001
$value ne "buffered" and $value ne "stream"
!ll&&!rl&&r
010
MC/DC0%0/4
not defined $value or ref $value or $value ne "buffered" and $value ne "stream"
not defined $value ref $value $value ne "buffered" $value ne "stream"
Truth table20%1/5
not(A) or B or C and D
A= not defined $valueB= ref $valueC= $value ne "buffered"D= $value ne "stream"
ABCDresult
1XXX1
01XX1
00111
000X0
00100
1644 if !defined($value)
1645 || ref($value)
1646 || ($value ne 'buffered' && $value ne 'stream');
1647 1 $receive_body = $value;
1648 }
1649 }
1650  
1651 45 ▶ croak 'request(): CONNECT response body must use streaming receive mode'
Branch: 1 branch
BranchTrueFalseTotal
if $is_connect and $receive_body ne "stream" 0 45 45
Condition66%2/3
$is_connect and $receive_body ne "stream"
!ll&&!rl&&r
35100
MC/DC0%0/2
$is_connect and $receive_body ne "stream"
$is_connect $receive_body ne "stream"
Truth table66%2/3
A and B
A= $is_connectB= $receive_body ne "stream"
ABresult
0X0
100
111
1652 if $is_connect && $receive_body ne 'stream';
1653  
1654 45 ▶ croak 'request(): unknown options: ' . join(', ', sort keys %option)
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 45 45
1655 if %option;
1656  
1657 45 $self->_assert_request_semantics(
1658 $request,
1659 'request()',
1660 );
1661 45 ▶ my $request_streaming = $stream_body ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$stream_body ? : 16 29 45
1662  
1663 45 $self->_assert_request_content_length(
1664 $request,
1665 'request()',
1666 $request_streaming,
1667 );
1668  
1669 39 ▶ my $sending_early = !$self->{quic}->ready ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!$self->{'quic'}->ready ? : 2 37 39
1670  
1671 39 ▶ if ($sending_early) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sending_early) 2 37 39
1672 2 ▶ croak 'request(): early_data => 1 is required before QUIC handshake completion'
Branch: 1 branch
BranchTrueFalseTotal
unless $early_data 0 2 2
1673 unless $early_data;
1674 croak 'request(): HTTP/3 was not started for 0-RTT'
1675 2 ▶ unless $self->{early_data_started};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"early_data_started"} 0 2 2
1676 croak 'request(): QUIC 0-RTT is not pending'
1677 2 ▶ unless $self->{quic}->early_data_status eq 'pending';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"quic"}->early_data_status eq "pending" 0 2 2
1678 croak 'request(): remembered peer HTTP/3 settings are required for 0-RTT'
1679 2 ▶ unless $self->{peer_settings_initialized};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"peer_settings_initialized"} 0 2 2
1680 }
1681  
1682 croak 'request(): on_data cannot be combined with on_body or receive_body on_data'
1683 39 ▶ if $callbacks{on_data} && ($callbacks{on_body} || $receive_options->{on_data});
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks{"on_data"} and $callbacks{"on_body"} || $receive_options->{"on_data"} 0 39 39
Condition50%3/6
$callbacks{"on_data"} and $callbacks{"on_body"} || $receive_options->{"on_data"}
!ll&&!rl&&r
3720
$callbacks{"on_body"} or $receive_options->{"on_data"}
l!l&&r!l&&!r
002
MC/DC0%0/3
$callbacks{"on_data"} and $callbacks{"on_body"} || $receive_options->{"on_data"}
$callbacks{"on_data"} $callbacks{"on_body"} $receive_options->{"on_data"}
Truth table50%2/4
A and B or C
A= $callbacks{"on_data"}B= $callbacks{"on_body"}C= $receive_options->{"on_data"}
ABCresult
0XX0
1000
11X1
1011
1684 39 my $on_data = delete $callbacks{on_data};
1685  
1686 39 my $stream_id = $self->_submit_request(
1687 $request,
1688 $request_streaming,
1689 );
1690 38 ▶ return unless defined $stream_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stream_id 0 38 38
1691  
1692 38 ▶ $request->mark_incomplete if $request_streaming;
Branch: 1 branch
BranchTrueFalseTotal
if $request_streaming 15 23 38
1693  
1694 38 my $transaction = Unblock::HTTP3::Transaction->_new(
1695 connection => $self,
1696 stream_id => $stream_id,
1697 request => $request,
1698 request_streaming => $request_streaming,
1699 early_data => $sending_early,
1700 callbacks => \%callbacks,
1701 );
1702  
1703 38 ▶ $transaction->_enable_datagrams if $datagrams;
Branch: 1 branch
BranchTrueFalseTotal
if $datagrams 3 35 38
1704  
1705 38 ▶ if ($receive_body eq 'stream' && defined $callbacks{on_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($receive_body eq "stream" and defined $callbacks{"on_body"}) 1 37 38
Condition100%3/3
$receive_body eq "stream" and defined $callbacks{"on_body"}
!ll&&!rl&&r
27101
MC/DC100%2/2
$receive_body eq "stream" and defined $callbacks{"on_body"}
$receive_body eq "stream" defined $callbacks{"on_body"}
Truth table100%3/3
A and B
A= $receive_body eq "stream"B= defined $callbacks{"on_body"}
ABresult
0X0
100
111
1706 croak 'request(): on_body cannot be combined with receive_body on_data'
1707 1 ▶ if exists $receive_options->{on_data};
Branch: 1 branch
BranchTrueFalseTotal
if exists $receive_options->{"on_data"} 0 1 1
1708  
1709 1 my %common_receive = %$receive_options;
1710 2 ▶ $common_receive{on_data} = sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
1711 2 my ($reader, $bytes) = @_;
1712 2 my $response = $transaction->response;
1713 2 my $result = $transaction->_invoke(
1714 'on_body',
1715 $response,
1716 $bytes,
1717 );
1718 2 ▶ die $result unless $result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 0 2 2
1719 1 };
1720 1 $receive_options = \%common_receive;
1721 }
1722  
1723 $transaction->_configure_receive_body(
1724 38 'response',
1725 $receive_body,
1726 $receive_options,
1727 );
1728  
1729 38 ▶ $transaction->on_data($on_data) if $on_data;
Branch: 1 branch
BranchTrueFalseTotal
if $on_data 2 36 38
1730 38 $self->{transactions}{$stream_id} = $transaction;
1731  
1732 38 ▶ if ($stream_body && defined $callbacks{on_drain}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream_body and defined $callbacks{"on_drain"}) 0 38 38
Condition66%2/3
$stream_body and defined $callbacks{"on_drain"}
!ll&&!rl&&r
23150
MC/DC0%0/2
$stream_body and defined $callbacks{"on_drain"}
$stream_body defined $callbacks{"on_drain"}
Truth table66%2/3
A and B
A= $stream_bodyB= defined $callbacks{"on_drain"}
ABresult
0X0
100
111
1733 $transaction->request_body(
1734 0 ▶ on_drain => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1735 0 my ($body) = @_;
1736 0 my $result = $transaction->_invoke('on_drain');
1737 0 ▶ die $result unless $result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 0 0 0
1738 },
1739 0 );
1740 }
1741  
1742 38 $self->_maybe_complete_transaction($stream_id);
1743  
1744 38 return $transaction;
1745 }
1746  
1747 # Callback consumers already own their transaction. Weak queue slots
1748 # preserve prompt mixed callback/pull reads without pinning every completed
1749 # request and response for the life of a multiplexed connection. Pure pull
1750 # entries remain strong, so an application may retrieve them later.
1751 1360 ▶sub _enqueue_delivery {
Subroutine _enqueue_delivery: called CC=9 SCAR=22.0
1752 1360 my ($self, $queue_name, $transaction, $callback_owned) = @_;
1753  
1754 1360 my $queue = $self->{$queue_name};
1755 1360 ▶ shift @$queue while @$queue && !defined $queue->[0];
Branch: 1 branch
BranchTrueFalseTotal
@$queue and not defined $queue->[0] and do { shift @$queue } 127 1360 1487
Condition100%3/3
@$queue and not defined $queue->[0]
!ll&&!rl&&r
1731187127
MC/DC100%2/2
@$queue and not defined $queue->[0]
@$queue not defined $queue->[0]
Truth table100%3/3
A and not(B)
A= @$queueB= not defined $queue->[0]
ABresult
0X0
100
111
1756 1360 push @$queue, $transaction;
1757 1360 ▶ if ($callback_owned) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callback_owned) 1327 33 1360
1758 1327 weaken($queue->[-1]);
1759 # A live old entry can keep the head from advancing while expired
1760 # weak notifications accumulate behind it. Periodic compaction
1761 # bounds that stale tail without scanning on every request. Strong
1762 # pull-only entries must remain queued until explicitly retrieved.
1763 1327 ▶ if (++$self->{weak_delivery_insertions}{$queue_name} >= 64) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$self->{"weak_delivery_insertions"}{$queue_name} >= 64) 20 1307 1327
1764 # Copying an SV with grep/map turns a weak reference strong.
1765 # Compact in place and restore the weakness of moved entries.
1766 20 my $write = 0;
1767 20 for my $read (0 .. $#$queue) {
1768 1189 ▶ next unless defined $queue->[$read];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $queue->[$read] 1139 50 1189
1769 50 ▶ if ($write != $read) {
Branch: 1 branch
BranchTrueFalseTotal
if ($write != $read) 20 30 50
1770 20 my $was_weak = isweak($queue->[$read]);
1771 20 $queue->[$write] = $queue->[$read];
1772 20 ▶ weaken($queue->[$write]) if $was_weak;
Branch: 1 branch
BranchTrueFalseTotal
if $was_weak 19 1 20
1773 }
1774 50 ++$write;
1775 }
1776 20 splice @$queue, $write;
1777 20 $self->{weak_delivery_insertions}{$queue_name} = 0;
1778 }
1779 }
1780 1360 return;
1781 }
1782  
1783 122 ▶sub _next_delivery {
Subroutine _next_delivery: called CC=3 SCAR=11.0
1784 122 my ($self, $queue_name) = @_;
1785 122 my $queue = $self->{$queue_name};
1786 122 ▶ shift @$queue while @$queue && !defined $queue->[0];
Branch: 1 branch
BranchTrueFalseTotal
@$queue and not defined $queue->[0] and do { shift @$queue } 17 122 139
Condition100%3/3
@$queue and not defined $queue->[0]
!ll&&!rl&&r
843817
MC/DC100%2/2
@$queue and not defined $queue->[0]
@$queue not defined $queue->[0]
Truth table100%3/3
A and not(B)
A= @$queueB= not defined $queue->[0]
ABresult
0X0
100
111
1787 122 return shift @$queue;
1788 }
1789  
1790 115 ▶sub next_transaction {
Subroutine next_transaction: called CC=4 SCAR=14.1
Pod undocumented
1791 115 my ($self, @args) = @_;
1792  
1793 115 ▶ croak 'next_transaction() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 115 115
1794 115 ▶ $self->_service if $self->{started} && !$self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"started"} and not $self->{"failed"} 104 11 115
Condition66%2/3
$self->{"started"} and not $self->{"failed"}
!ll&&!rl&&r
110104
MC/DC50%1/2
$self->{"started"} and not $self->{"failed"}
$self->{"started"} not $self->{"failed"}
Truth table66%2/3
A and not(B)
A= $self->{"started"}B= not $self->{"failed"}
ABresult
0X0
100
111
1795 115 return $self->_next_delivery('ready_transactions');
1796 }
1797  
1798 7 ▶sub next_informational {
Subroutine next_informational: called CC=4 SCAR=14.1
Pod undocumented
1799 7 my ($self, @args) = @_;
1800  
1801 7 ▶ croak 'next_informational() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 7 7
1802 7 ▶ $self->_service if $self->{started} && !$self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"started"} and not $self->{"failed"} 3 4 7
Condition66%2/3
$self->{"started"} and not $self->{"failed"}
!ll&&!rl&&r
403
MC/DC50%1/2
$self->{"started"} and not $self->{"failed"}
$self->{"started"} not $self->{"failed"}
Truth table66%2/3
A and not(B)
A= $self->{"started"}B= not $self->{"failed"}
ABresult
0X0
100
111
1803 7 return $self->_next_delivery('ready_informational');
1804 }
1805  
1806 89 ▶sub _request_contract {
Subroutine _request_contract: called CC=4 SCAR=14.3
1807 89 my ($request) = @_;
1808 89 ▶ return unless blessed($request);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($request) 0 89 89
1809  
1810 89 for my $method (qw(
1811 method target scheme authority protocol version
1812 header_count header_name header_value
1813 trailer_count trailer_name trailer_value
1814 has_buffered_body body
1815 )) {
1816 1246 ▶ return unless $request->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $request->can($method) 0 1246 1246
1817 }
1818  
1819 89 return 1;
1820 }
1821  
1822 67 ▶sub _response_contract {
Subroutine _response_contract: called CC=4 SCAR=14.3
1823 67 my ($response) = @_;
1824 67 ▶ return unless blessed($response);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($response) 0 67 67
1825  
1826 67 for my $method (qw(
1827 status version
1828 header_count header_name header_value
1829 trailer_count trailer_name trailer_value
1830 has_buffered_body body
1831 )) {
1832 670 ▶ return unless $response->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $response->can($method) 0 670 670
1833 }
1834  
1835 67 return 1;
1836 }
1837  
1838 187 ▶sub _message_header_values {
Subroutine _message_header_values: called CC=3 SCAR=11.0
1839 187 my ($message, $wanted) = @_;
1840  
1841 187 $wanted = lc $wanted;
1842 187 my @values;
1843  
1844 187 for my $index (0 .. $message->header_count - 1) {
1845 70 my $name = lc $message->header_name($index);
1846 70 ▶ push @values, $message->header_value($index)
Branch: 1 branch
BranchTrueFalseTotal
if $name eq $wanted 16 54 70
1847 if $name eq $wanted;
1848 }
1849  
1850 187 return \@values;
1851 }
1852  
1853 2 ▶sub _portable_headers {
Subroutine _portable_headers: called CC=2 SCAR=9.2
1854 2 my ($message, $context) = @_;
1855 2 my @fields;
1856  
1857 2 for my $index (0 .. $message->header_count - 1) {
1858 0 my $name = lc $message->header_name($index);
1859 0 my $value = $message->header_value($index);
1860 0 _validate_wire_field($context, $name, $value);
1861 0 push @fields, [ $name, $value ];
1862 }
1863  
1864 2 return \@fields;
1865 }
1866  
1867 0 ▶sub _portable_trailers {
Subroutine _portable_trailers: not called CC=2 SCAR=17.9
1868 0 my ($message) = @_;
1869 0 my @fields;
1870  
1871 0 for my $index (0 .. $message->trailer_count - 1) {
1872 0 my $name = lc $message->trailer_name($index);
1873 0 my $value = $message->trailer_value($index);
1874 0 push @fields, @{ _wire_trailers([ [ $name, $value ] ]) };
1875 }
1876  
1877 0 return \@fields;
1878 }
1879  
1880 1 ▶sub _portable_request_fields {
Subroutine _portable_request_fields: called CC=4 SCAR=14.7
1881 1 my ($request) = @_;
1882  
1883 1 my @fields = ([ ':method', $request->method ]);
1884 1 my $method = $request->method;
1885 1 my $protocol = $request->protocol;
1886  
1887 1 ▶ if ($method eq 'CONNECT' && !defined $protocol) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq 'CONNECT' and not defined $protocol) { } 0 1 1
Condition33%1/3
$method eq "CONNECT" and not defined $protocol
!ll&&!rl&&r
100
MC/DC0%0/2
$method eq "CONNECT" and not defined $protocol
$method eq "CONNECT" not defined $protocol
Truth table33%1/3
A and not(B)
A= $method eq "CONNECT"B= not defined $protocol
ABresult
0X0
100
111
1888 0 push @fields, [ ':authority', $request->authority ];
1889 } else {
1890 1 ▶ push @fields, [ ':protocol', $protocol ]
Branch: 1 branch
BranchTrueFalseTotal
if defined $protocol 0 1 1
1891 if defined $protocol;
1892 1 push @fields,
1893 [ ':scheme', $request->scheme ],
1894 [ ':authority', $request->authority ],
1895 [ ':path', $request->target ];
1896 }
1897  
1898 1 push @fields, @{ _portable_headers($request, 'request') };
1899 1 return \@fields;
1900 }
1901  
1902 1 ▶sub _portable_response_fields {
Subroutine _portable_response_fields: called CC=1 SCAR=0.0
1903 1 my ($response) = @_;
1904  
1905 1 my @fields = ([ ':status', '' . $response->status ]);
1906 1 push @fields, @{ _portable_headers($response, 'response') };
1907 1 return \@fields;
1908 }
1909  
1910 36 ▶sub _assert_response_contract {
Subroutine _assert_response_contract: called CC=2 SCAR=7.1
1911 36 my ($self, $response, $operation) = @_;
1912 36 ▶ croak "$operation: requires the Uniform HTTP response contract"
Branch: 1 branch
BranchTrueFalseTotal
unless _response_contract($response) 0 36 36
1913 unless _response_contract($response);
1914 36 return $response;
1915 }
1916  
1917 82 ▶sub _assert_http3_version {
Subroutine _assert_http3_version: called CC=3 SCAR=11.0
1918 82 my ($message, $operation) = @_;
1919  
1920 82 my $version = $message->version;
1921 82 ▶ return unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 64 18 82
1922  
1923 18 ▶ croak "$operation: explicit message version must be 3 for HTTP/3"
Branch: 1 branch
BranchTrueFalseTotal
unless "$version" eq 3 1 17 18
1924 unless "$version" eq '3';
1925  
1926 17 return;
1927 }
1928  
1929 118 ▶sub _declared_content_length {
Subroutine _declared_content_length: called CC=4 SCAR=13.9
1930 118 my ($message, $operation) = @_;
1931  
1932 118 my $values = _message_header_values($message, 'content-length');
1933 118 ▶ return unless @$values;
Branch: 1 branch
BranchTrueFalseTotal
unless @$values 103 15 118
1934  
1935 15 ▶ croak "$operation: multiple Content-Length fields are not allowed"
Branch: 1 branch
BranchTrueFalseTotal
unless @$values == 1 1 14 15
1936 unless @$values == 1;
1937  
1938 14 my $value = $values->[0];
1939  
1940 14 ▶ croak "$operation: Content-Length must be a decimal non-negative integer"
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /\A[0-9]+\z/ 3 11 14
1941 unless $value =~ /\A[0-9]+\z/;
1942  
1943 11 $value =~ s/\A0+(?=[0-9])//;
1944  
1945 11 return $value;
1946 }
1947  
1948 3 ▶sub _content_length_matches {
Subroutine _content_length_matches: called CC=2 SCAR=7.2
1949 3 my ($declared, $actual) = @_;
1950 3 ▶ return $declared eq "$actual" ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$declared eq "$actual" ? : 0 3 3
1951 }
1952  
1953 3 ▶sub _content_length_is_less_than {
Subroutine _content_length_is_less_than: called CC=4 SCAR=14.1
1954 3 my ($declared, $actual) = @_;
1955  
1956 3 my $actual_text = "$actual";
1957  
1958 3 ▶ return 1 if length($declared) < length($actual_text);
Branch: 1 branch
BranchTrueFalseTotal
if length $declared < length $actual_text 0 3 3
1959 3 ▶ return 0 if length($declared) > length($actual_text);
Branch: 1 branch
BranchTrueFalseTotal
if length $declared > length $actual_text 0 3 3
1960  
1961 3 ▶ return $declared lt $actual_text ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$declared lt $actual_text ? : 1 2 3
1962 }
1963  
1964 68 ▶sub _assert_request_content_length {
Subroutine _assert_request_content_length: called CC=7 SCAR=20.8
1965 68 my ($self, $request, $operation, $streaming) = @_;
1966  
1967 68 my $declared = _declared_content_length($request, $operation);
1968 64 ▶ return unless defined $declared;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $declared 62 2 64
1969  
1970 2 ▶ if ($request->method eq 'CONNECT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->method eq "CONNECT") 1 1 2
1971 1 ▶ croak "$operation: CONNECT request Content-Length must be 0"
Branch: 1 branch
BranchTrueFalseTotal
unless $declared eq 0 1 0 1
1972 unless $declared eq '0';
1973 0 return $declared;
1974 }
1975  
1976 1 ▶ return $declared if $streaming;
Branch: 1 branch
BranchTrueFalseTotal
if $streaming 0 1 1
1977  
1978 1 ▶ my $actual = $request->has_buffered_body
Branch: 1 branch
BranchTrueFalseTotal
$request->has_buffered_body ? : 1 0 1
1979 ? length($request->body)
1980 : 0;
1981  
1982 1 ▶ croak "$operation: Content-Length $declared does not match $actual body bytes"
Branch: 1 branch
BranchTrueFalseTotal
unless _content_length_matches($declared, $actual) 1 0 1
1983 unless _content_length_matches($declared, $actual);
1984  
1985 0 return $declared;
1986 }
1987  
1988 50 ▶sub _assert_response_content_length {
Subroutine _assert_response_content_length: called CC=15 SCAR=28.4
1989 50 my ($self, $transaction, $response, $operation) = @_;
1990  
1991 50 my $declared = _declared_content_length($response, $operation);
1992 50 ▶ return unless defined $declared;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $declared 41 9 50
1993  
1994 9 my $method = $transaction->request->method;
1995 9 my $status = $response->status;
1996  
1997 9 ▶ croak "$operation: Content-Length is not allowed on informational responses"
Branch: 1 branch
BranchTrueFalseTotal
if $status >= 100 and $status < 200 0 9 9
Condition33%1/3
$status >= 100 and $status < 200
!ll&&!rl&&r
090
MC/DC0%0/2
$status >= 100 and $status < 200
$status >= 100 $status < 200
Truth table33%1/3
A and B
A= $status >= 100B= $status < 200
ABresult
0X0
100
111
1998 if $status >= 100 && $status < 200;
1999 9 ▶ croak "$operation: Content-Length is not allowed on a 204 response"
Branch: 1 branch
BranchTrueFalseTotal
if $status == 204 1 8 9
2000 if $status == 204;
2001 8 ▶ croak "$operation: Content-Length is not allowed on a successful CONNECT response"
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "CONNECT" and $status >= 200 and $status < 300 1 7 8
Condition66%4/6
$method eq "CONNECT" and $status >= 200 and $status < 300
!ll&&!rl&&r
701
$method eq "CONNECT" and $status >= 200
!ll&&!rl&&r
701
MC/DC33%1/3
$method eq "CONNECT" and $status >= 200 and $status < 300
$method eq "CONNECT" $status >= 200 $status < 300
Truth table50%2/4
A and B and C
A= $method eq "CONNECT"B= $status >= 200C= $status < 300
ABCresult
0XX0
10X0
1100
1111
2002 if $method eq 'CONNECT' && $status >= 200 && $status < 300;
2003  
2004 7 ▶ return $declared
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "HEAD" or $status == 304 2 5 7
Condition100%3/3
$method eq "HEAD" or $status == 304
l!l&&r!l&&!r
115
MC/DC100%2/2
$method eq "HEAD" or $status == 304
$method eq "HEAD" $status == 304
Truth table100%3/3
A or B
A= $method eq "HEAD"B= $status == 304
ABresult
1X1
011
000
2005 if $method eq 'HEAD' || $status == 304;
2006  
2007 5 ▶ if ($status == 205) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status == 205) 1 4 5
2008 1 ▶ croak "$operation: Content-Length on a 205 response must be 0"
Branch: 1 branch
BranchTrueFalseTotal
unless $declared eq 0 1 0 1
2009 unless $declared eq '0';
2010 0 return $declared;
2011 }
2012  
2013 4 ▶ return $declared if $transaction->_response_is_streaming;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->_response_is_streaming 3 1 4
2014  
2015 1 ▶ my $actual = $response->has_buffered_body
Branch: 1 branch
BranchTrueFalseTotal
$response->has_buffered_body ? : 1 0 1
2016 ? length($response->body)
2017 : 0;
2018  
2019 1 ▶ croak "$operation: Content-Length $declared does not match $actual body bytes"
Branch: 1 branch
BranchTrueFalseTotal
unless _content_length_matches($declared, $actual) 1 0 1
2020 unless _content_length_matches($declared, $actual);
2021  
2022 0 return $declared;
2023 }
2024  
2025 43 ▶sub _assert_incremental_content_length {
Subroutine _assert_incremental_content_length: called CC=13 SCAR=26.0
2026 43 my ($self, $transaction, $kind, $message, $bytes, $final, $operation) = @_;
2027  
2028 43 my $declared;
2029  
2030 43 ▶ if ($kind eq 'request') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq 'request') { } 23 20 43
2031 23 $declared = $self->_assert_request_content_length(
2032 $message,
2033 $operation,
2034 );
2035  
2036 23 ▶ return if $message->method eq 'CONNECT';
Branch: 1 branch
BranchTrueFalseTotal
if $message->method eq "CONNECT" 12 11 23
2037 } else {
2038 20 $declared = $self->_assert_response_content_length(
2039 $transaction,
2040 $message,
2041 $operation,
2042 );
2043  
2044 20 my $status = $message->status;
2045 return
2046 20 ▶ if $transaction->request->method eq 'HEAD'
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->request->method eq "HEAD" or $status == 304 or $transaction->request->method eq "CONNECT" and $status >= 200 and $status < 300 10 10 20
Condition58%7/12
$transaction->request->method eq "HEAD" or $status == 304 or $transaction->request->method eq "CONNECT" and $status >= 200 and $status < 300
l!l&&r!l&&!r
01010
$transaction->request->method eq "HEAD" or $status == 304
l!l&&r!l&&!r
0020
$transaction->request->method eq "CONNECT" and $status >= 200 and $status < 300
!ll&&!rl&&r
10010
$transaction->request->method eq "CONNECT" and $status >= 200
!ll&&!rl&&r
10010
MC/DC20%1/5
$transaction->request->method eq "HEAD" or $status == 304 or $transaction->request->method eq "CONNECT" and $status >= 200 and $status < 300
$transaction->request->method eq "HEAD" $status == 304 $transaction->request->method eq "CONNECT" $status >= 200 $status < 300
Truth table33%2/6
A or B or C and D and E
A= $transaction->request->method eq "HEAD"B= $status == 304C= $transaction->request->method eq "CONNECT"D= $status >= 200E= $status < 300
ABCDEresult
1XXXX1
01XXX1
001111
000XX0
0010X0
001100
2047 || $status == 304
2048 || ($transaction->request->method eq 'CONNECT'
2049 && $status >= 200 && $status < 300);
2050 }
2051  
2052 21 ▶ return unless defined $declared;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $declared 18 3 21
2053  
2054 3 my $id = $transaction->stream_id;
2055 3 ▶ my $sent = $self->{body_bytes_sent}{$id}{$kind} // 0;
Condition100%2/2
$self->{"body_bytes_sent"}{$id}{$kind} // 0
l!l
12
MC/DC100%1/1
$self->{"body_bytes_sent"}{$id}{$kind} // 0
$self->{"body_bytes_sent"}{$id}{$kind}
Truth table100%2/2
A
A= $self->{"body_bytes_sent"}{$id}{$kind}
Aresult
11
00
2056 3 my $next = $sent + length($bytes);
2057  
2058 3 ▶ croak "$operation: body exceeds Content-Length $declared"
Branch: 1 branch
BranchTrueFalseTotal
if _content_length_is_less_than($declared, $next) 1 2 3
2059 if _content_length_is_less_than($declared, $next);
2060  
2061 2 ▶ if ($final) {
Branch: 1 branch
BranchTrueFalseTotal
if ($final) 1 1 2
2062 1 ▶ croak "$operation: Content-Length $declared does not match $next body bytes"
Branch: 1 branch
BranchTrueFalseTotal
unless _content_length_matches($declared, $next) 1 0 1
2063 unless _content_length_matches($declared, $next);
2064 }
2065  
2066 1 $self->{body_bytes_sent}{$id}{$kind} = $next;
2067 1 return;
2068 }
2069  
2070 2 ▶sub _send_informational_response {
Subroutine _send_informational_response: called CC=11 SCAR=30.2
2071 2 my ($self, $transaction, $response) = @_;
2072  
2073 croak 'informational responses require a server HTTP/3 connection'
2074 2 ▶ unless $self->{role} eq 'server';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "server" 0 2 2
2075 croak 'Transaction does not belong to this HTTP/3 connection'
2076 unless blessed($transaction)
2077 && $transaction->isa('Unblock::HTTP3::Transaction')
2078 && defined($self->{transactions}{ $transaction->stream_id })
2079 2 ▶ && $self->{transactions}{ $transaction->stream_id } == $transaction;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction 0 2 2
Condition33%3/9
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
!ll&&!rl&&r
002
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id}
!ll&&!rl&&r
002
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction")
!ll&&!rl&&r
002
MC/DC0%0/4
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
builtin::blessed($transaction) $transaction->isa("Unblock::HTTP3::Transaction") defined $self->{"transactions"}{$transaction->stream_id} $self->{"transactions"}{$transaction->stream_id} == $transaction
Truth table20%1/5
A and B and C and D
A= builtin::blessed($transaction)B= $transaction->isa("Unblock::HTTP3::Transaction")C= defined $self->{"transactions"}{$transaction->stream_id}D= $self->{"transactions"}{$transaction->stream_id} == $transaction
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2080 croak 'final response has already started'
2081 2 ▶ if $self->{response_sent}{ $transaction->stream_id };
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"response_sent"}{$transaction->stream_id} 0 2 2
2082 2 _assert_http3_version($response, 'send_informational()');
2083  
2084 2 ▶ croak 'informational response status must be 100 through 199, excluding 101'
Branch: 1 branch
BranchTrueFalseTotal
unless $response->status >= 100 and $response->status <= 199 and $response->status != 101 0 2 2
Condition33%2/6
$response->status >= 100 and $response->status <= 199 and $response->status != 101
!ll&&!rl&&r
002
$response->status >= 100 and $response->status <= 199
!ll&&!rl&&r
002
MC/DC0%0/3
$response->status >= 100 and $response->status <= 199 and $response->status != 101
$response->status >= 100 $response->status <= 199 $response->status != 101
Truth table25%1/4
A and B and C
A= $response->status >= 100B= $response->status <= 199C= $response->status != 101
ABCresult
0XX0
10X0
1100
1111
2085 unless $response->status >= 100
2086 && $response->status <= 199
2087 && $response->status != 101;
2088  
2089 2 $self->_assert_response_content_length(
2090 $transaction,
2091 $response,
2092 'send_informational()',
2093 );
2094 2 _assert_capsule_protocol_response(
2095 $response,
2096 'send_informational()',
2097 );
2098  
2099 2 ▶ if (ref($response) eq 'Uniform::HTTP::Response') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $response eq 'Uniform::HTTP::Response') { } 2 0 2
2100 $self->_assert_peer_field_section_size_value(
2101 2 $self->{native}->uniform_response_field_section_size($response),
2102 'send_informational()',
2103 );
2104  
2105 $self->{native}->submit_uniform_info(
2106 2 $transaction->stream_id,
2107 $response,
2108 );
2109  
2110 2 $response->freeze;
2111 } else {
2112 0 my $fields = _portable_response_fields($response);
2113  
2114 0 $self->_assert_peer_field_section_size_value(
2115 _field_section_size($fields),
2116 'send_informational()',
2117 );
2118  
2119 $self->{native}->submit_info(
2120 0 $transaction->stream_id,
2121 $fields,
2122 );
2123 }
2124  
2125 2 $self->_drain_output;
2126 2 return $response;
2127 }
2128  
2129 3 ▶sub _capsule_protocol_response_error {
Subroutine _capsule_protocol_response_error: called CC=6 SCAR=17.9
2130 3 my ($status, $headers) = @_;
2131  
2132 3 my $present = 0;
2133  
2134 3 for my $field (@$headers) {
2135 3 my $name = lc($field->[0]);
2136 3 ▶ if ($name eq 'capsule-protocol') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "capsule-protocol") 2 1 3
2137 2 $present = 1;
2138 2 last;
2139 }
2140 }
2141  
2142 3 ▶ return unless $present;
Branch: 1 branch
BranchTrueFalseTotal
unless $present 1 2 3
2143 2 ▶ return if $status >= 200 && $status < 300;
Branch: 1 branch
BranchTrueFalseTotal
if $status >= 200 and $status < 300 1 1 2
Condition66%2/3
$status >= 200 and $status < 300
!ll&&!rl&&r
011
MC/DC50%1/2
$status >= 200 and $status < 300
$status >= 200 $status < 300
Truth table66%2/3
A and B
A= $status >= 200B= $status < 300
ABresult
0X0
100
111
2144  
2145 1 return 'Capsule-Protocol is only valid on a successful HTTP/3 response';
2146 }
2147  
2148 24 ▶sub _assert_capsule_protocol_response {
Subroutine _assert_capsule_protocol_response: called CC=4 SCAR=21.7
2149 24 my ($response, $operation) = @_;
2150  
2151 24 my $values = _message_header_values($response, 'capsule-protocol');
2152 24 ▶ return unless @$values;
Branch: 1 branch
BranchTrueFalseTotal
unless @$values 24 0 24
2153 0 ▶ return if $response->status >= 200 && $response->status < 300;
Branch: 1 branch
BranchTrueFalseTotal
if $response->status >= 200 and $response->status < 300 0 0 0
Condition0%0/3
$response->status >= 200 and $response->status < 300
!ll&&!rl&&r
000
MC/DC0%0/2
$response->status >= 200 and $response->status < 300
$response->status >= 200 $response->status < 300
Truth table0%0/3
A and B
A= $response->status >= 200B= $response->status < 300
ABresult
0X0
100
111
2154  
2155 0 croak "$operation: Capsule-Protocol is only valid on a successful HTTP/3 response";
2156 }
2157  
2158 61 ▶sub _response_content_forbidden_reason {
Subroutine _response_content_forbidden_reason: called CC=5 SCAR=16.1
2159 61 my ($self, $transaction, $response) = @_;
2160  
2161 61 my $method = $transaction->request->method;
2162 61 my $status = $response->status;
2163  
2164 61 ▶ return 'response to HEAD must not contain content'
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "HEAD" 3 58 61
2165 if $method eq 'HEAD';
2166 58 ▶ return '204 response must not contain content'
Branch: 1 branch
BranchTrueFalseTotal
if $status == 204 7 51 58
2167 if $status == 204;
2168 51 ▶ return '205 response must not contain content'
Branch: 1 branch
BranchTrueFalseTotal
if $status == 205 2 49 51
2169 if $status == 205;
2170 49 ▶ return '304 response must not contain content'
Branch: 1 branch
BranchTrueFalseTotal
if $status == 304 2 47 49
2171 if $status == 304;
2172  
2173 47 return;
2174 }
2175  
2176 31 ▶sub _assert_response_body_allowed {
Subroutine _assert_response_body_allowed: called CC=2 SCAR=6.9
2177 31 my ($self, $transaction, $response, $operation) = @_;
2178  
2179 31 my $reason = $self->_response_content_forbidden_reason(
2180 $transaction,
2181 $response,
2182 );
2183  
2184 31 ▶ croak "$operation: $reason"
Branch: 1 branch
BranchTrueFalseTotal
if defined $reason 4 27 31
2185 if defined $reason;
2186  
2187 27 return;
2188 }
2189  
2190 30 ▶sub _assert_response_message_allowed {
Subroutine _assert_response_message_allowed: called CC=5 SCAR=16.1
2191 30 my ($self, $transaction, $response, $operation) = @_;
2192  
2193 30 my $reason = $self->_response_content_forbidden_reason(
2194 $transaction,
2195 $response,
2196 );
2197  
2198 30 ▶ return unless defined $reason;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $reason 20 10 30
2199  
2200 10 ▶ croak "$operation: $reason"
Branch: 1 branch
BranchTrueFalseTotal
if $response->has_buffered_body or $transaction->_response_is_streaming or $response->trailer_count 5 5 10
Condition83%5/6
$response->has_buffered_body or $transaction->_response_is_streaming or $response->trailer_count
l!l&&r!l&&!r
415
$response->has_buffered_body or $transaction->_response_is_streaming
l!l&&r!l&&!r
406
MC/DC66%2/3
$response->has_buffered_body or $transaction->_response_is_streaming or $response->trailer_count
$response->has_buffered_body $transaction->_response_is_streaming $response->trailer_count
Truth table75%3/4
A or B or C
A= $response->has_buffered_bodyB= $transaction->_response_is_streamingC= $response->trailer_count
ABCresult
1XX1
01X1
0011
0000
2201 if $response->has_buffered_body
2202 || $transaction->_response_is_streaming
2203 || $response->trailer_count;
2204  
2205 5 return;
2206 }
2207  
2208 31 ▶sub _respond_transaction {
Subroutine _respond_transaction: called CC=26 SCAR=39.9
2209 31 my ($self, $transaction, $response, %option) = @_;
2210  
2211 croak 'respond() requires a server HTTP/3 connection'
2212 31 ▶ unless $self->{role} eq 'server';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "server" 0 31 31
2213 croak 'Transaction does not belong to this HTTP/3 connection'
2214 unless blessed($transaction)
2215 && $transaction->isa('Unblock::HTTP3::Transaction')
2216 && defined($self->{transactions}{ $transaction->stream_id })
2217 31 ▶ && $self->{transactions}{ $transaction->stream_id } == $transaction;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction 0 31 31
Condition33%3/9
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
!ll&&!rl&&r
0031
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id}
!ll&&!rl&&r
0031
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction")
!ll&&!rl&&r
0031
MC/DC0%0/4
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
builtin::blessed($transaction) $transaction->isa("Unblock::HTTP3::Transaction") defined $self->{"transactions"}{$transaction->stream_id} $self->{"transactions"}{$transaction->stream_id} == $transaction
Truth table20%1/5
A and B and C and D
A= builtin::blessed($transaction)B= $transaction->isa("Unblock::HTTP3::Transaction")C= defined $self->{"transactions"}{$transaction->stream_id}D= $self->{"transactions"}{$transaction->stream_id} == $transaction
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2218 croak 'response has already been sent for this Transaction'
2219 31 ▶ if $self->{response_sent}{ $transaction->stream_id };
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"response_sent"}{$transaction->stream_id} 0 31 31
2220  
2221 31 $self->_assert_response_contract(
2222 $response,
2223 'respond()',
2224 );
2225  
2226 my $stream_body = exists($option{stream_body})
2227 ? delete($option{stream_body})
2228 31 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'stream_body'} ? : 2 29 31
2229 31 ▶ 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/ 1 30 31
Condition66%4/6
not defined $stream_body or ref $stream_body or not "$stream_body" =~ /\A[01]\z/
l!l&&r!l&&!r
1030
not defined $stream_body or ref $stream_body
l!l&&r!l&&!r
0130
MC/DC33%1/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 table50%2/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
2230 if !defined($stream_body)
2231 || ref($stream_body)
2232 || "$stream_body" !~ /\A[01]\z/;
2233 30 ▶ $stream_body = $stream_body ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$stream_body ? : 1 29 30
2234  
2235 30 my $on_drain = delete $option{on_drain};
2236 30 my $on_error = delete $option{on_error};
2237  
2238 30 ▶ croak 'respond(): on_drain must be a coderef'
Branch: 1 branch
BranchTrueFalseTotal
if defined $on_drain and ref $on_drain ne "CODE" 0 30 30
Condition33%1/3
defined $on_drain and ref $on_drain ne "CODE"
!ll&&!rl&&r
3000
MC/DC0%0/2
defined $on_drain and ref $on_drain ne "CODE"
defined $on_drain ref $on_drain ne "CODE"
Truth table33%1/3
A and B
A= defined $on_drainB= ref $on_drain ne "CODE"
ABresult
0X0
100
111
2239 if defined($on_drain) && ref($on_drain) ne 'CODE';
2240 30 ▶ croak 'respond(): on_error must be a coderef'
Branch: 1 branch
BranchTrueFalseTotal
if defined $on_error and ref $on_error ne "CODE" 0 30 30
Condition33%1/3
defined $on_error and ref $on_error ne "CODE"
!ll&&!rl&&r
3000
MC/DC0%0/2
defined $on_error and ref $on_error ne "CODE"
defined $on_error ref $on_error ne "CODE"
Truth table33%1/3
A and B
A= defined $on_errorB= ref $on_error ne "CODE"
ABresult
0X0
100
111
2241 if defined($on_error) && ref($on_error) ne 'CODE';
2242 30 ▶ croak 'respond(): unknown options: ' . join(', ', sort keys %option)
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 30 30
2243 if %option;
2244 30 ▶ croak 'respond(): on_drain requires stream_body'
Branch: 1 branch
BranchTrueFalseTotal
if $on_drain and not $stream_body 0 30 30
Condition33%1/3
$on_drain and not $stream_body
!ll&&!rl&&r
3000
MC/DC0%0/2
$on_drain and not $stream_body
$on_drain not $stream_body
Truth table33%1/3
A and not(B)
A= $on_drainB= not $stream_body
ABresult
0X0
100
111
2245 if $on_drain && !$stream_body;
2246 30 ▶ croak 'respond(): stream_body cannot be combined with a buffered body'
Branch: 1 branch
BranchTrueFalseTotal
if $stream_body and $response->has_buffered_body 0 30 30
Condition66%2/3
$stream_body and $response->has_buffered_body
!ll&&!rl&&r
2910
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
2247 if $stream_body && $response->has_buffered_body;
2248  
2249 30 $transaction->{response} = $response;
2250 30 $transaction->{response_body} = undef;
2251 30 $transaction->{response_streaming} = 0;
2252  
2253 30 ▶ if ($stream_body) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream_body) 1 29 30
2254 1 my %stream_option;
2255  
2256 1 ▶ if ($on_drain) {
Branch: 1 branch
BranchTrueFalseTotal
if ($on_drain) 0 1 1
2257 0 $transaction->_set_callback('on_drain', $on_drain);
2258 0 ▶ $stream_option{on_drain} = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
2259 0 my ($body) = @_;
2260 0 my $result = $transaction->_invoke('on_drain');
2261 0 ▶ die $result unless $result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 0 0 0
2262 0 };
2263 }
2264  
2265 1 $transaction->response_body(%stream_option);
2266 }
2267  
2268 30 ▶ $transaction->_set_callback('on_error', $on_error)
Branch: 1 branch
BranchTrueFalseTotal
if $on_error 0 30 30
2269 if $on_error;
2270  
2271 30 _assert_http3_version($response, 'respond()');
2272  
2273 30 $self->_assert_response_message_allowed(
2274 $transaction,
2275 $response,
2276 'respond()',
2277 );
2278 25 $self->_assert_response_content_length(
2279 $transaction,
2280 $response,
2281 'respond()',
2282 );
2283 22 _assert_capsule_protocol_response(
2284 $response,
2285 'respond()',
2286 );
2287  
2288 22 ▶ croak 'final response status must be 200 through 599'
Branch: 1 branch
BranchTrueFalseTotal
if $response->status < 200 0 22 22
2289 if $response->status < 200;
2290  
2291 22 $self->{response_sent}{ $transaction->stream_id } = 1;
2292  
2293 22 my $ok = eval {
2294 22 $self->_submit_response(
2295 $transaction->stream_id,
2296 $response,
2297 );
2298 22 1;
2299 };
2300  
2301 22 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 22 22
2302 0 delete $self->{response_sent}{ $transaction->stream_id };
2303 0 die $@;
2304 }
2305  
2306 22 $transaction->_mark_response_started;
2307 22 $self->_maybe_complete_transaction($transaction->stream_id);
2308 22 return $transaction;
2309 }
2310  
2311 4 ▶sub _write_stream_body {
Subroutine _write_stream_body: called CC=11 SCAR=27.6
2312 4 my ($self, $transaction, $bytes, $final, $operation) = @_;
2313  
2314 croak "$operation(): Transaction does not belong to this HTTP/3 connection"
2315 unless blessed($transaction)
2316 && $transaction->isa('Unblock::HTTP3::Transaction')
2317 && defined($self->{transactions}{ $transaction->stream_id })
2318 4 ▶ && $self->{transactions}{ $transaction->stream_id } == $transaction;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction 0 4 4
Condition33%3/9
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
!ll&&!rl&&r
004
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id}
!ll&&!rl&&r
004
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction")
!ll&&!rl&&r
004
MC/DC0%0/4
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
builtin::blessed($transaction) $transaction->isa("Unblock::HTTP3::Transaction") defined $self->{"transactions"}{$transaction->stream_id} $self->{"transactions"}{$transaction->stream_id} == $transaction
Truth table20%1/5
A and B and C and D
A= builtin::blessed($transaction)B= $transaction->isa("Unblock::HTTP3::Transaction")C= defined $self->{"transactions"}{$transaction->stream_id}D= $self->{"transactions"}{$transaction->stream_id} == $transaction
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2319  
2320 4 my $body;
2321  
2322 4 ▶ if ($self->{role} eq 'client') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'role'} eq 'client') { } 2 2 4
2323 2 ▶ croak "$operation(): Transaction has no streaming Request body"
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->_request_is_streaming 0 2 2
2324 unless $transaction->_request_is_streaming;
2325 2 $body = $transaction->request_body;
2326 } else {
2327 2 ▶ croak "$operation(): Transaction has no streaming Response body"
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->_response_is_streaming and $transaction->is_response_started 0 2 2
Condition33%1/3
$transaction->_response_is_streaming and $transaction->is_response_started
!ll&&!rl&&r
002
MC/DC0%0/2
$transaction->_response_is_streaming and $transaction->is_response_started
$transaction->_response_is_streaming $transaction->is_response_started
Truth table33%1/3
A and B
A= $transaction->_response_is_streamingB= $transaction->is_response_started
ABresult
0X0
100
111
2328 unless $transaction->_response_is_streaming
2329 && $transaction->is_response_started;
2330 $body = $transaction->{response_body}
2331 2 ▶ or croak "$operation(): Transaction has no streaming Response body";
Branch: 1 branch
BranchTrueFalseTotal
$body = $transaction->{"response_body"} or croak("$operation(): Transaction has no streaming Response body") 2 0 2
2332 }
2333  
2334 return $final
2335 4 ▶ ? do {
Branch: 1 branch
BranchTrueFalseTotal
$final ? : 2 2 4
2336 2 $body->complete($bytes);
2337 2 1;
2338 }
2339 : $body->write($bytes);
2340 }
2341  
2342 40 ▶sub _write_transaction_body {
Subroutine _write_transaction_body: called CC=17 SCAR=31.7
2343 40 my ($self, $transaction, $kind, $bytes, $final, $operation) = @_;
2344  
2345 croak "$operation(): Transaction does not belong to this HTTP/3 connection"
2346 unless blessed($transaction)
2347 && $transaction->isa('Unblock::HTTP3::Transaction')
2348 && defined($self->{transactions}{ $transaction->stream_id })
2349 40 ▶ && $self->{transactions}{ $transaction->stream_id } == $transaction;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction 0 40 40
Condition33%3/9
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
!ll&&!rl&&r
0040
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id}
!ll&&!rl&&r
0040
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction")
!ll&&!rl&&r
0040
MC/DC0%0/4
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
builtin::blessed($transaction) $transaction->isa("Unblock::HTTP3::Transaction") defined $self->{"transactions"}{$transaction->stream_id} $self->{"transactions"}{$transaction->stream_id} == $transaction
Truth table20%1/5
A and B and C and D
A= builtin::blessed($transaction)B= $transaction->isa("Unblock::HTTP3::Transaction")C= defined $self->{"transactions"}{$transaction->stream_id}D= $self->{"transactions"}{$transaction->stream_id} == $transaction
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2350  
2351 40 my $id = $transaction->stream_id;
2352 40 my $message;
2353  
2354 40 ▶ if ($kind eq 'request') {
Branch: 2 branches
BranchTrueFalseTotal
if ($kind eq 'request') { } 23 17 40
elsif ($kind eq 'response') { } 17 0 17
2355 croak "$operation(): request body production requires a client connection"
2356 23 ▶ unless $self->{role} eq 'client';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "client" 0 23 23
2357  
2358 23 $message = $transaction->request;
2359  
2360 23 ▶ croak "$operation(): Request is not configured for incremental body production"
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->_request_is_streaming 0 23 23
2361 unless $transaction->_request_is_streaming;
2362 } elsif ($kind eq 'response') {
2363 croak "$operation(): response body production requires a server connection"
2364 17 ▶ unless $self->{role} eq 'server';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "server" 0 17 17
2365  
2366 17 ▶ $message = $transaction->response
Branch: 1 branch
BranchTrueFalseTotal
$message = $transaction->response or croak("$operation(): Transaction has no Response") 17 0 17
2367 or croak "$operation(): Transaction has no Response";
2368  
2369 17 $self->_assert_response_body_allowed(
2370 $transaction,
2371 $message,
2372 $operation,
2373 );
2374  
2375 17 ▶ croak "$operation(): Response is not configured for incremental body production"
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->_response_is_streaming 0 17 17
2376 unless $transaction->_response_is_streaming;
2377  
2378 17 ▶ if (!$self->{response_sent}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"response_sent"}{$id}) 8 9 17
2379 8 $self->{response_sent}{$id} = 1;
2380  
2381 8 my $ok = eval {
2382 8 $self->_submit_response($id, $message);
2383 8 1;
2384 };
2385  
2386 8 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 8 8
2387 0 delete $self->{response_sent}{$id};
2388 0 delete $self->{body_bytes_sent}{$id};
2389 0 die $@;
2390 }
2391  
2392 8 $transaction->_mark_response_started;
2393 }
2394 } else {
2395 0 croak "$operation(): unsupported HTTP body producer '$kind'";
2396 }
2397  
2398 40 ▶ $self->_assert_incremental_content_length(
Branch: 1 branch
BranchTrueFalseTotal
$final ? : 20 20 40
2399 $transaction,
2400 $kind,
2401 $message,
2402 $bytes,
2403 $final ? 1 : 0,
2404 $operation,
2405 );
2406  
2407 $self->{native}->append_body(
2408 40 ▶ $id,
Branch: 1 branch
BranchTrueFalseTotal
$final ? : 20 20 40
2409 $bytes,
2410 $final ? 1 : 0,
2411 );
2412  
2413 40 $self->_drain_output;
2414 40 $self->_maybe_complete_transaction($id);
2415  
2416 # Each active streaming producer gets a share of the native retained
2417 # body budget. A QUIC-credit-blocked stream must not withhold every
2418 # other producer's on_drain merely because its own data remains queued.
2419 # A complete write is accepted before this advisory return; one write
2420 # can exceed its share, so this is NOT a hard memory or packet limit.
2421 40 ▶ return $self->{native}->streaming_retained_bytes_for_stream($id)
Branch: 1 branch
BranchTrueFalseTotal
$self->{'native'}->streaming_retained_bytes_for_stream($id) < $self->_streaming_share_limit ? : 38 2 40
2422 < $self->_streaming_share_limit ? 1 : 0;
2423 }
2424  
2425 474 ▶sub _streaming_share_limit {
Subroutine _streaming_share_limit: called CC=3 SCAR=11.0
2426 474 my ($self) = @_;
2427 474 my $count = $self->{native}->active_streaming_body_count;
2428 474 ▶ return $self->{send_buffer_limit} if $count < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $count < 2 471 3 474
2429 3 my $share = int($self->{send_buffer_limit} / $count);
2430 3 ▶ return $share || 1;
Condition50%1/2
$share || 1
l!l
30
MC/DC0%0/1
$share || 1
$share
Truth table50%1/2
A
A= $share
Aresult
11
00
2431 }
2432  
2433 434 ▶sub _drain_body_producers {
Subroutine _drain_body_producers: called CC=6 SCAR=17.9
2434 434 my ($self) = @_;
2435  
2436 434 my $share = $self->_streaming_share_limit;
2437 434 for my $transaction (values %{ $self->{transactions} }) {
2438 677 ▶ next if $transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal 237 440 677
2439 440 my $id = $transaction->stream_id;
2440 440 ▶ next if $self->{native}->streaming_retained_bytes_for_stream($id)
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"native"}->streaming_retained_bytes_for_stream($id) >= $share 9 431 440
2441 >= $share;
2442  
2443 431 ▶ if (my $body = $transaction->_request_body_object) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $transaction->_request_body_object) 129 302 431
2444 129 $body->_drain;
2445 }
2446  
2447 431 ▶ if (my $body = $transaction->_response_body_object) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $transaction->_response_body_object) 69 362 431
2448 69 $body->_drain;
2449 }
2450 }
2451  
2452 434 return;
2453 }
2454  
2455 29 ▶sub _consume_received_body {
Subroutine _consume_received_body: called CC=18 SCAR=35.4
2456 29 my ($self, $transaction, $kind, $amount) = @_;
2457  
2458 croak 'received body Transaction does not belong to this HTTP/3 connection'
2459 unless blessed($transaction)
2460 && $transaction->isa('Unblock::HTTP3::Transaction')
2461 && defined($self->{transactions}{ $transaction->stream_id })
2462 29 ▶ && $self->{transactions}{ $transaction->stream_id } == $transaction;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction 0 29 29
Condition33%3/9
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
!ll&&!rl&&r
0029
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id}
!ll&&!rl&&r
0029
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction")
!ll&&!rl&&r
0029
MC/DC0%0/4
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
builtin::blessed($transaction) $transaction->isa("Unblock::HTTP3::Transaction") defined $self->{"transactions"}{$transaction->stream_id} $self->{"transactions"}{$transaction->stream_id} == $transaction
Truth table20%1/5
A and B and C and D
A= builtin::blessed($transaction)B= $transaction->isa("Unblock::HTTP3::Transaction")C= defined $self->{"transactions"}{$transaction->stream_id}D= $self->{"transactions"}{$transaction->stream_id} == $transaction
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2463  
2464 29 ▶ croak 'received body consume amount must be a non-negative integer'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $amount and not ref $amount and $amount =~ /\A[0-9]+\z/ 0 29 29
Condition33%2/6
defined $amount and not ref $amount and $amount =~ /\A[0-9]+\z/
!ll&&!rl&&r
0029
defined $amount and not ref $amount
!ll&&!rl&&r
0029
MC/DC0%0/3
defined $amount and not ref $amount and $amount =~ /\A[0-9]+\z/
defined $amount not ref $amount $amount =~ /\A[0-9]+\z/
Truth table25%1/4
A and not(B) and C
A= defined $amountB= not ref $amountC= $amount =~ /\A[0-9]+\z/
ABCresult
0XX0
10X0
1100
1111
2465 unless defined($amount)
2466 && !ref($amount)
2467 && $amount =~ /\A[0-9]+\z/;
2468  
2469 29 ▶ return if $amount == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $amount == 0 0 29 29
2470  
2471 croak 'request receive bodies exist only on server connections'
2472 29 ▶ if $kind eq 'request' && $self->{role} ne 'server';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "request" and $self->{"role"} ne "server" 0 29 29
Condition66%2/3
$kind eq "request" and $self->{"role"} ne "server"
!ll&&!rl&&r
2090
MC/DC0%0/2
$kind eq "request" and $self->{"role"} ne "server"
$kind eq "request" $self->{"role"} ne "server"
Truth table66%2/3
A and B
A= $kind eq "request"B= $self->{"role"} ne "server"
ABresult
0X0
100
111
2473 croak 'response receive bodies exist only on client connections'
2474 29 ▶ if $kind eq 'response' && $self->{role} ne 'client';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "response" and $self->{"role"} ne "client" 0 29 29
Condition66%2/3
$kind eq "response" and $self->{"role"} ne "client"
!ll&&!rl&&r
9200
MC/DC0%0/2
$kind eq "response" and $self->{"role"} ne "client"
$kind eq "response" $self->{"role"} ne "client"
Truth table66%2/3
A and B
A= $kind eq "response"B= $self->{"role"} ne "client"
ABresult
0X0
100
111
2475 29 ▶ croak "unsupported received body kind '$kind'"
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "request" and $kind ne "response" 0 29 29
Condition66%2/3
$kind ne "request" and $kind ne "response"
!ll&&!rl&&r
9200
MC/DC0%0/2
$kind ne "request" and $kind ne "response"
$kind ne "request" $kind ne "response"
Truth table66%2/3
A and B
A= $kind ne "request"B= $kind ne "response"
ABresult
0X0
100
111
2476 if $kind ne 'request' && $kind ne 'response';
2477  
2478 29 ▶ my $stream = $self->{streams}{ $transaction->stream_id }
Branch: 1 branch
BranchTrueFalseTotal
my $stream = $self->{"streams"}{$transaction->stream_id} or croak("received body stream is no longer available") 29 0 29
2479 or croak 'received body stream is no longer available';
2480  
2481 # STOP_SENDING already discards and credits delivered, unconsumed bytes
2482 # in Net::QUIC. Terminal Reader cleanup must not credit them a second time.
2483 29 ▶ return if $transaction->is_terminal
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal and defined $stream->local_stop_sending_code 1 28 29
Condition100%3/3
$transaction->is_terminal and defined $stream->local_stop_sending_code
!ll&&!rl&&r
2711
MC/DC100%2/2
$transaction->is_terminal and defined $stream->local_stop_sending_code
$transaction->is_terminal defined $stream->local_stop_sending_code
Truth table100%3/3
A and B
A= $transaction->is_terminalB= defined $stream->local_stop_sending_code
ABresult
0X0
100
111
2484 && defined($stream->local_stop_sending_code);
2485  
2486 28 $stream->consume(0 + $amount);
2487 28 return;
2488 }
2489  
2490 5 ▶sub _cancel_transaction {
Subroutine _cancel_transaction: called CC=6 SCAR=21.6
2491 5 my ($self, $transaction) = @_;
2492  
2493 croak 'Transaction does not belong to this HTTP/3 connection'
2494 unless blessed($transaction)
2495 && $transaction->isa('Unblock::HTTP3::Transaction')
2496 && defined($self->{transactions}{ $transaction->stream_id })
2497 5 ▶ && $self->{transactions}{ $transaction->stream_id } == $transaction;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction 0 5 5
Condition33%3/9
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
!ll&&!rl&&r
005
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id}
!ll&&!rl&&r
005
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction")
!ll&&!rl&&r
005
MC/DC0%0/4
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
builtin::blessed($transaction) $transaction->isa("Unblock::HTTP3::Transaction") defined $self->{"transactions"}{$transaction->stream_id} $self->{"transactions"}{$transaction->stream_id} == $transaction
Truth table20%1/5
A and B and C and D
A= builtin::blessed($transaction)B= $transaction->isa("Unblock::HTTP3::Transaction")C= defined $self->{"transactions"}{$transaction->stream_id}D= $self->{"transactions"}{$transaction->stream_id} == $transaction
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2498  
2499 5 ▶ return $transaction if $transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal 0 5 5
2500  
2501 5 $self->_reject_message_stream(
2502 $transaction->stream_id,
2503 'HTTP/3 transaction cancelled',
2504 $H3_REQUEST_CANCELLED,
2505 );
2506  
2507 5 $transaction->_mark_cancelled;
2508 5 return $transaction;
2509 }
2510  
2511 11 ▶sub _transaction_priority {
Subroutine _transaction_priority: called CC=8 SCAR=23.1
2512 11 my ($self, $transaction) = @_;
2513  
2514 croak 'priority Transaction does not belong to this connection'
2515 unless blessed($transaction)
2516 && $transaction->isa('Unblock::HTTP3::Transaction')
2517 && defined($self->{transactions}{ $transaction->stream_id })
2518 11 ▶ && $self->{transactions}{ $transaction->stream_id } == $transaction;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction 0 11 11
Condition33%3/9
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
!ll&&!rl&&r
0011
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id}
!ll&&!rl&&r
0011
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction")
!ll&&!rl&&r
0011
MC/DC0%0/4
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
builtin::blessed($transaction) $transaction->isa("Unblock::HTTP3::Transaction") defined $self->{"transactions"}{$transaction->stream_id} $self->{"transactions"}{$transaction->stream_id} == $transaction
Truth table20%1/5
A and B and C and D
A= builtin::blessed($transaction)B= $transaction->isa("Unblock::HTTP3::Transaction")C= defined $self->{"transactions"}{$transaction->stream_id}D= $self->{"transactions"}{$transaction->stream_id} == $transaction
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2519  
2520 11 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"role"} eq "server" and not $transaction->is_terminal) 8 3 11
Condition66%2/3
$self->{"role"} eq "server" and not $transaction->is_terminal
!ll&&!rl&&r
308
MC/DC50%1/2
$self->{"role"} eq "server" and not $transaction->is_terminal
$self->{"role"} eq "server" not $transaction->is_terminal
Truth table66%2/3
A and not(B)
A= $self->{"role"} eq "server"B= not $transaction->is_terminal
ABresult
0X0
100
111
2521 $self->{role} eq 'server'
2522 && !$transaction->is_terminal
2523 ) {
2524 my $priority = $self->{native}->get_server_stream_priority(
2525 8 $transaction->stream_id,
2526 );
2527  
2528 return {
2529 8 ▶ urgency => 0 + $priority->[0],
Branch: 1 branch
BranchTrueFalseTotal
$priority->[1] ? : 6 2 8
2530 incremental => $priority->[1] ? 1 : 0,
2531 };
2532 }
2533  
2534 3 return { %{ $transaction->{priority} } };
2535 }
2536  
2537 2 ▶sub _set_transaction_priority {
Subroutine _set_transaction_priority: called CC=8 SCAR=23.2
2538 2 my ($self, $transaction, $priority) = @_;
2539  
2540 croak 'priority Transaction does not belong to this connection'
2541 unless blessed($transaction)
2542 && $transaction->isa('Unblock::HTTP3::Transaction')
2543 && defined($self->{transactions}{ $transaction->stream_id })
2544 2 ▶ && $self->{transactions}{ $transaction->stream_id } == $transaction;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction 0 2 2
Condition33%3/9
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
!ll&&!rl&&r
002
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id}
!ll&&!rl&&r
002
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction")
!ll&&!rl&&r
002
MC/DC0%0/4
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
builtin::blessed($transaction) $transaction->isa("Unblock::HTTP3::Transaction") defined $self->{"transactions"}{$transaction->stream_id} $self->{"transactions"}{$transaction->stream_id} == $transaction
Truth table20%1/5
A and B and C and D
A= builtin::blessed($transaction)B= $transaction->isa("Unblock::HTTP3::Transaction")C= defined $self->{"transactions"}{$transaction->stream_id}D= $self->{"transactions"}{$transaction->stream_id} == $transaction
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2545 2 ▶ croak 'priority must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $priority eq "HASH" 0 2 2
2546 unless ref($priority) eq 'HASH';
2547  
2548 2 my $stream_id = $transaction->stream_id;
2549  
2550 2 ▶ if ($self->{role} eq 'client') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'role'} eq 'client') { } 1 1 2
2551 1 my $field = Unblock::HTTP3::Transaction::_priority_field(
2552 $priority,
2553 );
2554  
2555 $self->{native}->set_client_stream_priority(
2556 1 $stream_id,
2557 $field,
2558 );
2559 } else {
2560 $self->{native}->set_server_stream_priority(
2561 $stream_id,
2562 $priority->{urgency},
2563 1 ▶ $priority->{incremental} ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
$priority->{'incremental'} ? : 1 0 1
2564 );
2565 }
2566  
2567 2 $transaction->{priority} = { %$priority };
2568 2 $self->_service;
2569  
2570 2 return;
2571 }
2572  
2573 8 ▶sub _send_transaction_datagram {
Subroutine _send_transaction_datagram: called CC=14 SCAR=31.3
2574 8 my ($self, $transaction, $bytes) = @_;
2575  
2576 croak 'HTTP Datagram Transaction does not belong to this connection'
2577 unless blessed($transaction)
2578 && $transaction->isa('Unblock::HTTP3::Transaction')
2579 && defined($self->{transactions}{ $transaction->stream_id })
2580 8 ▶ && $self->{transactions}{ $transaction->stream_id } == $transaction;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction 0 8 8
Condition33%3/9
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
!ll&&!rl&&r
008
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id}
!ll&&!rl&&r
008
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction")
!ll&&!rl&&r
008
MC/DC0%0/4
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
builtin::blessed($transaction) $transaction->isa("Unblock::HTTP3::Transaction") defined $self->{"transactions"}{$transaction->stream_id} $self->{"transactions"}{$transaction->stream_id} == $transaction
Truth table20%1/5
A and B and C and D
A= builtin::blessed($transaction)B= $transaction->isa("Unblock::HTTP3::Transaction")C= defined $self->{"transactions"}{$transaction->stream_id}D= $self->{"transactions"}{$transaction->stream_id} == $transaction
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2581 8 ▶ croak 'HTTP Datagrams are not enabled for this Transaction'
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->datagrams_enabled 0 8 8
2582 unless $transaction->datagrams_enabled;
2583 8 ▶ croak 'HTTP Datagram payload is required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes 0 8 8
2584 unless defined $bytes;
2585 8 ▶ croak 'HTTP Datagram payload must be bytes, not a reference'
Branch: 1 branch
BranchTrueFalseTotal
if ref $bytes 0 8 8
2586 if ref($bytes);
2587 8 ▶ croak 'HTTP/3 DATAGRAM is not negotiated with the peer'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can_send_http_datagrams 0 8 8
2588 unless $self->can_send_http_datagrams;
2589  
2590 8 my $id = $transaction->stream_id;
2591 croak 'HTTP Datagram request stream send side is closed'
2592 8 ▶ if $self->{output_finished}{$id};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"output_finished"}{$id} 0 8 8
2593  
2594 8 my $stream = $self->{streams}{$id};
2595 8 ▶ croak 'HTTP Datagram request stream is no longer available'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stream 0 8 8
2596 unless defined $stream;
2597 8 ▶ croak 'HTTP Datagram request stream send side is reset'
Branch: 1 branch
BranchTrueFalseTotal
if defined $stream->local_reset_code 0 8 8
2598 if defined $stream->local_reset_code;
2599  
2600 8 my $quarter = $id >> 2;
2601 8 my $prefix = _encode_http3_varint($quarter);
2602 8 my $max = $self->_transaction_datagram_payload_size($transaction);
2603  
2604 8 ▶ croak "HTTP Datagram payload exceeds current path capacity $max"
Branch: 1 branch
BranchTrueFalseTotal
if length $bytes > $max 0 8 8
2605 if length($bytes) > $max;
2606  
2607 8 ▶ return $self->{quic}->send_datagram($prefix . $bytes) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'quic'}->send_datagram($prefix . $bytes) ? : 8 0 8
2608 }
2609  
2610 10 ▶sub _transaction_datagram_payload_size {
Subroutine _transaction_datagram_payload_size: called CC=10 SCAR=28.6
2611 10 my ($self, $transaction) = @_;
2612  
2613 croak 'HTTP Datagram Transaction does not belong to this connection'
2614 unless blessed($transaction)
2615 && $transaction->isa('Unblock::HTTP3::Transaction')
2616 && defined($self->{transactions}{ $transaction->stream_id })
2617 10 ▶ && $self->{transactions}{ $transaction->stream_id } == $transaction;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction 0 10 10
Condition33%3/9
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
!ll&&!rl&&r
0010
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id}
!ll&&!rl&&r
0010
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction")
!ll&&!rl&&r
0010
MC/DC0%0/4
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
builtin::blessed($transaction) $transaction->isa("Unblock::HTTP3::Transaction") defined $self->{"transactions"}{$transaction->stream_id} $self->{"transactions"}{$transaction->stream_id} == $transaction
Truth table20%1/5
A and B and C and D
A= builtin::blessed($transaction)B= $transaction->isa("Unblock::HTTP3::Transaction")C= defined $self->{"transactions"}{$transaction->stream_id}D= $self->{"transactions"}{$transaction->stream_id} == $transaction
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2618  
2619 10 ▶ return 0 unless $transaction->datagrams_enabled;
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->datagrams_enabled 0 10 10
2620 10 ▶ return 0 unless $self->can_send_http_datagrams;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can_send_http_datagrams 0 10 10
2621  
2622 10 my $capacity = $self->{quic}->max_datagram_payload_size;
2623 10 ▶ return 0 unless defined($capacity) && $capacity > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $capacity and $capacity > 0 0 10 10
Condition33%1/3
defined $capacity and $capacity > 0
!ll&&!rl&&r
0010
MC/DC0%0/2
defined $capacity and $capacity > 0
defined $capacity $capacity > 0
Truth table33%1/3
A and B
A= defined $capacityB= $capacity > 0
ABresult
0X0
100
111
2624  
2625 10 my $prefix = _encode_http3_varint($transaction->stream_id >> 2);
2626 10 my $available = $capacity - length($prefix);
2627  
2628 10 ▶ return $available > 0 ? $available : 0;
Branch: 1 branch
BranchTrueFalseTotal
$available > 0 ? : 10 0 10
2629 }
2630  
2631 6 ▶sub _buffer_transaction_datagram {
Subroutine _buffer_transaction_datagram: called CC=3 SCAR=11.0
2632 6 my ($self, $transaction, $bytes) = @_;
2633  
2634 6 my $length = length($bytes);
2635  
2636 6 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"datagram_buffered_count"} >= $self->{"max_buffered_datagrams"} or $self->{"datagram_buffered_bytes"} + $length > $self->{"max_buffered_datagram_bytes"}) 1 5 6
Condition66%2/3
$self->{"datagram_buffered_count"} >= $self->{"max_buffered_datagrams"} or $self->{"datagram_buffered_bytes"} + $length > $self->{"max_buffered_datagram_bytes"}
l!l&&r!l&&!r
105
MC/DC50%1/2
$self->{"datagram_buffered_count"} >= $self->{"max_buffered_datagrams"} or $self->{"datagram_buffered_bytes"} + $length > $self->{"max_buffered_datagram_bytes"}
$self->{"datagram_buffered_count"} >= $self->{"max_buffered_datagrams"} $self->{"datagram_buffered_bytes"} + $length > $self->{"max_buffered_datagram_bytes"}
Truth table66%2/3
A or B
A= $self->{"datagram_buffered_count"} >= $self->{"max_buffered_datagrams"}B= $self->{"datagram_buffered_bytes"} + $length > $self->{"max_buffered_datagram_bytes"}
ABresult
1X1
011
000
2637 $self->{datagram_buffered_count} >= $self->{max_buffered_datagrams}
2638 || $self->{datagram_buffered_bytes} + $length
2639 > $self->{max_buffered_datagram_bytes}
2640 ) {
2641 1 ++$self->{datagram_receive_drops};
2642 1 return;
2643 }
2644  
2645 5 ++$self->{datagram_buffered_count};
2646 5 $self->{datagram_buffered_bytes} += $length;
2647 5 $transaction->_enqueue_datagram($bytes);
2648 5 return 1;
2649 }
2650  
2651 6 ▶sub _datagram_dequeued {
Subroutine _datagram_dequeued: called CC=3 SCAR=11.3
2652 6 my ($self, $length) = @_;
2653  
2654 --$self->{datagram_buffered_count}
2655 6 ▶ if $self->{datagram_buffered_count} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"datagram_buffered_count"} > 0 6 0 6
2656 6 $self->{datagram_buffered_bytes} -= $length;
2657 $self->{datagram_buffered_bytes} = 0
2658 6 ▶ if $self->{datagram_buffered_bytes} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"datagram_buffered_bytes"} < 0 0 6 6
2659  
2660 6 return;
2661 }
2662  
2663 1 ▶sub _reject_datagram_stream {
Subroutine _reject_datagram_stream: called CC=6 SCAR=18.9
2664 1 my ($self, $transaction, $reason) = @_;
2665  
2666 1 my $id = $transaction->stream_id;
2667 1 my $stream = $self->{streams}{$id};
2668  
2669 1 ▶ if (defined $stream) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stream) 1 0 1
2670 1 ▶ if ($stream->can_receive && !$stream->remote_finished) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream->can_receive and not $stream->remote_finished) 1 0 1
Condition33%1/3
$stream->can_receive and not $stream->remote_finished
!ll&&!rl&&r
001
MC/DC0%0/2
$stream->can_receive and not $stream->remote_finished
$stream->can_receive not $stream->remote_finished
Truth table33%1/3
A and not(B)
A= $stream->can_receiveB= not $stream->remote_finished
ABresult
0X0
100
111
2671 1 $self->{native}->shutdown_stream_read($id);
2672 1 $stream->stop_sending($H3_DATAGRAM_ERROR);
2673 1 $transaction->_mark_local_stop_sending($H3_DATAGRAM_ERROR);
2674 }
2675  
2676 1 ▶ if ($stream->can_send && !$self->{output_finished}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream->can_send and not $self->{"output_finished"}{$id}) 1 0 1
Condition33%1/3
$stream->can_send and not $self->{"output_finished"}{$id}
!ll&&!rl&&r
001
MC/DC0%0/2
$stream->can_send and not $self->{"output_finished"}{$id}
$stream->can_send not $self->{"output_finished"}{$id}
Truth table33%1/3
A and not(B)
A= $stream->can_sendB= not $self->{"output_finished"}{$id}
ABresult
0X0
100
111
2677 1 $self->{native}->shutdown_stream_write($id);
2678 1 $stream->reset($H3_DATAGRAM_ERROR);
2679 1 $transaction->_mark_local_reset($H3_DATAGRAM_ERROR);
2680 }
2681 }
2682  
2683 1 $self->{native}->discard_body($id);
2684 1 $transaction->_mark_error($reason, $H3_DATAGRAM_ERROR);
2685 1 return;
2686 }
2687  
2688 9 ▶sub _receive_quic_datagram {
Subroutine _receive_quic_datagram: called CC=21 SCAR=35.1
2689 9 my ($self, $bytes, $early_data) = @_;
2690  
2691 9 ▶ return if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 0 9 9
2692  
2693 9 ▶ if ($early_data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($early_data) 1 8 9
2694 1 ▶ return if $self->{role} ne 'server';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"role"} ne "server" 0 1 1
2695  
2696 1 ▶ if (!defined($self->{remembered_local_settings})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"remembered_local_settings"}) 0 1 1
2697 0 $self->_fail_connection(
2698 $H3_SETTINGS_ERROR,
2699 'received HTTP/3 0-RTT DATAGRAM without remembered_local_settings',
2700 );
2701 0 return;
2702 }
2703  
2704 # An unreliable DATAGRAM can race ahead of the client's 0-RTT
2705 # SETTINGS control stream. Drop it until current peer SETTINGS have
2706 # actually arrived; there is no safe request association yet.
2707 1 ▶ return unless $self->{peer_settings_received};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"peer_settings_received"} 0 1 1
2708 }
2709  
2710 9 ▶ if (!$self->{enable_http_datagrams}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"enable_http_datagrams"}) 0 9 9
2711 0 $self->_fail_connection(
2712 $H3_DATAGRAM_ERROR,
2713 'received QUIC DATAGRAM without local SETTINGS_H3_DATAGRAM',
2714 );
2715 0 return;
2716 }
2717  
2718 # A peer may send after it has sent its SETTINGS while the control-stream
2719 # bytes are still racing this unreliable DATAGRAM. Dropping is safer than
2720 # assigning semantics before the peer SETTINGS have been processed.
2721 9 ▶ return unless $self->{peer_settings_received};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"peer_settings_received"} 0 9 9
2722  
2723 9 ▶ if (!$self->{peer_h3_datagram}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"peer_h3_datagram"}) 0 9 9
2724 0 $self->_fail_connection(
2725 $H3_DATAGRAM_ERROR,
2726 'received QUIC DATAGRAM without peer SETTINGS_H3_DATAGRAM',
2727 );
2728 0 return;
2729 }
2730  
2731 9 my ($quarter, $prefix_length) = _decode_http3_varint($bytes, 0);
2732  
2733 9 ▶ if (!defined $quarter) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $quarter) 1 8 9
2734 1 $self->_fail_connection(
2735 $H3_DATAGRAM_ERROR,
2736 'HTTP Datagram is missing a complete Quarter Stream ID',
2737 );
2738 1 return;
2739 }
2740  
2741 8 ▶ if (_decimal_less_than($HTTP3_MAX_QUARTER_STREAM_ID, $quarter)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_decimal_less_than($HTTP3_MAX_QUARTER_STREAM_ID, $quarter)) 0 8 8
2742 0 $self->_fail_connection(
2743 $H3_DATAGRAM_ERROR,
2744 'HTTP Datagram Quarter Stream ID exceeds the RFC 9297 maximum',
2745 );
2746 0 return;
2747 }
2748  
2749 8 my $id = (0 + $quarter) << 2;
2750 8 my $transaction = $self->{transactions}{$id};
2751  
2752 # RFC 9297 permits silently dropping a DATAGRAM that races ahead of the
2753 # request stream. The same treatment is appropriate after transaction
2754 # cleanup, where the receive side is already gone.
2755 8 ▶ return unless defined $transaction;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $transaction 0 8 8
2756  
2757 8 my $stream = $self->{streams}{$id};
2758 8 ▶ return unless defined $stream;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stream 0 8 8
2759 8 ▶ return if $stream->remote_finished;
Branch: 1 branch
BranchTrueFalseTotal
if $stream->remote_finished 0 8 8
2760 8 ▶ return if defined $stream->remote_reset_code;
Branch: 1 branch
BranchTrueFalseTotal
if defined $stream->remote_reset_code 0 8 8
2761  
2762 8 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($transaction->early_data and $self->{"role"} eq "server" and not $self->{"quic"}->ready) 1 7 8
Condition66%4/6
$transaction->early_data and $self->{"role"} eq "server" and not $self->{"quic"}->ready
!ll&&!rl&&r
701
$transaction->early_data and $self->{"role"} eq "server"
!ll&&!rl&&r
701
MC/DC33%1/3
$transaction->early_data and $self->{"role"} eq "server" and not $self->{"quic"}->ready
$transaction->early_data $self->{"role"} eq "server" not $self->{"quic"}->ready
Truth table50%2/4
A and B and not(C)
A= $transaction->early_dataB= $self->{"role"} eq "server"C= not $self->{"quic"}->ready
ABCresult
0XX0
10X0
1100
1111
2763 $transaction->early_data
2764 && $self->{role} eq 'server'
2765 && !$self->{quic}->ready
2766 ) {
2767 1 my $payload = substr($bytes, $prefix_length);
2768 1 my $length = length($payload);
2769  
2770 1 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"datagram_buffered_count"} >= $self->{"max_buffered_datagrams"} or $self->{"datagram_buffered_bytes"} + $length > $self->{"max_buffered_datagram_bytes"}) 0 1 1
Condition33%1/3
$self->{"datagram_buffered_count"} >= $self->{"max_buffered_datagrams"} or $self->{"datagram_buffered_bytes"} + $length > $self->{"max_buffered_datagram_bytes"}
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->{"datagram_buffered_count"} >= $self->{"max_buffered_datagrams"} or $self->{"datagram_buffered_bytes"} + $length > $self->{"max_buffered_datagram_bytes"}
$self->{"datagram_buffered_count"} >= $self->{"max_buffered_datagrams"} $self->{"datagram_buffered_bytes"} + $length > $self->{"max_buffered_datagram_bytes"}
Truth table33%1/3
A or B
A= $self->{"datagram_buffered_count"} >= $self->{"max_buffered_datagrams"}B= $self->{"datagram_buffered_bytes"} + $length > $self->{"max_buffered_datagram_bytes"}
ABresult
1X1
011
000
2771 $self->{datagram_buffered_count}
2772 >= $self->{max_buffered_datagrams}
2773 || $self->{datagram_buffered_bytes} + $length
2774 > $self->{max_buffered_datagram_bytes}
2775 ) {
2776 0 ++$self->{datagram_receive_drops};
2777 0 return;
2778 }
2779  
2780 1 ++$self->{datagram_buffered_count};
2781 1 $self->{datagram_buffered_bytes} += $length;
2782 1 push @{ $self->{pending_early_datagrams}{$id} }, $payload;
2783 1 return;
2784 }
2785  
2786 7 ▶ if (!$transaction->datagrams_enabled) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($transaction->datagrams_enabled) 1 6 7
2787 1 $self->_reject_datagram_stream(
2788 $transaction,
2789 'received HTTP Datagram for a request without datagram semantics',
2790 );
2791 1 return;
2792 }
2793  
2794 6 my $payload = substr($bytes, $prefix_length);
2795 6 $transaction->_receive_datagram($payload);
2796 6 return;
2797 }
2798  
2799 1 ▶sub _capsule_protocol_error {
Subroutine _capsule_protocol_error: called CC=7 SCAR=24.0
2800 1 my ($self, $transaction, $error) = @_;
2801  
2802 croak 'Capsule Protocol Transaction does not belong to this connection'
2803 unless blessed($transaction)
2804 && $transaction->isa('Unblock::HTTP3::Transaction')
2805 && defined($self->{transactions}{ $transaction->stream_id })
2806 1 ▶ && $self->{transactions}{ $transaction->stream_id } == $transaction;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction 0 1 1
Condition33%3/9
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
!ll&&!rl&&r
001
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id}
!ll&&!rl&&r
001
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction")
!ll&&!rl&&r
001
MC/DC0%0/4
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id} and $self->{"transactions"}{$transaction->stream_id} == $transaction
builtin::blessed($transaction) $transaction->isa("Unblock::HTTP3::Transaction") defined $self->{"transactions"}{$transaction->stream_id} $self->{"transactions"}{$transaction->stream_id} == $transaction
Truth table20%1/5
A and B and C and D
A= builtin::blessed($transaction)B= $transaction->isa("Unblock::HTTP3::Transaction")C= defined $self->{"transactions"}{$transaction->stream_id}D= $self->{"transactions"}{$transaction->stream_id} == $transaction
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2807  
2808 1 ▶ my $message = defined($error) && length("$error")
Branch: 1 branch
BranchTrueFalseTotal
defined $error && length "$error" ? : 1 0 1
Condition33%1/3
defined $error and length "$error"
!ll&&!rl&&r
001
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
2809 ? "$error"
2810 : 'malformed Capsule Protocol stream';
2811 1 $message =~ s/\s+\z//;
2812  
2813 1 $self->_reject_message_stream(
2814 $transaction->stream_id,
2815 "Capsule Protocol error: $message",
2816 );
2817  
2818 1 $transaction->_mark_error(
2819 "Capsule Protocol error: $message",
2820 );
2821  
2822 1 return;
2823 }
2824  
2825 2 ▶sub _receive_body_failure {
Subroutine _receive_body_failure: called CC=3 SCAR=11.6
2826 2 my ($self, $transaction, $reason, $discarded_bytes) = @_;
2827 2 my $stream = $self->{streams}{ $transaction->stream_id };
2828 2 ▶ $stream->consume($discarded_bytes) if $stream && $discarded_bytes;
Branch: 1 branch
BranchTrueFalseTotal
if $stream and $discarded_bytes 2 0 2
Condition33%1/3
$stream and $discarded_bytes
!ll&&!rl&&r
002
MC/DC0%0/2
$stream and $discarded_bytes
$stream $discarded_bytes
Truth table33%1/3
A and B
A= $streamB= $discarded_bytes
ABresult
0X0
100
111
2829 2 $self->_reject_message_stream($transaction->stream_id, $reason, $H3_EXCESSIVE_LOAD);
2830 2 $transaction->_mark_error($reason, $H3_EXCESSIVE_LOAD);
2831 2 return;
2832 }
2833  
2834 9 ▶sub _reject_message_stream {
Subroutine _reject_message_stream: called CC=9 SCAR=22.2
2835 9 my ($self, $id, $reason, $code) = @_;
2836 9 ▶ $code = $H3_MESSAGE_ERROR unless defined $code;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code 2 7 9
2837  
2838 9 $self->{rejected_streams}{$id} = "$reason";
2839  
2840 9 my $stream = $self->{streams}{$id};
2841 9 my $transaction = $self->{transactions}{$id};
2842  
2843 9 ▶ if (defined $stream) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stream) 9 0 9
2844 9 ▶ if ($stream->can_receive && !$stream->remote_finished) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream->can_receive and not $stream->remote_finished) 7 2 9
Condition66%2/3
$stream->can_receive and not $stream->remote_finished
!ll&&!rl&&r
027
MC/DC50%1/2
$stream->can_receive and not $stream->remote_finished
$stream->can_receive not $stream->remote_finished
Truth table66%2/3
A and not(B)
A= $stream->can_receiveB= not $stream->remote_finished
ABresult
0X0
100
111
2845 7 $self->{native}->shutdown_stream_read($id);
2846 7 $stream->stop_sending($code);
2847 7 ▶ $transaction->_mark_local_stop_sending($code)
Branch: 1 branch
BranchTrueFalseTotal
if defined $transaction 6 1 7
2848 if defined $transaction;
2849 }
2850  
2851 9 ▶ if ($stream->can_send && !defined($stream->local_reset_code)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream->can_send and not defined $stream->local_reset_code) 9 0 9
Condition33%1/3
$stream->can_send and not defined $stream->local_reset_code
!ll&&!rl&&r
009
MC/DC0%0/2
$stream->can_send and not defined $stream->local_reset_code
$stream->can_send not defined $stream->local_reset_code
Truth table33%1/3
A and not(B)
A= $stream->can_sendB= not defined $stream->local_reset_code
ABresult
0X0
100
111
2852 9 $self->{native}->shutdown_stream_write($id);
2853 9 $stream->reset($code);
2854 9 ▶ $transaction->_mark_local_reset($code)
Branch: 1 branch
BranchTrueFalseTotal
if defined $transaction 8 1 9
2855 if defined $transaction;
2856 }
2857 }
2858  
2859 9 $self->{native}->discard_body($id);
2860 9 $self->{native}->discard_header_block($id);
2861 9 return;
2862 }
2863  
2864 65 ▶sub _release_peer_bidi_stream_credit {
Subroutine _release_peer_bidi_stream_credit: called CC=7 SCAR=20.2
2865 65 my ($self, $id, $stream) = @_;
2866  
2867 65 ▶ return unless $self->{role} eq 'server';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "server" 32 33 65
2868 33 ▶ return unless defined $stream;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stream 0 33 33
2869 33 ▶ return if $stream->local_initiated;
Branch: 1 branch
BranchTrueFalseTotal
if $stream->local_initiated 0 33 33
2870 33 ▶ return unless $stream->bidirectional;
Branch: 1 branch
BranchTrueFalseTotal
unless $stream->bidirectional 0 33 33
2871  
2872 33 ▶ my $lifecycle = $self->{stream_lifecycle}{$id} ||= {};
Condition50%1/2
$self->{"stream_lifecycle"}{$id} ||= {}
l!l
330
MC/DC0%0/1
$self->{"stream_lifecycle"}{$id} ||= {}
$self->{"stream_lifecycle"}{$id}
Truth table50%1/2
A
A= $self->{"stream_lifecycle"}{$id}
Aresult
11
00
2873 33 ▶ return if $lifecycle->{peer_bidi_credit_released};
Branch: 1 branch
BranchTrueFalseTotal
if $lifecycle->{"peer_bidi_credit_released"} 0 33 33
2874  
2875 33 $lifecycle->{peer_bidi_credit_released} = 1;
2876 33 ++$self->{native_max_client_streams_bidi};
2877  
2878 $self->{native}->set_max_client_streams_bidi(
2879 $self->{native_max_client_streams_bidi},
2880 33 );
2881  
2882 33 return;
2883 }
2884  
2885 120 ▶sub _cleanup_stream_if_done {
Subroutine _cleanup_stream_if_done: called CC=5 SCAR=16.1
2886 120 my ($self, $id) = @_;
2887  
2888 120 my $lifecycle = $self->{stream_lifecycle}{$id};
2889 120 ▶ return unless defined($lifecycle) && $lifecycle->{closed_seen};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lifecycle and $lifecycle->{"closed_seen"} 55 65 120
Condition66%2/3
defined $lifecycle and $lifecycle->{"closed_seen"}
!ll&&!rl&&r
05565
MC/DC50%1/2
defined $lifecycle and $lifecycle->{"closed_seen"}
defined $lifecycle $lifecycle->{"closed_seen"}
Truth table66%2/3
A and B
A= defined $lifecycleB= $lifecycle->{"closed_seen"}
ABresult
0X0
100
111
2890  
2891 65 my $transaction = $self->{transactions}{$id};
2892 65 ▶ return if defined($transaction) && !$transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if defined $transaction and not $transaction->is_terminal 0 65 65
Condition66%2/3
defined $transaction and not $transaction->is_terminal
!ll&&!rl&&r
2630
MC/DC0%0/2
defined $transaction and not $transaction->is_terminal
defined $transaction not $transaction->is_terminal
Truth table66%2/3
A and not(B)
A= defined $transactionB= not $transaction->is_terminal
ABresult
0X0
100
111
2893  
2894 65 delete $self->{streams}{$id};
2895 65 delete $self->{messages}{$id};
2896 65 delete $self->{outgoing}{$id};
2897 65 delete $self->{stream_lifecycle}{$id};
2898 65 delete $self->{trailer_field_section_size}{$id};
2899 65 delete $self->{output_finished}{$id};
2900 65 delete $self->{blocked_output}{$id};
2901 65 delete $self->{response_sent}{$id};
2902 65 delete $self->{body_bytes_sent}{$id};
2903 65 delete $self->{rejected_streams}{$id};
2904 65 delete $self->{peer_uni_probe}{$id};
2905 65 delete $self->{core_uni_streams}{$id};
2906 65 delete $self->{ignored_uni_streams}{$id};
2907 65 delete $self->{extension_stream_objects}{$id};
2908 65 delete $self->{transactions}{$id};
2909  
2910 65 return;
2911 }
2912  
2913 256 ▶sub _maybe_complete_transaction {
Subroutine _maybe_complete_transaction: called CC=17 SCAR=28.4
2914 256 my ($self, $id) = @_;
2915  
2916 256 my $transaction = $self->{transactions}{$id};
2917 256 ▶ return unless defined $transaction;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $transaction 24 232 256
2918 232 ▶ return if $transaction->is_terminal || $transaction->{callback_depth};
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal or $transaction->{"callback_depth"} 40 192 232
Condition100%3/3
$transaction->is_terminal or $transaction->{"callback_depth"}
l!l&&r!l&&!r
3010192
MC/DC100%2/2
$transaction->is_terminal or $transaction->{"callback_depth"}
$transaction->is_terminal $transaction->{"callback_depth"}
Truth table100%3/3
A or B
A= $transaction->is_terminalB= $transaction->{"callback_depth"}
ABresult
1X1
011
000
2919  
2920 192 ▶ if ($self->{role} eq 'client') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"role"} eq "client") 115 77 192
2921 115 my $response = $transaction->response;
2922 115 ▶ return unless defined $response;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $response 61 54 115
2923 54 ▶ return unless $response->is_complete;
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_complete 23 31 54
2924  
2925 31 my $reader = $transaction->_incoming_body_reader('response');
2926 31 ▶ return if defined($reader) && !$reader->is_complete;
Branch: 1 branch
BranchTrueFalseTotal
if defined $reader and not $reader->is_complete 0 31 31
Condition66%2/3
defined $reader and not $reader->is_complete
!ll&&!rl&&r
18130
MC/DC0%0/2
defined $reader and not $reader->is_complete
defined $reader not $reader->is_complete
Truth table66%2/3
A and not(B)
A= defined $readerB= not $reader->is_complete
ABresult
0X0
100
111
2927  
2928 31 ▶ if ($transaction->request->method eq 'CONNECT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($transaction->request->method eq "CONNECT") 10 21 31
2929 10 my $writer = $transaction->_request_body_object;
2930 10 ▶ return unless defined($writer) && $writer->is_complete;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $writer and $writer->is_complete 4 6 10
Condition66%2/3
defined $writer and $writer->is_complete
!ll&&!rl&&r
046
MC/DC50%1/2
defined $writer and $writer->is_complete
defined $writer $writer->is_complete
Truth table66%2/3
A and B
A= defined $writerB= $writer->is_complete
ABresult
0X0
100
111
2931 }
2932  
2933 27 $transaction->_mark_complete;
2934 27 $self->_cleanup_stream_if_done($id);
2935 27 return;
2936 }
2937  
2938 77 my $request = $transaction->request;
2939 77 ▶ return unless $request->is_complete;
Branch: 1 branch
BranchTrueFalseTotal
unless $request->is_complete 20 57 77
2940 57 ▶ return unless $transaction->{request_end_callback_called};
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->{"request_end_callback_called"} 1 56 57
2941  
2942 56 my $reader = $transaction->_incoming_body_reader('request');
2943 56 ▶ return if defined($reader) && !$reader->is_complete;
Branch: 1 branch
BranchTrueFalseTotal
if defined $reader and not $reader->is_complete 0 56 56
Condition66%2/3
defined $reader and not $reader->is_complete
!ll&&!rl&&r
40160
MC/DC0%0/2
defined $reader and not $reader->is_complete
defined $reader not $reader->is_complete
Truth table66%2/3
A and not(B)
A= defined $readerB= not $reader->is_complete
ABresult
0X0
100
111
2944  
2945 56 ▶ return unless $self->{output_finished}{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"output_finished"}{$id} 28 28 56
2946  
2947 28 $transaction->_mark_complete;
2948 28 $self->_cleanup_stream_if_done($id);
2949 28 return;
2950 }
2951  
2952 0 ▶sub shutdown_notice_sent {
Subroutine shutdown_notice_sent: not called CC=3 SCAR=24.8
Pod undocumented
2953 0 my ($self, @args) = @_;
2954 0 ▶ croak 'shutdown_notice_sent() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 0 0
2955 0 ▶ return $self->{shutdown_notice_sent} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'shutdown_notice_sent'} ? : 0 0 0
2956 }
2957  
2958 0 ▶sub shutdown_started {
Subroutine shutdown_started: not called CC=3 SCAR=24.8
Pod undocumented
2959 0 my ($self, @args) = @_;
2960 0 ▶ croak 'shutdown_started() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 0 0
2961 0 ▶ return $self->{shutdown_started} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'shutdown_started'} ? : 0 0 0
2962 }
2963  
2964 0 ▶sub remote_shutdown_id {
Subroutine remote_shutdown_id: not called CC=2 SCAR=17.9
Pod undocumented
2965 0 my ($self, @args) = @_;
2966 0 ▶ croak 'remote_shutdown_id() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 0 0
2967 0 return $self->{remote_shutdown_id};
2968 }
2969  
2970 0 ▶sub shutdown_notice {
Subroutine shutdown_notice: not called CC=4 SCAR=30.0
Pod undocumented
2971 0 my ($self) = @_;
2972  
2973 croak 'HTTP/3 connection has not been started'
2974 0 ▶ unless $self->{started};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"started"} 0 0 0
2975 croak 'HTTP/3 connection has failed'
2976 0 ▶ if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 0 0 0
2977  
2978 0 ▶ return $self if $self->{shutdown_notice_sent};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"shutdown_notice_sent"} 0 0 0
2979  
2980 0 $self->{native}->submit_shutdown_notice;
2981 0 $self->{shutdown_notice_sent} = 1;
2982 0 $self->_drain_output;
2983  
2984 0 return $self;
2985 }
2986  
2987 0 ▶sub shutdown {
Subroutine shutdown: not called CC=4 SCAR=30.0
Pod undocumented
2988 0 my ($self) = @_;
2989  
2990 croak 'HTTP/3 connection has not been started'
2991 0 ▶ unless $self->{started};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"started"} 0 0 0
2992 croak 'HTTP/3 connection has failed'
2993 0 ▶ if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 0 0 0
2994  
2995 0 ▶ return $self if $self->{shutdown_started};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"shutdown_started"} 0 0 0
2996  
2997 0 $self->{native}->begin_shutdown;
2998 0 $self->{shutdown_started} = 1;
2999 0 $self->_drain_output;
3000  
3001 0 return $self;
3002 }
3003  
3004 0 ▶sub drained {
Subroutine drained: not called CC=4 SCAR=30.0
Pod undocumented
3005 0 my ($self, @args) = @_;
3006  
3007 0 ▶ croak 'drained() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 0 0
3008 croak 'drained() is only meaningful for a server HTTP/3 connection'
3009 0 ▶ unless $self->{role} eq 'server';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "server" 0 0 0
3010  
3011 0 ▶ return $self->{native}->is_drained ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'native'}->is_drained ? : 0 0 0
3012 }
3013  
3014 23 ▶sub _bind_local_streams {
Subroutine _bind_local_streams: called CC=6 SCAR=18.9
3015 23 my ($self) = @_;
3016  
3017 23 ▶ return 1 if defined $self->{control_stream_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"control_stream_id"} 0 23 23
3018  
3019 23 my $control = $self->{quic}->open_uni_stream;
3020 23 my $qenc = $self->{quic}->open_uni_stream;
3021 23 my $qdec = $self->{quic}->open_uni_stream;
3022  
3023 23 ▶ croak 'peer did not permit the three required HTTP/3 unidirectional streams'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $control and defined $qenc and defined $qdec 0 23 23
Condition33%2/6
defined $control and defined $qenc and defined $qdec
!ll&&!rl&&r
0023
defined $control and defined $qenc
!ll&&!rl&&r
0023
MC/DC0%0/3
defined $control and defined $qenc and defined $qdec
defined $control defined $qenc defined $qdec
Truth table25%1/4
A and B and C
A= defined $controlB= defined $qencC= defined $qdec
ABCresult
0XX0
10X0
1100
1111
3024 unless defined($control) && defined($qenc) && defined($qdec);
3025  
3026 23 for my $stream ($control, $qenc, $qdec) {
3027 69 $self->{streams}{ $stream->id } = $stream;
3028 }
3029  
3030 $self->{native}->bind_streams(
3031 23 $control->id,
3032 $qenc->id,
3033 $qdec->id,
3034 );
3035  
3036 23 $self->{control_stream_id} = $control->id;
3037 23 $self->{qpack_encoder_stream_id} = $qenc->id;
3038 23 $self->{qpack_decoder_stream_id} = $qdec->id;
3039 23 return 1;
3040 }
3041  
3042 23 ▶sub start {
Subroutine start: called CC=15 SCAR=29.5
Pod undocumented
3043 23 my ($self) = @_;
3044  
3045 23 ▶ if ($self->{started}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"started"}) 0 23 23
3046 0 $self->_sync_early_data_status;
3047 0 return $self;
3048 }
3049  
3050 23 ▶ my $ready = $self->{quic}->ready ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'quic'}->ready ? : 20 3 23
3051 23 my $early_status = $self->{quic}->early_data_status;
3052  
3053 23 ▶ if (!$ready) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $ready) { } 3 20 23
elsif ($self->{'role'} eq 'server' and $early_status eq 'accepted' and not defined $self->{'remembered_local_settings'}) { } 0 40 40
3054 3 ▶ if ($self->{role} eq 'client') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'role'} eq 'client') { } 2 1 3
3055 croak 'cannot start HTTP/3 0-RTT without remembered_peer_settings'
3056 2 ▶ unless defined $self->{remembered_peer_settings};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"remembered_peer_settings"} 0 2 2
3057 2 ▶ croak "cannot start HTTP/3 before QUIC is ready unless 0-RTT is pending"
Branch: 1 branch
BranchTrueFalseTotal
unless $early_status eq "pending" 0 2 2
3058 unless $early_status eq 'pending';
3059 } else {
3060 croak 'cannot start HTTP/3 server before QUIC is ready without remembered_local_settings'
3061 1 ▶ unless defined $self->{remembered_local_settings};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"remembered_local_settings"} 0 1 1
3062 }
3063  
3064 3 $self->{early_data_started} = 1;
3065 ▶ } elsif (
Condition50%3/6
$self->{"role"} eq "server" and $early_status eq "accepted" and not defined $self->{"remembered_local_settings"}
!ll&&!rl&&r
2000
$self->{"role"} eq "server" and $early_status eq "accepted"
!ll&&!rl&&r
9110
MC/DC0%0/3
$self->{"role"} eq "server" and $early_status eq "accepted" and not defined $self->{"remembered_local_settings"}
$self->{"role"} eq "server" $early_status eq "accepted" not defined $self->{"remembered_local_settings"}
Truth table50%2/4
A and B and not(C)
A= $self->{"role"} eq "server"B= $early_status eq "accepted"C= not defined $self->{"remembered_local_settings"}
ABCresult
0XX0
10X0
1100
1111
3066 $self->{role} eq 'server'
3067 && $early_status eq 'accepted'
3068 && !defined($self->{remembered_local_settings})
3069 ) {
3070 0 croak 'accepted QUIC 0-RTT requires remembered_local_settings for HTTP/3';
3071 }
3072  
3073 23 ▶ if (!defined $self->{quic}->send_buffer_limit) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"quic"}->send_buffer_limit) 22 1 23
3074 22 $self->{quic}->send_buffer_limit($self->{send_buffer_limit});
3075 }
3076  
3077 # A client sending 0-RTT must send its control and QPACK streams in early
3078 # data. A server can receive and parse early request/control streams before
3079 # handshake completion, but its own HTTP/3 streams use 1-RTT and are bound
3080 # once the QUIC connection becomes ready.
3081 23 ▶ if ($ready || $self->{role} eq 'client') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ready or $self->{"role"} eq "client") 22 1 23
Condition100%3/3
$ready or $self->{"role"} eq "client"
l!l&&r!l&&!r
2021
MC/DC100%2/2
$ready or $self->{"role"} eq "client"
$ready $self->{"role"} eq "client"
Truth table100%3/3
A or B
A= $readyB= $self->{"role"} eq "client"
ABresult
1X1
011
000
3082 22 $self->_bind_local_streams;
3083 }
3084  
3085 23 $self->{started} = 1;
3086  
3087 23 my $weak = $self;
3088 23 weaken($weak);
3089  
3090 483 ▶ $self->{quic}->on_stream_activity(sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
3091 483 ▶ return unless defined $weak;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $weak 0 483 483
3092 483 $weak->_service;
3093 23 });
3094  
3095 0 ▶ $self->{quic}->on_stream_available(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
3096 0 ▶ return unless defined $weak;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $weak 0 0 0
3097 0 my ($quic, $kind) = @_;
3098 0 $weak->_service;
3099 0 $weak->_request_stream_available($kind);
3100 23 });
3101  
3102 23 ▶ if ($self->{quic}->can_receive_datagram) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"quic"}->can_receive_datagram) 9 14 23
3103 9 ▶ $self->{quic}->on_datagram(sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
3104 9 my ($quic, $bytes, $early_data) = @_;
3105 9 ▶ return unless defined $weak;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $weak 0 9 9
3106 9 $weak->_receive_quic_datagram($bytes, $early_data);
3107 9 });
3108 }
3109  
3110 23 $self->_service;
3111  
3112 23 return $self;
3113 }
3114  
3115 8 ▶sub _request_stream_available {
Subroutine _request_stream_available: called CC=10 SCAR=23.0
3116 8 my ($self, $kind) = @_;
3117 return unless $self->{role} eq 'client'
3118 && $self->{request_credit_blocked}
3119 && defined($kind) && $kind eq 'bidi'
3120 && !$self->{failed}
3121 && !defined($self->{remote_shutdown_id})
3122 8 ▶ && !$self->{shutdown_started};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "client" and $self->{"request_credit_blocked"} and defined $kind and $kind eq "bidi" and not $self->{"failed"} and not defined $self->{"remote_shutdown_id"} and not $self->{"shutdown_started"} 6 2 8
Condition94%17/18
$self->{"role"} eq "client" and $self->{"request_credit_blocked"} and defined $kind and $kind eq "bidi" and not $self->{"failed"} and not defined $self->{"remote_shutdown_id"} and not $self->{"shutdown_started"}
!ll&&!rl&&r
512
$self->{"role"} eq "client" and $self->{"request_credit_blocked"} and defined $kind and $kind eq "bidi" and not $self->{"failed"} and not defined $self->{"remote_shutdown_id"}
!ll&&!rl&&r
413
$self->{"role"} eq "client" and $self->{"request_credit_blocked"} and defined $kind and $kind eq "bidi" and not $self->{"failed"}
!ll&&!rl&&r
314
$self->{"role"} eq "client" and $self->{"request_credit_blocked"} and defined $kind and $kind eq "bidi"
!ll&&!rl&&r
215
$self->{"role"} eq "client" and $self->{"request_credit_blocked"} and defined $kind
!ll&&!rl&&r
206
$self->{"role"} eq "client" and $self->{"request_credit_blocked"}
!ll&&!rl&&r
116
MC/DC85%6/7
$self->{"role"} eq "client" and $self->{"request_credit_blocked"} and defined $kind and $kind eq "bidi" and not $self->{"failed"} and not defined $self->{"remote_shutdown_id"} and not $self->{"shutdown_started"}
$self->{"role"} eq "client" $self->{"request_credit_blocked"} defined $kind $kind eq "bidi" not $self->{"failed"} not defined $self->{"remote_shutdown_id"} not $self->{"shutdown_started"}
Truth table87%7/8
A and B and C and D and not(E) and not(F) and not(G)
A= $self->{"role"} eq "client"B= $self->{"request_credit_blocked"}C= defined $kindD= $kind eq "bidi"E= not $self->{"failed"}F= not defined $self->{"remote_shutdown_id"}G= not $self->{"shutdown_started"}
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110XX0
111110X0
11111100
11111111
3123  
3124 # This is a one-shot wakeup, not a claim that any stream slot remains.
3125 # Consumers must try request() again and wait for another notification
3126 # if another user of this QUIC connection has consumed the credit.
3127 2 $self->{request_credit_blocked} = 0;
3128 2 ▶ my $callback = $self->{on_request_available} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $callback = $self->{"on_request_available"} or return 1 1 2
3129 1 my $ok = eval { $callback->($self); 1 };
3130 1 ▶ warn "on_request_available callback failed: $@" unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 1 1
3131 1 return;
3132 }
3133  
3134 1 ▶sub _reset_peer_settings_to_defaults {
Subroutine _reset_peer_settings_to_defaults: called CC=1 SCAR=0.0
3135 1 my ($self) = @_;
3136  
3137 1 $self->{peer_max_field_section_size} = $HTTP3_MAX_VARINT;
3138 1 $self->{peer_enable_connect_protocol} = 0;
3139 1 $self->{peer_h3_datagram} = 0;
3140 1 $self->{peer_extension_settings} = {};
3141 1 $self->{peer_settings_wire} = {};
3142 1 $self->{peer_settings_received} = 0;
3143 1 $self->{peer_settings_initialized} = 0;
3144 1 $self->{pending_peer_settings} = undef;
3145 1 $self->{pending_peer_extension_settings} = undef;
3146 1 $self->{peer_settings_parser} = {};
3147 1 return;
3148 }
3149  
3150 1 ▶sub _rollback_rejected_early_data {
Subroutine _rollback_rejected_early_data: called CC=8 SCAR=20.9
3151 1 my ($self) = @_;
3152  
3153 1 ▶ return if $self->{early_data_rollback_done};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"early_data_rollback_done"} 0 1 1
3154 1 ▶ return unless $self->{role} eq 'client';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "client" 0 1 1
3155 1 ▶ return unless $self->{early_data_started};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"early_data_started"} 0 1 1
3156 1 ▶ return unless $self->{quic}->early_data_status eq 'rejected';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"quic"}->early_data_status eq "rejected" 0 1 1
3157 1 ▶ return unless $self->{quic}->ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"quic"}->ready 0 1 1
3158  
3159 1 for my $transaction (values %{ $self->{transactions} }) {
3160 1 ▶ next if $transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal 0 1 1
3161 1 $transaction->_mark_error(
3162 'QUIC 0-RTT was rejected; retry the request only if it is replay-safe',
3163 );
3164 }
3165  
3166 1 $self->{transactions} = {};
3167 1 $self->{ready_transactions} = [];
3168 1 $self->{pending_early_transactions} = [];
3169 1 $self->{pending_early_datagrams} = {};
3170 1 $self->{ready_informational} = [];
3171 1 $self->{streams} = {};
3172 1 $self->{messages} = {};
3173 1 $self->{outgoing} = {};
3174 1 $self->{stream_lifecycle} = {};
3175 1 $self->{trailer_field_section_size} = {};
3176 1 $self->{output_finished} = {};
3177 1 $self->{response_sent} = {};
3178 1 $self->{body_bytes_sent} = {};
3179 1 $self->{rejected_streams} = {};
3180 1 $self->{peer_uni_probe} = {};
3181 1 $self->{core_uni_streams} = {};
3182 1 $self->{ignored_uni_streams} = {};
3183 1 $self->{extension_stream_objects} = {};
3184 1 $self->{control_settings_rewritten} = 0;
3185 1 $self->{control_settings_delta} = 0;
3186 1 $self->{control_settings_pending} = undef;
3187 1 delete $self->{control_stream_id};
3188 1 delete $self->{qpack_encoder_stream_id};
3189 1 delete $self->{qpack_decoder_stream_id};
3190  
3191 $self->{native} = Unblock::HTTP3::_Native->client(
3192 $self->{max_field_section_size},
3193 $self->{qpack_max_table_capacity},
3194 $self->{qpack_blocked_streams},
3195 0,
3196 $self->{enable_http_datagrams},
3197 1 );
3198  
3199 1 $self->_reset_peer_settings_to_defaults;
3200  
3201 1 $self->{started} = 0;
3202 1 $self->{early_data_started} = 0;
3203 1 $self->{early_data_rollback_done} = 1;
3204 1 $self->{early_data_status} = 'rejected';
3205  
3206 1 $self->start;
3207 1 return 1;
3208 }
3209  
3210 0 ▶sub _discard_pending_early_datagrams {
Subroutine _discard_pending_early_datagrams: not called CC=3 SCAR=24.8
3211 0 my ($self, $id) = @_;
3212  
3213 0 my $pending = delete $self->{pending_early_datagrams}{$id};
3214 0 ▶ return unless defined $pending;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pending 0 0 0
3215  
3216 0 for my $bytes (@$pending) {
3217 0 $self->_datagram_dequeued(length($bytes));
3218 }
3219  
3220 0 return;
3221 }
3222  
3223 332 ▶sub _promote_accepted_early_transactions {
Subroutine _promote_accepted_early_transactions: called CC=18 SCAR=34.8
3224 332 my ($self) = @_;
3225  
3226 332 ▶ return unless $self->{role} eq 'server';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "server" 0 332 332
3227 332 ▶ return unless $self->{quic}->ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"quic"}->ready 0 332 332
3228 332 ▶ return if $self->{quic}->early_data_status eq 'rejected';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"quic"}->early_data_status eq "rejected" 0 332 332
3229 332 ▶ return unless @{ $self->{pending_early_transactions} };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"pending_early_transactions"};} 331 1 332
3230  
3231 my @pending =
3232 1 splice @{ $self->{pending_early_transactions} };
3233  
3234 1 for my $transaction (@pending) {
3235 1 ▶ next if $transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal 0 1 1
3236  
3237 1 my $datagrams = 0;
3238 1 ▶ if (defined $self->{datagram_request}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"datagram_request"}) 1 0 1
3239 $datagrams =
3240 1 ▶ $self->{datagram_request}->(
Branch: 1 branch
BranchTrueFalseTotal
$self->{'datagram_request'}->($self, $transaction->request) ? : 1 0 1
3241 $self,
3242 $transaction->request,
3243 ) ? 1 : 0;
3244 }
3245  
3246 1 ▶ $transaction->_enable_datagrams if $datagrams;
Branch: 1 branch
BranchTrueFalseTotal
if $datagrams 1 0 1
3247  
3248 1 my $id = $transaction->stream_id;
3249 1 my $queued = delete $self->{pending_early_datagrams}{$id};
3250  
3251 1 ▶ if (defined $queued && @$queued) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $queued and @$queued) 1 0 1
Condition33%1/3
defined $queued and @$queued
!ll&&!rl&&r
001
MC/DC0%0/2
defined $queued and @$queued
defined $queued @$queued
Truth table33%1/3
A and B
A= defined $queuedB= @$queued
ABresult
0X0
100
111
3252 1 ▶ if (!$datagrams) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($datagrams) 0 1 1
3253 0 for my $bytes (@$queued) {
3254 0 $self->_datagram_dequeued(length($bytes));
3255 }
3256  
3257 $self->_reject_datagram_stream(
3258 0 $transaction,
3259 'received HTTP Datagram for a request without datagram semantics',
3260 );
3261 0 next;
3262 }
3263  
3264 1 for my $bytes (@$queued) {
3265 1 $self->_datagram_dequeued(length($bytes));
3266 1 $transaction->_receive_datagram($bytes);
3267 }
3268 }
3269  
3270 $self->_enqueue_delivery(
3271 'ready_transactions',
3272 $transaction,
3273 1 ▶ defined($self->{callbacks}{on_request}) ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'callbacks'}{'on_request'} ? : 0 1 1
3274 );
3275  
3276 1 ▶ if (defined $self->{callbacks}{on_request}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"callbacks"}{"on_request"}) 0 1 1
3277 0 my $result = $transaction->_invoke(
3278 'on_request',
3279 $transaction->request,
3280 );
3281 0 ▶ die $result unless $result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 0 0 0
3282 }
3283 }
3284  
3285 1 return 1;
3286 }
3287  
3288 0 ▶sub _reject_pending_early_transactions {
Subroutine _reject_pending_early_transactions: not called CC=5 SCAR=34.0
3289 0 my ($self) = @_;
3290  
3291 0 ▶ return unless $self->{role} eq 'server';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "server" 0 0 0
3292 0 ▶ return unless @{ $self->{pending_early_transactions} };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"pending_early_transactions"};} 0 0 0
3293  
3294 my @pending =
3295 0 splice @{ $self->{pending_early_transactions} };
3296  
3297 0 for my $transaction (@pending) {
3298 0 my $id = $transaction->stream_id;
3299 0 $self->_discard_pending_early_datagrams($id);
3300  
3301 0 ▶ $transaction->_mark_error(
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->is_terminal 0 0 0
3302 'QUIC rejected 0-RTT before HTTP request processing',
3303 ) unless $transaction->is_terminal;
3304 }
3305  
3306 0 return 1;
3307 }
3308  
3309 656 ▶sub _sync_early_data_status {
Subroutine _sync_early_data_status: called CC=7 SCAR=19.5
3310 656 my ($self) = @_;
3311  
3312 656 my $status = $self->{quic}->early_data_status;
3313 656 my $previous = $self->{early_data_status};
3314 656 $self->{early_data_status} = $status;
3315  
3316 656 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"role"} eq "client" and $self->{"early_data_started"} and $status eq "rejected") 1 655 656
Condition100%6/6
$self->{"role"} eq "client" and $self->{"early_data_started"} and $status eq "rejected"
!ll&&!rl&&r
642131
$self->{"role"} eq "client" and $self->{"early_data_started"}
!ll&&!rl&&r
35129114
MC/DC100%3/3
$self->{"role"} eq "client" and $self->{"early_data_started"} and $status eq "rejected"
$self->{"role"} eq "client" $self->{"early_data_started"} $status eq "rejected"
Truth table100%4/4
A and B and C
A= $self->{"role"} eq "client"B= $self->{"early_data_started"}C= $status eq "rejected"
ABCresult
0XX0
10X0
1100
1111
3317 $self->{role} eq 'client'
3318 && $self->{early_data_started}
3319 && $status eq 'rejected'
3320 ) {
3321 1 return $self->_rollback_rejected_early_data;
3322 }
3323  
3324 655 ▶ if ($self->{role} eq 'server') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"role"} eq "server") 351 304 655
3325 351 ▶ if ($status eq 'rejected') {
Branch: 2 branches
BranchTrueFalseTotal
if ($status eq 'rejected') { } 0 351 351
elsif ($self->{'quic'}->ready) { } 332 19 351
3326 0 $self->_reject_pending_early_transactions;
3327 } elsif ($self->{quic}->ready) {
3328 332 $self->_promote_accepted_early_transactions;
3329 }
3330 }
3331  
3332 655 return 0;
3333 }
3334  
3335 284 ▶sub _now_ns {
Subroutine _now_ns: called CC=1 SCAR=0.0
3336 return int(
3337 284 Time::HiRes::clock_gettime(Time::HiRes::CLOCK_MONOTONIC())
3338 * 1_000_000_000
3339 );
3340 }
3341  
3342 615 ▶sub _service {
Subroutine _service: called CC=20 SCAR=31.0
3343 615 my ($self) = @_;
3344  
3345 615 ▶ return unless $self->{started};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"started"} 0 615 615
3346 615 ▶ return if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 0 615 615
3347  
3348 615 my $restarted = $self->_sync_early_data_status;
3349 return if !$self->{quic}->ready
3350 615 ▶ && $self->{quic}->early_data_status eq 'rejected';
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"quic"}->ready and $self->{"quic"}->early_data_status eq "rejected" 0 615 615
Condition66%2/3
not $self->{"quic"}->ready and $self->{"quic"}->early_data_status eq "rejected"
!ll&&!rl&&r
594210
MC/DC0%0/2
not $self->{"quic"}->ready and $self->{"quic"}->early_data_status eq "rejected"
not $self->{"quic"}->ready $self->{"quic"}->early_data_status eq "rejected"
Truth table66%2/3
not(A) and B
A= not $self->{"quic"}->readyB= $self->{"quic"}->early_data_status eq "rejected"
ABresult
0X0
100
111
3351 615 ▶ return if $restarted;
Branch: 1 branch
BranchTrueFalseTotal
if $restarted 0 615 615
3352  
3353 615 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"role"} eq "server" and $self->{"quic"}->ready and not defined $self->{"control_stream_id"}) 1 614 615
Condition100%6/6
$self->{"role"} eq "server" and $self->{"quic"}->ready and not defined $self->{"control_stream_id"}
!ll&&!rl&&r
2833311
$self->{"role"} eq "server" and $self->{"quic"}->ready
!ll&&!rl&&r
26419332
MC/DC100%3/3
$self->{"role"} eq "server" and $self->{"quic"}->ready and not defined $self->{"control_stream_id"}
$self->{"role"} eq "server" $self->{"quic"}->ready not defined $self->{"control_stream_id"}
Truth table100%4/4
A and B and not(C)
A= $self->{"role"} eq "server"B= $self->{"quic"}->readyC= not defined $self->{"control_stream_id"}
ABCresult
0XX0
10X0
1100
1111
3354 $self->{role} eq 'server'
3355 && $self->{quic}->ready
3356 && !defined($self->{control_stream_id})
3357 ) {
3358 1 $self->_bind_local_streams;
3359 }
3360  
3361 615 ▶ if ($self->{servicing}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"servicing"}) 0 615 615
3362 0 $self->{service_again} = 1;
3363 0 return;
3364 }
3365  
3366 615 $self->{servicing} = 1;
3367  
3368 615 my $ok = eval {
3369 do {
3370 615 $self->{service_again} = 0;
3371  
3372 615 my @new_ids;
3373  
3374 615 ▶ while (my $stream = $self->{quic}->next_stream) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $stream = $self->{"quic"}->next_stream) 92 615 707
3375 92 $self->{streams}{ $stream->id } = $stream;
3376 92 push @new_ids, $stream->id;
3377 }
3378  
3379 615 for my $id (@new_ids) {
3380 92 ▶ last if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 0 92 92
3381 92 $self->_service_stream($id);
3382 }
3383  
3384 615 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"failed"} and defined(my $id = $self->{"quic"}->next_active_stream_id)) 557 615 1172
Condition100%3/3
not $self->{"failed"} and defined(my $id = $self->{"quic"}->next_active_stream_id)
!ll&&!rl&&r
6609557
MC/DC100%2/2
not $self->{"failed"} and defined(my $id = $self->{"quic"}->next_active_stream_id)
not $self->{"failed"} defined(my $id = $self->{"quic"}->next_active_stream_id)
Truth table100%3/3
not(A) and B
A= not $self->{"failed"}B= defined(my $id = $self->{"quic"}->next_active_stream_id)
ABresult
0X0
100
111
3385 !$self->{failed}
3386 && defined(my $id = $self->{quic}->next_active_stream_id)
3387 ) {
3388 557 $self->_service_stream($id);
3389 }
3390  
3391 615 ▶ if (!$self->{failed}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"failed"}) 609 6 615
3392 609 $self->_drain_events;
3393 $self->_drain_output
3394 609 ▶ if defined $self->{control_stream_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"control_stream_id"} 590 19 609
3395 }
3396 615 ▶ } while ($self->{service_again} && !$self->{failed});
Branch: 1 branch
BranchTrueFalseTotal
$self->{"service_again"} and not $self->{"failed"} and do { do { $self->{"service_again"} = 0; my @new_ids; while (my $stream = $self->{"quic"}->next_stream) { do { $self->{"streams"}{$stream->id} = $stream; push @new_ids, $stream->id }; } ; foreach my $id (@new_ids) { last if $self->{"failed"}; $self->_service_stream($id); } ; while (not $self->{"failed"} and defined(my $id = $self->{"quic"}->next_active_stream_id)) { do { $self->_service_stream($id) }; } ; unless ($self->{"failed"}) { $self->_drain_events; $self->_drain_output if defined $self->{"control_stream_id"}; } } } 0 615 615
Condition33%1/3
$self->{"service_again"} and not $self->{"failed"}
!ll&&!rl&&r
61500
MC/DC0%0/2
$self->{"service_again"} and not $self->{"failed"}
$self->{"service_again"} not $self->{"failed"}
Truth table33%1/3
A and not(B)
A= $self->{"service_again"}B= not $self->{"failed"}
ABresult
0X0
100
111
3397  
3398 615 1;
3399 };
3400  
3401 615 my $error = $@;
3402 615 $self->{servicing} = 0;
3403  
3404 615 ▶ die $error unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 615 615
3405 615 return;
3406 }
3407  
3408 4 ▶sub _service_ignored_uni_stream {
Subroutine _service_ignored_uni_stream: called CC=5 SCAR=16.1
3409 4 my ($self, $id, $stream) = @_;
3410  
3411 4 ▶ if ($stream->can_receive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream->can_receive) 4 0 4
3412 4 ▶ while (my $chunk = $stream->next_data_chunk) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $chunk = $stream->next_data_chunk) 2 4 6
3413 2 my ($bytes) = @$chunk;
3414 2 ▶ $stream->consume(length($bytes))
Branch: 1 branch
BranchTrueFalseTotal
if length $bytes 1 1 2
3415 if length($bytes);
3416 }
3417 }
3418  
3419 4 ▶ if ($stream->closed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream->closed) 1 3 4
3420 1 delete $self->{streams}{$id};
3421 1 delete $self->{ignored_uni_streams}{$id};
3422 1 delete $self->{peer_uni_probe}{$id};
3423 }
3424  
3425 4 return;
3426 }
3427  
3428 14 ▶sub _service_extension_stream {
Subroutine _service_extension_stream: called CC=6 SCAR=18.0
3429 14 my ($self, $id, $stream, $extension) = @_;
3430  
3431 14 ▶ if ($stream->can_receive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream->can_receive) 8 6 14
3432 8 $extension->_drain_receive;
3433 }
3434  
3435 14 ▶ if ($stream->can_send) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream->can_send) 6 8 14
3436 6 $extension->_drain_send;
3437 }
3438  
3439 14 my $remote_reset = $stream->remote_reset_code;
3440 14 ▶ $extension->_mark_reset($remote_reset)
Branch: 1 branch
BranchTrueFalseTotal
if defined $remote_reset 0 14 14
3441 if defined $remote_reset;
3442  
3443 14 my $remote_stop = $stream->remote_stop_sending_code;
3444 14 ▶ $extension->_mark_stop($remote_stop)
Branch: 1 branch
BranchTrueFalseTotal
if defined $remote_stop 0 14 14
3445 if defined $remote_stop;
3446  
3447 14 ▶ if ($stream->closed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream->closed) 5 9 14
3448 5 delete $self->{streams}{$id};
3449 5 delete $self->{extension_stream_objects}{$id};
3450 5 delete $self->{peer_uni_probe}{$id};
3451 }
3452  
3453 14 return;
3454 }
3455  
3456 53 ▶sub _classify_peer_uni_stream {
Subroutine _classify_peer_uni_stream: called CC=22 SCAR=37.1
3457 53 my ($self, $id, $stream) = @_;
3458  
3459 53 ▶ my $state = $self->{peer_uni_probe}{$id} ||= {
Condition50%1/2
$self->{"peer_uni_probe"}{$id} ||= {"buffer", "", "fin", 0}
l!l
530
MC/DC0%0/1
$self->{"peer_uni_probe"}{$id} ||= {"buffer", "", "fin", 0}
$self->{"peer_uni_probe"}{$id}
Truth table50%1/2
A
A= $self->{"peer_uni_probe"}{$id}
Aresult
11
00
3460 buffer => '',
3461 fin => 0,
3462 };
3463  
3464 53 while (1) {
3465 my ($type, $type_length) =
3466 106 _decode_http3_varint($state->{buffer}, 0);
3467  
3468 106 ▶ if (defined $type) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type) 53 53 106
3469 53 ▶ if ($self->{role} eq 'client' && $type eq '1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"role"} eq "client" and $type eq 1) 1 52 53
Condition100%3/3
$self->{"role"} eq "client" and $type eq 1
!ll&&!rl&&r
29231
MC/DC100%2/2
$self->{"role"} eq "client" and $type eq 1
$self->{"role"} eq "client" $type eq 1
Truth table100%3/3
A and B
A= $self->{"role"} eq "client"B= $type eq 1
ABresult
0X0
100
111
3470 $stream->consume(length($state->{buffer}))
3471 1 ▶ if length($state->{buffer});
Branch: 1 branch
BranchTrueFalseTotal
if length $state->{"buffer"} 1 0 1
3472  
3473 1 delete $self->{peer_uni_probe}{$id};
3474  
3475 1 $self->_fail_connection(
3476 $H3_ID_ERROR,
3477 'peer opened a push stream without advertised push capacity',
3478 );
3479  
3480 1 return 'failed';
3481 }
3482  
3483 52 ▶ if ($CORE_STREAM_TYPE{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CORE_STREAM_TYPE{$type}) 49 3 52
3484 49 my $bytes = $state->{buffer};
3485 49 my $fin = $state->{fin};
3486  
3487 49 delete $self->{peer_uni_probe}{$id};
3488 49 $self->{core_uni_streams}{$id} = 1;
3489  
3490 49 $self->_inspect_peer_settings_bytes($id, $bytes);
3491 49 ▶ return 'failed' if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 1 48 49
3492  
3493 my $result = $self->{native}->read_stream(
3494 48 ▶ $id,
Branch: 1 branch
BranchTrueFalseTotal
$fin ? : 0 48 48
3495 $bytes,
3496 $fin ? 1 : 0,
3497 _now_ns(),
3498 );
3499  
3500 48 ▶ if (@$result > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$result > 1) 0 48 48
3501 0 my ($unused, $lib_error, $app_error, $detail) = @$result;
3502  
3503 0 $self->_fail_connection(
3504 $app_error,
3505 "libnghttp3 read error: $detail ($lib_error)",
3506 );
3507  
3508 0 return 'failed';
3509 }
3510  
3511 48 my $consumed = $result->[0];
3512 48 ▶ $stream->consume($consumed) if $consumed;
Branch: 1 branch
BranchTrueFalseTotal
if $consumed 48 0 48
3513 48 $self->_drain_events;
3514  
3515 48 return 'core';
3516 }
3517  
3518 3 ▶ if (_is_grease_stream_type($type)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_grease_stream_type($type)) 0 3 3
3519 $stream->consume(length($state->{buffer}))
3520 0 ▶ if length($state->{buffer});
Branch: 1 branch
BranchTrueFalseTotal
if length $state->{"buffer"} 0 0 0
3521  
3522 0 delete $self->{peer_uni_probe}{$id};
3523 0 $self->{ignored_uni_streams}{$id} = 1;
3524  
3525 0 return 'ignored';
3526 }
3527  
3528 3 my $handler = $self->{extension_stream_handlers}{$type};
3529  
3530 3 ▶ if (!defined $handler) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $handler) 1 2 3
3531 $stream->consume(length($state->{buffer}))
3532 1 ▶ if length($state->{buffer});
Branch: 1 branch
BranchTrueFalseTotal
if length $state->{"buffer"} 1 0 1
3533  
3534 1 delete $self->{peer_uni_probe}{$id};
3535 1 $self->{ignored_uni_streams}{$id} = 1;
3536  
3537 1 return 'ignored';
3538 }
3539  
3540 my $payload = substr(
3541 $state->{buffer},
3542 2 $type_length,
3543 );
3544  
3545 2 $stream->consume($type_length);
3546  
3547 2 require Unblock::HTTP3::Extension::Stream;
3548  
3549 my $extension = Unblock::HTTP3::Extension::Stream->_new(
3550 connection => $self,
3551 stream => $stream,
3552 type => $type,
3553 header_length => $type_length,
3554 incoming => 1,
3555 initial => $payload,
3556 initial_fin => $state->{fin},
3557 2 );
3558  
3559 2 delete $self->{peer_uni_probe}{$id};
3560 2 $self->{extension_stream_objects}{$id} = $extension;
3561  
3562 2 $handler->($self, $extension);
3563 2 $extension->_drain_receive;
3564  
3565 2 return 'extension';
3566 }
3567  
3568 53 my $chunk = $stream->next_data_chunk;
3569  
3570 53 ▶ if (!defined $chunk) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chunk) 0 53 53
3571 0 ▶ if ($stream->remote_finished) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream->remote_finished) 0 0 0
3572 $stream->consume(length($state->{buffer}))
3573 0 ▶ if length($state->{buffer});
Branch: 1 branch
BranchTrueFalseTotal
if length $state->{"buffer"} 0 0 0
3574  
3575 0 delete $self->{peer_uni_probe}{$id};
3576 0 $self->{ignored_uni_streams}{$id} = 1;
3577  
3578 0 return 'ignored';
3579 }
3580  
3581 0 return 'pending';
3582 }
3583  
3584 53 my ($bytes, $fin) = @$chunk;
3585 53 $state->{buffer} .= $bytes;
3586 53 ▶ $state->{fin} ||= $fin ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$fin ? : 0 53 53
Condition33%1/3
$state->{"fin"} ||= $fin ? 1 : 0
l!l&&r!l&&!r
0053
MC/DC0%0/2
$state->{"fin"} ||= $fin ? 1 : 0
$state->{"fin"} $fin ? 1 : 0
Truth table33%1/3
A ||= B
A= $state->{"fin"}B= $fin ? 1 : 0
ABresult
1X1
011
000
3587  
3588 53 ▶ if ($fin && !length($state->{buffer})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fin and not length $state->{"buffer"}) 0 53 53
Condition33%1/3
$fin and not length $state->{"buffer"}
!ll&&!rl&&r
5300
MC/DC0%0/2
$fin and not length $state->{"buffer"}
$fin not length $state->{"buffer"}
Truth table33%1/3
A and not(B)
A= $finB= not length $state->{"buffer"}
ABresult
0X0
100
111
3589 0 delete $self->{peer_uni_probe}{$id};
3590 0 $self->{ignored_uni_streams}{$id} = 1;
3591 0 return 'ignored';
3592 }
3593 }
3594 }
3595  
3596 7 ▶sub _is_local_critical_stream {
Subroutine _is_local_critical_stream: called CC=7 SCAR=22.1
3597 7 my ($self, $id) = @_;
3598  
3599 return 1
3600 if defined($self->{control_stream_id})
3601 7 ▶ && $id == $self->{control_stream_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"} 0 7 7
Condition33%1/3
defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"}
!ll&&!rl&&r
070
MC/DC0%0/2
defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"}
defined $self->{"control_stream_id"} $id == $self->{"control_stream_id"}
Truth table33%1/3
A and B
A= defined $self->{"control_stream_id"}B= $id == $self->{"control_stream_id"}
ABresult
0X0
100
111
3602 return 1
3603 if defined($self->{qpack_encoder_stream_id})
3604 7 ▶ && $id == $self->{qpack_encoder_stream_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"qpack_encoder_stream_id"} and $id == $self->{"qpack_encoder_stream_id"} 1 6 7
Condition66%2/3
defined $self->{"qpack_encoder_stream_id"} and $id == $self->{"qpack_encoder_stream_id"}
!ll&&!rl&&r
061
MC/DC50%1/2
defined $self->{"qpack_encoder_stream_id"} and $id == $self->{"qpack_encoder_stream_id"}
defined $self->{"qpack_encoder_stream_id"} $id == $self->{"qpack_encoder_stream_id"}
Truth table66%2/3
A and B
A= defined $self->{"qpack_encoder_stream_id"}B= $id == $self->{"qpack_encoder_stream_id"}
ABresult
0X0
100
111
3605 return 1
3606 if defined($self->{qpack_decoder_stream_id})
3607 6 ▶ && $id == $self->{qpack_decoder_stream_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"qpack_decoder_stream_id"} and $id == $self->{"qpack_decoder_stream_id"} 0 6 6
Condition33%1/3
defined $self->{"qpack_decoder_stream_id"} and $id == $self->{"qpack_decoder_stream_id"}
!ll&&!rl&&r
060
MC/DC0%0/2
defined $self->{"qpack_decoder_stream_id"} and $id == $self->{"qpack_decoder_stream_id"}
defined $self->{"qpack_decoder_stream_id"} $id == $self->{"qpack_decoder_stream_id"}
Truth table33%1/3
A and B
A= defined $self->{"qpack_decoder_stream_id"}B= $id == $self->{"qpack_decoder_stream_id"}
ABresult
0X0
100
111
3608  
3609 6 return 0;
3610 }
3611  
3612 649 ▶sub _service_stream {
Subroutine _service_stream: called CC=46 SCAR=38.8
3613 649 my ($self, $id) = @_;
3614  
3615 649 my $stream = $self->{streams}{$id};
3616 649 ▶ return unless defined $stream;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stream 0 649 649
3617  
3618 649 ▶ if (my $extension = $self->{extension_stream_objects}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $extension = $self->{"extension_stream_objects"}{$id}) 12 637 649
3619 12 $self->_service_extension_stream(
3620 $id,
3621 $stream,
3622 $extension,
3623 );
3624 12 return;
3625 }
3626  
3627 637 ▶ if ($self->{ignored_uni_streams}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ignored_uni_streams"}{$id}) 3 634 637
3628 3 $self->_service_ignored_uni_stream($id, $stream);
3629 3 return;
3630 }
3631  
3632 634 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless ($stream->bidirectional or $stream->local_initiated or $self->{"core_uni_streams"}{$id} or exists $self->{"peer_uni_probe"}{$id}) 53 581 634
Condition88%8/9
$stream->bidirectional or $stream->local_initiated or $self->{"core_uni_streams"}{$id} or exists $self->{"peer_uni_probe"}{$id}
l!l&&r!l&&!r
581053
$stream->bidirectional or $stream->local_initiated or $self->{"core_uni_streams"}{$id}
l!l&&r!l&&!r
46012153
$stream->bidirectional or $stream->local_initiated
l!l&&r!l&&!r
352108174
MC/DC75%3/4
$stream->bidirectional or $stream->local_initiated or $self->{"core_uni_streams"}{$id} or exists $self->{"peer_uni_probe"}{$id}
$stream->bidirectional $stream->local_initiated $self->{"core_uni_streams"}{$id} exists $self->{"peer_uni_probe"}{$id}
Truth table80%4/5
A or B or C or D
A= $stream->bidirectionalB= $stream->local_initiatedC= $self->{"core_uni_streams"}{$id}D= exists $self->{"peer_uni_probe"}{$id}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
3633 !$stream->bidirectional
3634 && !$stream->local_initiated
3635 && !$self->{core_uni_streams}{$id}
3636 && !exists($self->{peer_uni_probe}{$id})
3637 ) {
3638 53 $self->{peer_uni_probe}{$id} = {
3639 buffer => '',
3640 fin => 0,
3641 };
3642 }
3643  
3644 634 ▶ if (exists $self->{peer_uni_probe}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"peer_uni_probe"}{$id}) 53 581 634
3645 53 my $kind = $self->_classify_peer_uni_stream(
3646 $id,
3647 $stream,
3648 );
3649  
3650 53 ▶ if ($kind eq 'extension') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "extension") 2 51 53
3651 2 my $extension = $self->{extension_stream_objects}{$id};
3652 2 ▶ $self->_service_extension_stream(
Branch: 1 branch
BranchTrueFalseTotal
if defined $extension 2 0 2
3653 $id,
3654 $stream,
3655 $extension,
3656 ) if defined $extension;
3657 2 return;
3658 }
3659  
3660 51 ▶ if ($kind eq 'ignored') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "ignored") 1 50 51
3661 1 $self->_service_ignored_uni_stream($id, $stream);
3662 1 return;
3663 }
3664  
3665 50 ▶ return if $kind ne 'core';
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "core" 2 48 50
3666 48 ▶ return if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 0 48 48
3667 }
3668  
3669 629 ▶ if ($stream->can_receive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream->can_receive) 521 108 629
3670 521 while (1) {
3671 755 my $chunk = $stream->next_data_chunk;
3672 755 ▶ last unless defined $chunk;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $chunk 519 236 755
3673  
3674 236 my ($bytes, $fin) = @$chunk;
3675  
3676 # Rejected streams still need QUIC reset/close bookkeeping below.
3677 # Discard payload without allowing queued HTTP callbacks to escape.
3678 236 ▶ if ($self->{rejected_streams}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"rejected_streams"}{$id}) 0 236 236
3679 0 ▶ $stream->consume(length($bytes)) if length($bytes);
Branch: 1 branch
BranchTrueFalseTotal
if length $bytes 0 0 0
3680 0 next;
3681 }
3682  
3683 236 $self->_inspect_peer_settings_bytes($id, $bytes);
3684 236 ▶ return if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 0 236 236
3685  
3686 my $result = $self->{native}->read_stream(
3687 236 ▶ $id,
Branch: 1 branch
BranchTrueFalseTotal
$fin ? : 59 177 236
3688 $bytes,
3689 $fin ? 1 : 0,
3690 _now_ns(),
3691 );
3692  
3693 236 ▶ if (@$result > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$result > 1) 2 234 236
3694 2 my ($unused, $lib_error, $app_error, $detail) = @$result;
3695  
3696 2 $self->_fail_connection(
3697 $app_error,
3698 "libnghttp3 read error: $detail ($lib_error)",
3699 );
3700 2 return;
3701 }
3702  
3703 234 my $consumed = $result->[0];
3704 234 ▶ $stream->consume($consumed) if $consumed;
Branch: 1 branch
BranchTrueFalseTotal
if $consumed 168 66 234
3705 234 $self->_drain_events;
3706 234 ▶ return if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 0 234 234
3707 }
3708 }
3709  
3710 627 ▶ if ($stream->can_send && !$self->{rejected_streams}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream->can_send and not $self->{"rejected_streams"}{$id}) 434 193 627
Condition100%3/3
$stream->can_send and not $self->{"rejected_streams"}{$id}
!ll&&!rl&&r
16825434
MC/DC100%2/2
$stream->can_send and not $self->{"rejected_streams"}{$id}
$stream->can_send not $self->{"rejected_streams"}{$id}
Truth table100%3/3
A and not(B)
A= $stream->can_sendB= not $self->{"rejected_streams"}{$id}
ABresult
0X0
100
111
3711 # Activity may indicate ACKs or new QUIC send credit. Allow nghttp3
3712 # to retry this stream, but re-block it if QUIC still accepts only
3713 # a partial write. Other streams must remain eligible meanwhile.
3714 434 ▶ if (delete $self->{blocked_output}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $self->{"blocked_output"}{$id}) 9 425 434
3715 9 $self->{native}->unblock_stream($id);
3716 }
3717 434 my $acked_offset = $stream->acked_offset;
3718  
3719 434 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"}) 16 418 434
Condition100%3/3
defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"}
!ll&&!rl&&r
341516
MC/DC100%2/2
defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"}
defined $self->{"control_stream_id"} $id == $self->{"control_stream_id"}
Truth table100%3/3
A and B
A= defined $self->{"control_stream_id"}B= $id == $self->{"control_stream_id"}
ABresult
0X0
100
111
3720 defined($self->{control_stream_id})
3721 && $id == $self->{control_stream_id}
3722 ) {
3723 16 ▶ if (defined $self->{control_settings_pending}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'control_settings_pending'}) { } 0 16 16
elsif ($self->{'control_settings_delta'}) { } 9 7 16
3724 0 $acked_offset = 0;
3725 } elsif ($self->{control_settings_delta}) {
3726 9 my $delta = $self->{control_settings_delta};
3727 9 ▶ $acked_offset = $acked_offset > $delta
Branch: 1 branch
BranchTrueFalseTotal
$acked_offset > $delta ? : 9 0 9
3728 ? $acked_offset - $delta
3729 : 0;
3730 }
3731 }
3732  
3733 $self->{native}->update_ack_offset(
3734 434 $id,
3735 $acked_offset,
3736 );
3737 434 $self->_drain_events;
3738 434 ▶ return if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 0 434 434
3739 434 $self->_drain_body_producers;
3740 }
3741  
3742 627 ▶ my $lifecycle = $self->{stream_lifecycle}{$id} ||= {};
Condition100%2/2
$self->{"stream_lifecycle"}{$id} ||= {}
l!l
459168
MC/DC100%1/1
$self->{"stream_lifecycle"}{$id} ||= {}
$self->{"stream_lifecycle"}{$id}
Truth table100%2/2
A
A= $self->{"stream_lifecycle"}{$id}
Aresult
11
00
3743  
3744 627 my $remote_reset = $stream->remote_reset_code;
3745 627 ▶ if (defined($remote_reset) && !$lifecycle->{remote_reset_seen}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $remote_reset and not $lifecycle->{"remote_reset_seen"}) 12 615 627
Condition100%3/3
defined $remote_reset and not $lifecycle->{"remote_reset_seen"}
!ll&&!rl&&r
607812
MC/DC100%2/2
defined $remote_reset and not $lifecycle->{"remote_reset_seen"}
defined $remote_reset not $lifecycle->{"remote_reset_seen"}
Truth table100%3/3
A and not(B)
A= defined $remote_resetB= not $lifecycle->{"remote_reset_seen"}
ABresult
0X0
100
111
3746 12 $lifecycle->{remote_reset_seen} = 1;
3747 12 $lifecycle->{remote_reset_code} = 0 + $remote_reset;
3748  
3749 12 ▶ if ($self->{core_uni_streams}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"core_uni_streams"}{$id}) 1 11 12
3750 1 $self->_fail_connection(
3751 $H3_CLOSED_CRITICAL_STREAM,
3752 'peer reset a critical HTTP/3 stream',
3753 );
3754 1 return;
3755 }
3756  
3757 11 $self->{native}->shutdown_stream_read($id);
3758  
3759 11 my $transaction = $self->{transactions}{$id};
3760 11 ▶ if (defined $transaction) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $transaction) 9 2 11
3761 9 $transaction->_mark_remote_reset($remote_reset);
3762 9 ▶ $transaction->_mark_cancelled
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->is_terminal 2 7 9
3763 unless $transaction->is_terminal;
3764 }
3765 }
3766  
3767 626 my $remote_stop = $stream->remote_stop_sending_code;
3768 626 ▶ if (defined($remote_stop) && !$lifecycle->{remote_stop_seen}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $remote_stop and not $lifecycle->{"remote_stop_seen"}) 7 619 626
Condition100%3/3
defined $remote_stop and not $lifecycle->{"remote_stop_seen"}
!ll&&!rl&&r
607127
MC/DC100%2/2
defined $remote_stop and not $lifecycle->{"remote_stop_seen"}
defined $remote_stop not $lifecycle->{"remote_stop_seen"}
Truth table100%3/3
A and not(B)
A= defined $remote_stopB= not $lifecycle->{"remote_stop_seen"}
ABresult
0X0
100
111
3769 7 $lifecycle->{remote_stop_seen} = 1;
3770 7 $lifecycle->{remote_stop_sending_code} = 0 + $remote_stop;
3771  
3772 7 ▶ if ($self->_is_local_critical_stream($id)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_local_critical_stream($id)) 1 6 7
3773 1 $self->_fail_connection(
3774 $H3_CLOSED_CRITICAL_STREAM,
3775 'peer requested closure of a critical HTTP/3 stream',
3776 );
3777 1 return;
3778 }
3779  
3780 6 $self->{native}->shutdown_stream_write($id);
3781 6 $self->{native}->discard_body($id);
3782  
3783 6 my $transaction = $self->{transactions}{$id};
3784 6 ▶ if (defined $transaction) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $transaction) 5 1 6
3785 5 $transaction->_mark_remote_stop_sending($remote_stop);
3786 5 ▶ $transaction->_mark_cancelled
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->is_terminal 5 0 5
3787 unless $transaction->is_terminal;
3788 }
3789 }
3790  
3791 625 ▶ if ($stream->closed && !$lifecycle->{closed_seen}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream->closed and not $lifecycle->{"closed_seen"}) 65 560 625
Condition66%2/3
$stream->closed and not $lifecycle->{"closed_seen"}
!ll&&!rl&&r
560065
MC/DC50%1/2
$stream->closed and not $lifecycle->{"closed_seen"}
$stream->closed not $lifecycle->{"closed_seen"}
Truth table66%2/3
A and not(B)
A= $stream->closedB= not $lifecycle->{"closed_seen"}
ABresult
0X0
100
111
3792 65 $lifecycle->{closed_seen} = 1;
3793  
3794 65 ▶ if ($self->{core_uni_streams}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"core_uni_streams"}{$id}) 0 65 65
3795 0 $self->_fail_connection(
3796 $H3_CLOSED_CRITICAL_STREAM,
3797 'peer closed a critical HTTP/3 stream',
3798 );
3799 0 return;
3800 }
3801  
3802 $self->_release_peer_bidi_stream_credit(
3803 65 $id,
3804 $stream,
3805 );
3806  
3807 $self->{native}->close_stream(
3808 65 $id,
3809 $remote_reset,
3810 $stream->local_reset_code,
3811 );
3812  
3813 65 $self->_cleanup_stream_if_done($id);
3814 }
3815  
3816 625 return;
3817 }
3818  
3819 1325 ▶sub _drain_events {
Subroutine _drain_events: called CC=61 SCAR=56.0
3820 1325 my ($self) = @_;
3821  
3822 1325 ▶ while (!$self->{failed} && (my $event = $self->{native}->next_event)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"failed"} and my $event = $self->{"native"}->next_event) 283 1325 1608
Condition66%2/3
not $self->{"failed"} and my $event = $self->{"native"}->next_event
!ll&&!rl&&r
01325283
MC/DC50%1/2
not $self->{"failed"} and my $event = $self->{"native"}->next_event
not $self->{"failed"} my $event = $self->{"native"}->next_event
Truth table66%2/3
not(A) and B
A= not $self->{"failed"}B= my $event = $self->{"native"}->next_event
ABresult
0X0
100
111
3823 283 my ($type, $id, @args) = @$event;
3824  
3825 283 ▶ if ($type eq 'settings') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "settings") 16 267 283
3826 16 $self->{peer_max_field_section_size} = "$args[0]";
3827 16 ▶ $self->{peer_enable_connect_protocol} = $args[1] ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$args[1] ? : 6 10 16
3828 16 ▶ $self->{peer_h3_datagram} = $args[2] ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$args[2] ? : 8 8 16
3829 16 $self->_accept_peer_extension_settings;
3830 16 next;
3831 }
3832  
3833 267 ▶ if ($type eq 'origin') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "origin") 2 265 267
3834 2 ▶ push @{ $self->{peer_origin_pending} }, $args[0]
Branch: 1 branch
BranchTrueFalseTotal
if _valid_origin_serialization($args[0]) 2 0 2
3835 if _valid_origin_serialization($args[0]);
3836 2 next;
3837 }
3838  
3839 265 ▶ if ($type eq 'end_origin') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "end_origin") 1 264 265
3840 $self->{peer_origins} = []
3841 1 ▶ unless defined $self->{peer_origins};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"peer_origins"} 1 0 1
3842  
3843 1 push @{ $self->{peer_origins} },
3844 1 @{ $self->{peer_origin_pending} };
3845  
3846 1 $self->{peer_origin_pending} = [];
3847 1 next;
3848 }
3849  
3850 264 ▶ if ($self->{rejected_streams}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"rejected_streams"}{$id}) 2 262 264
3851 2 ▶ if ($type eq 'data') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'data') { } 2 0 2
elsif ($type eq 'deferred_consume') { } 0 0 0
3852 2 my $stream = $self->{streams}{$id};
3853 2 ▶ $stream->consume(length($args[0]))
Branch: 1 branch
BranchTrueFalseTotal
if defined $stream and length $args[0] and not defined $stream->local_stop_sending_code 0 2 2
Condition33%2/6
defined $stream and length $args[0] and not defined $stream->local_stop_sending_code
!ll&&!rl&&r
020
defined $stream and length $args[0]
!ll&&!rl&&r
002
MC/DC0%0/3
defined $stream and length $args[0] and not defined $stream->local_stop_sending_code
defined $stream length $args[0] not defined $stream->local_stop_sending_code
Truth table25%1/4
A and B and not(C)
A= defined $streamB= length $args[0]C= not defined $stream->local_stop_sending_code
ABCresult
0XX0
10X0
1100
1111
3854 if defined($stream) && length($args[0])
3855 && !defined($stream->local_stop_sending_code);
3856 } elsif ($type eq 'deferred_consume') {
3857 0 my $stream = $self->{streams}{$id};
3858 0 ▶ $stream->consume($args[0])
Branch: 1 branch
BranchTrueFalseTotal
if defined $stream and $args[0] and not defined $stream->local_stop_sending_code 0 0 0
Condition0%0/6
defined $stream and $args[0] and not defined $stream->local_stop_sending_code
!ll&&!rl&&r
000
defined $stream and $args[0]
!ll&&!rl&&r
000
MC/DC0%0/3
defined $stream and $args[0] and not defined $stream->local_stop_sending_code
defined $stream $args[0] not defined $stream->local_stop_sending_code
Truth table0%0/4
A and B and not(C)
A= defined $streamB= $args[0]C= not defined $stream->local_stop_sending_code
ABCresult
0XX0
10X0
1100
1111
3859 if defined($stream) && $args[0]
3860 && !defined($stream->local_stop_sending_code);
3861 }
3862 2 next;
3863 }
3864  
3865 262 ▶ if ($type eq 'headers') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "headers") 70 192 262
3866 70 my ($field_section_size, $fin) = @args;
3867  
3868 70 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($field_section_size > $self->{"max_field_section_size"}) 0 70 70
3869 $field_section_size
3870 > $self->{max_field_section_size}
3871 ) {
3872 0 $self->_fail_connection(
3873 $H3_EXCESSIVE_LOAD,
3874 'HTTP/3 field section exceeds configured limit',
3875 );
3876 0 next;
3877 }
3878  
3879 $self->_finish_headers(
3880 70 ▶ $id,
Branch: 1 branch
BranchTrueFalseTotal
$fin ? : 0 70 70
3881 $fin ? 1 : 0,
3882 );
3883 70 next;
3884 }
3885  
3886 192 ▶ if ($type eq 'data') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "data") 55 137 192
3887 55 my $bytes = $args[0];
3888 55 my $message = $self->{messages}{$id};
3889  
3890 55 ▶ croak "received HTTP/3 DATA before message headers"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message 0 55 55
3891 unless defined $message;
3892  
3893 55 ▶ my $transaction = $self->{transactions}{$id}
Branch: 1 branch
BranchTrueFalseTotal
my $transaction = $self->{"transactions"}{$id} or croak("received HTTP/3 DATA for unknown Transaction") 55 0 55
3894 or croak "received HTTP/3 DATA for unknown Transaction";
3895 55 ▶ if ($transaction->is_terminal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($transaction->is_terminal) 0 55 55
3896 0 my $stream = $self->{streams}{$id};
3897 0 ▶ $stream->consume(length($bytes)) if $stream && length($bytes);
Branch: 1 branch
BranchTrueFalseTotal
if $stream and length $bytes 0 0 0
Condition0%0/3
$stream and length $bytes
!ll&&!rl&&r
000
MC/DC0%0/2
$stream and length $bytes
$stream length $bytes
Truth table0%0/3
A and B
A= $streamB= length $bytes
ABresult
0X0
100
111
3898 0 next;
3899 }
3900 55 $transaction->{receive_started} = 1;
3901 55 ▶ my $kind = $self->{role} eq 'server'
Branch: 1 branch
BranchTrueFalseTotal
$self->{'role'} eq 'server' ? : 24 31 55
3902 ? 'request'
3903 : 'response';
3904 55 my $reader = $transaction->_incoming_body_reader($kind);
3905  
3906 55 ▶ if (defined $reader) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $reader) 29 26 55
3907 29 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($reader->pending_bytes + length($bytes) > $self->{"max_streaming_body_bytes"}) 0 29 29
3908 $reader->pending_bytes + length($bytes)
3909 > $self->{max_streaming_body_bytes}
3910 ) {
3911 0 $self->_receive_body_failure($transaction,
3912 'HTTP/3 streaming body queue exceeds configured limit', length($bytes));
3913 0 next;
3914 }
3915  
3916 29 $reader->_push_owned($bytes);
3917 29 next;
3918 }
3919  
3920 26 my $current = $transaction->_buffered_body_bytes($kind);
3921  
3922 26 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($current + length($bytes) > $self->{"max_buffered_body_bytes"}) 2 24 26
3923 $current + length($bytes)
3924 > $self->{max_buffered_body_bytes}
3925 ) {
3926 2 $self->_receive_body_failure($transaction,
3927 'HTTP/3 buffered body exceeds configured limit', length($bytes));
3928 2 next;
3929 }
3930  
3931 24 $transaction->_append_buffered_body($kind, $bytes);
3932  
3933 24 my $stream = $self->{streams}{$id};
3934 24 ▶ $stream->consume(length($bytes))
Branch: 1 branch
BranchTrueFalseTotal
if defined $stream and length $bytes 24 0 24
Condition33%1/3
defined $stream and length $bytes
!ll&&!rl&&r
0024
MC/DC0%0/2
defined $stream and length $bytes
defined $stream length $bytes
Truth table33%1/3
A and B
A= defined $streamB= length $bytes
ABresult
0X0
100
111
3935 if defined($stream) && length($bytes);
3936  
3937 24 next;
3938 }
3939  
3940 137 ▶ if ($type eq 'deferred_consume') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "deferred_consume") 0 137 137
3941 0 my $stream = $self->{streams}{$id};
3942 0 ▶ $stream->consume($args[0])
Branch: 1 branch
BranchTrueFalseTotal
if defined $stream and $args[0] and not defined $stream->local_stop_sending_code 0 0 0
Condition0%0/6
defined $stream and $args[0] and not defined $stream->local_stop_sending_code
!ll&&!rl&&r
000
defined $stream and $args[0]
!ll&&!rl&&r
000
MC/DC0%0/3
defined $stream and $args[0] and not defined $stream->local_stop_sending_code
defined $stream $args[0] not defined $stream->local_stop_sending_code
Truth table0%0/4
A and B and not(C)
A= defined $streamB= $args[0]C= not defined $stream->local_stop_sending_code
ABCresult
0XX0
10X0
1100
1111
3943 if defined($stream) && $args[0]
3944 && !defined($stream->local_stop_sending_code);
3945 0 next;
3946 }
3947  
3948 137 ▶ if ($type eq 'end_stream') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "end_stream") 58 79 137
3949 58 my $transaction = $self->{transactions}{$id};
3950 58 ▶ if (defined $transaction && !$transaction->is_terminal) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $transaction and not $transaction->is_terminal) 58 0 58
Condition33%1/3
defined $transaction and not $transaction->is_terminal
!ll&&!rl&&r
0058
MC/DC0%0/2
defined $transaction and not $transaction->is_terminal
defined $transaction not $transaction->is_terminal
Truth table33%1/3
A and not(B)
A= defined $transactionB= not $transaction->is_terminal
ABresult
0X0
100
111
3951 58 ▶ my $kind = $self->{role} eq 'server'
Branch: 1 branch
BranchTrueFalseTotal
$self->{'role'} eq 'server' ? : 31 27 58
3952 ? 'request'
3953 : 'response';
3954 58 my $reader = $transaction->_incoming_body_reader($kind);
3955  
3956 58 ▶ if (defined $reader) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $reader) { } 18 40 58
3957 18 my $message = $self->{messages}{$id};
3958 18 ▶ if (defined $message) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $message) 18 0 18
3959 18 $message->freeze_trailers;
3960 18 $message->freeze;
3961 18 $message->mark_complete;
3962 }
3963 18 $reader->_mark_end;
3964 } else {
3965 40 $transaction->_finish_received_message($kind);
3966 }
3967 }
3968  
3969 58 $self->_maybe_complete_transaction($id);
3970 58 next;
3971 }
3972  
3973 79 ▶ if ($type eq 'stop_sending') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "stop_sending") 0 79 79
3974 0 my $stream = $self->{streams}{$id};
3975 0 ▶ if (defined($stream) && $stream->can_receive) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stream and $stream->can_receive) 0 0 0
Condition0%0/3
defined $stream and $stream->can_receive
!ll&&!rl&&r
000
MC/DC0%0/2
defined $stream and $stream->can_receive
defined $stream $stream->can_receive
Truth table0%0/3
A and B
A= defined $streamB= $stream->can_receive
ABresult
0X0
100
111
3976 0 $stream->stop_sending($args[0]);
3977 0 my $transaction = $self->{transactions}{$id};
3978 0 ▶ $transaction->_mark_local_stop_sending($args[0])
Branch: 1 branch
BranchTrueFalseTotal
if defined $transaction 0 0 0
3979 if defined $transaction;
3980 }
3981 0 next;
3982 }
3983  
3984 79 ▶ if ($type eq 'reset_stream') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "reset_stream") 0 79 79
3985 0 my $transaction = $self->{transactions}{$id};
3986 0 ▶ $transaction->_mark_local_reset($args[0])
Branch: 1 branch
BranchTrueFalseTotal
if defined $transaction 0 0 0
3987 if defined $transaction;
3988  
3989 0 my $stream = $self->{streams}{$id};
3990 0 ▶ $stream->reset($args[0])
Branch: 1 branch
BranchTrueFalseTotal
if defined $stream and $stream->can_send 0 0 0
Condition0%0/3
defined $stream and $stream->can_send
!ll&&!rl&&r
000
MC/DC0%0/2
defined $stream and $stream->can_send
defined $stream $stream->can_send
Truth table0%0/3
A and B
A= defined $streamB= $stream->can_send
ABresult
0X0
100
111
3991 if defined($stream) && $stream->can_send;
3992 0 next;
3993 }
3994  
3995 79 ▶ if ($type eq 'begin_trailers') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "begin_trailers") 4 75 79
3996 4 $self->{trailer_field_section_size}{$id} = 0;
3997 4 next;
3998 }
3999  
4000 75 ▶ if ($type eq 'trailer') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "trailer") 6 69 75
4001 6 my $message = $self->{messages}{$id};
4002  
4003 6 ▶ croak "received HTTP/3 trailer before message headers"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message 0 6 6
4004 unless defined $message;
4005  
4006 $self->{trailer_field_section_size}{$id}
4007 6 ▶ = ($self->{trailer_field_section_size}{$id} // 0)
Condition50%1/2
$self->{"trailer_field_section_size"}{$id} // 0
l!l
60
MC/DC0%0/1
$self->{"trailer_field_section_size"}{$id} // 0
$self->{"trailer_field_section_size"}{$id}
Truth table50%1/2
A
A= $self->{"trailer_field_section_size"}{$id}
Aresult
11
00
4008 + length($args[0]) + length($args[1]) + 32;
4009  
4010 6 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"trailer_field_section_size"}{$id} > $self->{"max_field_section_size"}) 0 6 6
4011 $self->{trailer_field_section_size}{$id}
4012 > $self->{max_field_section_size}
4013 ) {
4014 0 $self->_fail_connection(
4015 $H3_EXCESSIVE_LOAD,
4016 'HTTP/3 trailer field section exceeds configured limit',
4017 );
4018 0 next;
4019 }
4020  
4021 $message->add_trailer(
4022 6 $args[0],
4023 $args[1],
4024 );
4025 6 next;
4026 }
4027  
4028 69 ▶ if ($type eq 'end_trailers') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "end_trailers") 4 65 69
4029 4 delete $self->{trailer_field_section_size}{$id};
4030 4 my $message = $self->{messages}{$id};
4031  
4032 4 ▶ if (defined $message) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $message) 4 0 4
4033 4 _coalesce_trailer_cookie_fields($message);
4034 4 $message->freeze_trailers;
4035 }
4036  
4037 4 next;
4038 }
4039  
4040 65 ▶ if ($type eq 'shutdown') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "shutdown") 0 65 65
4041 0 $self->{remote_shutdown_id} = 0 + $id;
4042 0 next;
4043 }
4044  
4045 65 ▶ if ($type eq 'stream_close') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "stream_close") 65 0 65
4046 65 next;
4047 }
4048  
4049 0 croak "unknown native HTTP/3 event '$type'";
4050 }
4051  
4052 1325 return;
4053 }
4054  
4055 5 ▶sub _coalesce_trailer_cookie_fields {
Subroutine _coalesce_trailer_cookie_fields: called CC=2 SCAR=6.9
4056 5 my ($message) = @_;
4057  
4058 5 my $values = $message->trailer_values('cookie');
4059 5 ▶ return unless @$values > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$values > 1 4 1 5
4060  
4061 1 $message->trailer(
4062 'cookie',
4063 join('; ', @$values),
4064 );
4065  
4066 1 return 1;
4067 }
4068  
4069 70 ▶sub _finish_headers {
Subroutine _finish_headers: called CC=64 SCAR=48.9
4070 70 my ($self, $id, $fin) = @_;
4071  
4072 70 my $message;
4073  
4074 70 ▶ if ($self->{role} eq 'server') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'role'} eq 'server') { } 38 32 70
4075 38 my $method = $self->{native}->header_pseudo($id, ':method');
4076  
4077 38 ▶ croak 'HTTP/3 request is missing :method'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $method 0 38 38
4078 unless defined $method;
4079  
4080 38 my $scheme = $self->{native}->header_pseudo($id, ':scheme');
4081 38 my $authority = $self->{native}->header_pseudo($id, ':authority');
4082 38 my $path = $self->{native}->header_pseudo($id, ':path');
4083 38 my $protocol = $self->{native}->header_pseudo($id, ':protocol');
4084 38 ▶ my $is_connect = $method eq 'CONNECT' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$method eq 'CONNECT' ? : 9 29 38
4085 38 ▶ my $is_extended_connect =
Branch: 1 branch
BranchTrueFalseTotal
$is_connect && defined $protocol ? : 7 31 38
Condition100%3/3
$is_connect and defined $protocol
!ll&&!rl&&r
2927
MC/DC100%2/2
$is_connect and defined $protocol
$is_connect defined $protocol
Truth table100%3/3
A and B
A= $is_connectB= defined $protocol
ABresult
0X0
100
111
4086 $is_connect && defined($protocol) ? 1 : 0;
4087 38 my $target;
4088 38 my $host_values = $self->{native}->header_values($id, 'host');
4089  
4090 38 ▶ if ($is_connect && !$is_extended_connect) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_connect and not $is_extended_connect) { } 2 36 38
Condition100%3/3
$is_connect and not $is_extended_connect
!ll&&!rl&&r
2972
MC/DC100%2/2
$is_connect and not $is_extended_connect
$is_connect not $is_extended_connect
Truth table100%3/3
A and not(B)
A= $is_connectB= not $is_extended_connect
ABresult
0X0
100
111
4091 2 ▶ croak 'HTTP/3 CONNECT request is missing :authority'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $authority 0 2 2
4092 unless defined $authority;
4093 2 ▶ croak 'HTTP/3 CONNECT request must not contain :scheme'
Branch: 1 branch
BranchTrueFalseTotal
if defined $scheme 0 2 2
4094 if defined $scheme;
4095 2 ▶ croak 'HTTP/3 CONNECT request must not contain :path'
Branch: 1 branch
BranchTrueFalseTotal
if defined $path 0 2 2
4096 if defined $path;
4097  
4098 2 $target = $authority;
4099  
4100 2 my $semantic_error = _request_semantic_error(
4101 method => 'CONNECT',
4102 scheme => undef,
4103 authority => $authority,
4104 target => $target,
4105 protocol => undef,
4106 host_values => $host_values,
4107 );
4108  
4109 2 ▶ if (defined $semantic_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $semantic_error) 0 2 2
4110 0 $self->_reject_message_stream($id, $semantic_error);
4111 0 return;
4112 }
4113 } else {
4114 36 ▶ if ($is_extended_connect && !$self->{enable_extended_connect}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_extended_connect and not $self->{"enable_extended_connect"}) 0 36 36
Condition66%2/3
$is_extended_connect and not $self->{"enable_extended_connect"}
!ll&&!rl&&r
2970
MC/DC0%0/2
$is_extended_connect and not $self->{"enable_extended_connect"}
$is_extended_connect not $self->{"enable_extended_connect"}
Truth table66%2/3
A and not(B)
A= $is_extended_connectB= not $self->{"enable_extended_connect"}
ABresult
0X0
100
111
4115 0 $self->_reject_message_stream(
4116 $id,
4117 'Extended CONNECT was not enabled by this server',
4118 );
4119 0 return;
4120 }
4121  
4122 36 ▶ if ($is_extended_connect && !defined $path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_extended_connect and not defined $path) 0 36 36
Condition66%2/3
$is_extended_connect and not defined $path
!ll&&!rl&&r
2970
MC/DC0%0/2
$is_extended_connect and not defined $path
$is_extended_connect not defined $path
Truth table66%2/3
A and not(B)
A= $is_extended_connectB= not defined $path
ABresult
0X0
100
111
4123 0 $self->_reject_message_stream(
4124 $id,
4125 'Extended CONNECT requires :path',
4126 );
4127 0 return;
4128 }
4129  
4130 36 ▶ croak 'HTTP/3 request is missing :path'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 36 36
4131 unless defined $path;
4132  
4133 36 $target = $path;
4134  
4135 36 my $semantic_error = _request_semantic_error(
4136 method => $method,
4137 scheme => $scheme,
4138 authority => $authority,
4139 target => $target,
4140 protocol => $protocol,
4141 host_values => $host_values,
4142 );
4143  
4144 36 ▶ if (defined $semantic_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $semantic_error) 1 35 36
4145 1 $self->_reject_message_stream($id, $semantic_error);
4146 1 return;
4147 }
4148  
4149 35 ▶ if (!defined($authority) && @$host_values == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $authority and @$host_values == 1) 0 35 35
Condition33%1/3
not defined $authority and @$host_values == 1
!ll&&!rl&&r
3500
MC/DC0%0/2
not defined $authority and @$host_values == 1
not defined $authority @$host_values == 1
Truth table33%1/3
not(A) and B
A= not defined $authorityB= @$host_values == 1
ABresult
0X0
100
111
4150 0 $authority = $host_values->[0];
4151 }
4152 }
4153  
4154 $message = $self->{native}->receive_uniform_request(
4155 37 $id,
4156 $method,
4157 $target,
4158 $scheme,
4159 $authority,
4160 $protocol,
4161 $fin,
4162 );
4163  
4164 37 my $response = Uniform::HTTP::Response->new(
4165 status => 200,
4166 version => '3',
4167 );
4168  
4169 37 my $stream = $self->{streams}{$id};
4170 37 ▶ my $stream_is_early = defined($stream) && $stream->early_data ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $stream && $stream->early_data ? : 1 36 37
Condition66%2/3
defined $stream and $stream->early_data
!ll&&!rl&&r
0361
MC/DC50%1/2
defined $stream and $stream->early_data
defined $stream $stream->early_data
Truth table66%2/3
A and B
A= defined $streamB= $stream->early_data
ABresult
0X0
100
111
4171  
4172 37 ▶ if ($stream_is_early && !defined($self->{remembered_local_settings})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream_is_early and not defined $self->{"remembered_local_settings"}) 0 37 37
Condition66%2/3
$stream_is_early and not defined $self->{"remembered_local_settings"}
!ll&&!rl&&r
3610
MC/DC0%0/2
$stream_is_early and not defined $self->{"remembered_local_settings"}
$stream_is_early not defined $self->{"remembered_local_settings"}
Truth table66%2/3
A and not(B)
A= $stream_is_earlyB= not defined $self->{"remembered_local_settings"}
ABresult
0X0
100
111
4173 0 $self->_fail_connection(
4174 $H3_SETTINGS_ERROR,
4175 'received HTTP/3 0-RTT request without remembered_local_settings',
4176 );
4177 0 return;
4178 }
4179  
4180 my $transaction = Unblock::HTTP3::Transaction->_new(
4181 connection => $self,
4182 stream_id => $id,
4183 request => $message,
4184 response => $response,
4185 early_data => $stream_is_early,
4186 callbacks => $self->{callbacks},
4187 37 );
4188  
4189 my $request_receive_mode = $is_connect
4190 || defined($self->{callbacks}{on_body})
4191 ? 'stream'
4192 37 ▶ : $self->{receive_body_mode};
Branch: 1 branch
BranchTrueFalseTotal
$is_connect || defined $self->{'callbacks'}{'on_body'} ? : 9 28 37
Condition66%2/3
$is_connect or defined $self->{"callbacks"}{"on_body"}
l!l&&r!l&&!r
9028
MC/DC50%1/2
$is_connect or defined $self->{"callbacks"}{"on_body"}
$is_connect defined $self->{"callbacks"}{"on_body"}
Truth table66%2/3
A or B
A= $is_connectB= defined $self->{"callbacks"}{"on_body"}
ABresult
1X1
011
000
4193  
4194 37 my %request_receive_options;
4195 37 ▶ if (defined $self->{callbacks}{on_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"callbacks"}{"on_body"}) 0 37 37
4196 0 ▶ $request_receive_options{on_data} = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
4197 0 my ($reader, $bytes) = @_;
4198 0 my $result = $transaction->_invoke(
4199 'on_body',
4200 $transaction->request,
4201 $bytes,
4202 );
4203 0 ▶ die $result unless $result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 0 0 0
4204 0 };
4205 }
4206 $transaction->_configure_receive_body(
4207 37 'request',
4208 $request_receive_mode,
4209 \%request_receive_options,
4210 );
4211 37 ▶ $transaction->_ensure_receive_reader('request')
Branch: 1 branch
BranchTrueFalseTotal
if $request_receive_mode eq "stream" 10 27 37
4212 if $request_receive_mode eq 'stream';
4213  
4214 37 $self->{transactions}{$id} = $transaction;
4215  
4216 37 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($stream_is_early and not $self->{'quic'}->ready) { } 1 36 37
Condition66%2/3
$stream_is_early and not $self->{"quic"}->ready
!ll&&!rl&&r
3601
MC/DC50%1/2
$stream_is_early and not $self->{"quic"}->ready
$stream_is_early not $self->{"quic"}->ready
Truth table66%2/3
A and not(B)
A= $stream_is_earlyB= not $self->{"quic"}->ready
ABresult
0X0
100
111
4217 $stream_is_early
4218 && !$self->{quic}->ready
4219 ) {
4220 1 push @{ $self->{pending_early_transactions} }, $transaction;
4221 } else {
4222 36 my $datagrams = 0;
4223 36 ▶ if (defined $self->{datagram_request}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"datagram_request"}) 3 33 36
4224 $datagrams =
4225 3 ▶ $self->{datagram_request}->($self, $message) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'datagram_request'}->($self, $message) ? : 1 2 3
4226 }
4227  
4228 36 ▶ $transaction->_enable_datagrams if $datagrams;
Branch: 1 branch
BranchTrueFalseTotal
if $datagrams 1 35 36
4229 $self->_enqueue_delivery(
4230 'ready_transactions',
4231 $transaction,
4232 36 ▶ defined($self->{callbacks}{on_request}) ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'callbacks'}{'on_request'} ? : 32 4 36
4233 );
4234  
4235 36 ▶ if (defined $self->{callbacks}{on_request}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"callbacks"}{"on_request"}) 32 4 36
4236 32 my $result = $transaction->_invoke(
4237 'on_request',
4238 $transaction->request,
4239 );
4240 32 ▶ die $result unless $result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 0 32 32
4241 }
4242 }
4243 } else {
4244 32 my $status = $self->{native}->header_pseudo($id, ':status');
4245  
4246 32 ▶ croak 'HTTP/3 response is missing :status'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status 0 32 32
4247 unless defined $status;
4248  
4249 32 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"native"}->has_header($id, "capsule-protocol") and not 0 + $status >= 200 && 0 + $status < 300) 0 32 32
Condition50%3/6
$self->{"native"}->has_header($id, "capsule-protocol") and not 0 + $status >= 200 && 0 + $status < 300
!ll&&!rl&&r
3020
0 + $status >= 200 && 0 + $status < 300
!ll&&!rl&&r
002
MC/DC0%0/3
$self->{"native"}->has_header($id, "capsule-protocol") and not 0 + $status >= 200 && 0 + $status < 300
$self->{"native"}->has_header($id, "capsule-protocol") 0 + $status >= 200 0 + $status < 300
Truth table50%2/4
A and not(B && C)
A= $self->{"native"}->has_header($id, "capsule-protocol")B= 0 + $status >= 200C= 0 + $status < 300
ABCresult
0XX0
1110
10X1
1101
4250 $self->{native}->has_header($id, 'capsule-protocol')
4251 && !(0 + $status >= 200 && 0 + $status < 300)
4252 ) {
4253 0 $self->_reject_message_stream(
4254 $id,
4255 'Capsule-Protocol is only valid on a successful HTTP/3 response',
4256 );
4257 0 return;
4258 }
4259  
4260 $message = $self->{native}->receive_uniform_response(
4261 32 $id,
4262 0 + $status,
4263 $fin,
4264 );
4265  
4266 32 ▶ my $transaction = $self->{transactions}{$id}
Branch: 1 branch
BranchTrueFalseTotal
my $transaction = $self->{"transactions"}{$id} or croak("received HTTP/3 response for unknown Transaction") 32 0 32
4267 or croak "received HTTP/3 response for unknown Transaction";
4268  
4269 32 ▶ if ($message->status < 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($message->status < 200) 2 30 32
4270 2 $message->mark_complete;
4271 2 $message->freeze;
4272  
4273 2 ▶ croak 'HTTP/3 does not use 101 Switching Protocols'
Branch: 1 branch
BranchTrueFalseTotal
if $message->status == 101 0 2 2
4274 if $message->status == 101;
4275 2 ▶ croak 'informational HTTP/3 response cannot end the stream'
Branch: 1 branch
BranchTrueFalseTotal
if $fin 0 2 2
4276 if $fin;
4277  
4278 2 $transaction->_push_informational($message);
4279 $self->_enqueue_delivery(
4280 'ready_informational',
4281 $transaction,
4282 2 ▶ defined($transaction->{callbacks}{on_informational}) ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
defined $transaction->{'callbacks'}{'on_informational'} ? : 1 1 2
4283 );
4284 2 my $result = $transaction->_invoke(
4285 'on_informational',
4286 $message,
4287 );
4288 2 ▶ die $result unless $result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $result eq 1 0 2 2
4289 2 return;
4290 }
4291  
4292 30 $transaction->_set_response($message);
4293 30 my $response_result = $transaction->_invoke(
4294 'on_response',
4295 $message,
4296 );
4297 30 ▶ die $response_result unless $response_result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $response_result eq 1 0 30 30
4298 30 ▶ return if $transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal 1 29 30
4299  
4300 29 $transaction->_ensure_receive_reader('response');
4301  
4302 29 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($transaction->request->method eq "CONNECT" and $message->status < 200 || $message->status >= 300) 2 27 29
Condition83%5/6
$transaction->request->method eq "CONNECT" and $message->status < 200 || $message->status >= 300
!ll&&!rl&&r
2252
$message->status < 200 or $message->status >= 300
l!l&&r!l&&!r
025
MC/DC66%2/3
$transaction->request->method eq "CONNECT" and $message->status < 200 || $message->status >= 300
$transaction->request->method eq "CONNECT" $message->status < 200 $message->status >= 300
Truth table75%3/4
A and B or C
A= $transaction->request->method eq "CONNECT"B= $message->status < 200C= $message->status >= 300
ABCresult
0XX0
1000
11X1
1011
4303 $transaction->request->method eq 'CONNECT'
4304 && ($message->status < 200 || $message->status >= 300)
4305 ) {
4306 2 my $writer = $transaction->_request_body_object;
4307 2 ▶ $writer->complete
Branch: 1 branch
BranchTrueFalseTotal
if defined $writer and not $writer->is_complete 2 0 2
Condition33%1/3
defined $writer and not $writer->is_complete
!ll&&!rl&&r
002
MC/DC0%0/2
defined $writer and not $writer->is_complete
defined $writer not $writer->is_complete
Truth table33%1/3
A and not(B)
A= defined $writerB= not $writer->is_complete
ABresult
0X0
100
111
4308 if defined($writer) && !$writer->is_complete;
4309 }
4310  
4311 29 my $callback = $transaction->{callbacks};
4312 $self->_enqueue_delivery(
4313 'ready_transactions',
4314 $transaction,
4315 ($callback->{on_response} || $callback->{on_complete}
4316 || $callback->{on_body} || $callback->{on_data}
4317 29 ▶ || $callback->{on_finish}) ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
$callback->{'on_response'} || $callback->{'on_complete'} || $callback->{'on_body'} || $callback->{'on_data'} || $callback->{'on_finish'} ? : 6 23 29
Condition83%10/12
$callback->{"on_response"} or $callback->{"on_complete"} or $callback->{"on_body"} or $callback->{"on_data"} or $callback->{"on_finish"}
l!l&&r!l&&!r
3323
$callback->{"on_response"} or $callback->{"on_complete"} or $callback->{"on_body"} or $callback->{"on_data"}
l!l&&r!l&&!r
3026
$callback->{"on_response"} or $callback->{"on_complete"} or $callback->{"on_body"}
l!l&&r!l&&!r
3026
$callback->{"on_response"} or $callback->{"on_complete"}
l!l&&r!l&&!r
1226
MC/DC60%3/5
$callback->{"on_response"} or $callback->{"on_complete"} or $callback->{"on_body"} or $callback->{"on_data"} or $callback->{"on_finish"}
$callback->{"on_response"} $callback->{"on_complete"} $callback->{"on_body"} $callback->{"on_data"} $callback->{"on_finish"}
Truth table66%4/6
A or B or C or D or E
A= $callback->{"on_response"}B= $callback->{"on_complete"}C= $callback->{"on_body"}D= $callback->{"on_data"}E= $callback->{"on_finish"}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
4318 );
4319 }
4320  
4321 66 my $lifecycle = $self->{stream_lifecycle}{$id};
4322  
4323 66 my $transaction = $self->{transactions}{$id};
4324  
4325 66 ▶ if (defined($lifecycle) && defined($transaction)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lifecycle and defined $transaction) 29 37 66
Condition66%2/3
defined $lifecycle and defined $transaction
!ll&&!rl&&r
37029
MC/DC50%1/2
defined $lifecycle and defined $transaction
defined $lifecycle defined $transaction
Truth table66%2/3
A and B
A= defined $lifecycleB= defined $transaction
ABresult
0X0
100
111
4326 29 ▶ if (defined $lifecycle->{remote_reset_code}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lifecycle->{"remote_reset_code"}) 0 29 29
4327 $transaction->_mark_remote_reset(
4328 $lifecycle->{remote_reset_code},
4329 0 );
4330 0 ▶ $transaction->_mark_cancelled
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->is_terminal 0 0 0
4331 unless $transaction->is_terminal;
4332 }
4333  
4334 29 ▶ if (defined $lifecycle->{remote_stop_sending_code}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lifecycle->{"remote_stop_sending_code"}) 0 29 29
4335 $transaction->_mark_remote_stop_sending(
4336 $lifecycle->{remote_stop_sending_code},
4337 0 );
4338 0 ▶ $transaction->_mark_cancelled
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->is_terminal 0 0 0
4339 unless $transaction->is_terminal;
4340 }
4341 }
4342  
4343 66 $self->{messages}{$id} = $message;
4344 66 return;
4345 }
4346  
4347 13 ▶sub _validate_wire_field {
Subroutine _validate_wire_field: called CC=5 SCAR=16.1
4348 13 my ($context, $name, $value) = @_;
4349  
4350 croak "HTTP/3 does not allow connection-specific field '$name'"
4351 13 ▶ if $CONNECTION_SPECIFIC_FIELD{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $CONNECTION_SPECIFIC_FIELD{$name} 5 8 13
4352  
4353 8 ▶ if ($name eq 'te') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "te") 4 4 8
4354 4 ▶ croak "HTTP/3 TE is only allowed in request headers"
Branch: 1 branch
BranchTrueFalseTotal
unless $context eq "request" 2 2 4
4355 unless $context eq 'request';
4356  
4357 2 my $normalized = $value;
4358 2 $normalized =~ s/\A[ \t]+//;
4359 2 $normalized =~ s/[ \t]+\z//;
4360  
4361 2 ▶ croak "HTTP/3 TE field may contain only 'trailers'"
Branch: 1 branch
BranchTrueFalseTotal
unless lc $normalized eq "trailers" 1 1 2
4362 unless lc($normalized) eq 'trailers';
4363 }
4364  
4365 5 return;
4366 }
4367  
4368 110 ▶sub _decimal_less_than {
Subroutine _decimal_less_than: called CC=6 SCAR=17.9
4369 110 my ($left, $right) = @_;
4370  
4371 110 $left = "$left";
4372 110 $right = "$right";
4373  
4374 110 $left =~ s/\A0+//;
4375 110 $right =~ s/\A0+//;
4376 110 ▶ $left = '0' if $left eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $left eq "" 1 109 110
4377 110 ▶ $right = '0' if $right eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $right eq "" 7 103 110
4378  
4379 110 ▶ return 1 if length($left) < length($right);
Branch: 1 branch
BranchTrueFalseTotal
if length $left < length $right 0 110 110
4380 110 ▶ return 0 if length($left) > length($right);
Branch: 1 branch
BranchTrueFalseTotal
if length $left > length $right 85 25 110
4381  
4382 25 ▶ return $left lt $right ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$left lt $right ? : 3 22 25
4383 }
4384  
4385 0 ▶sub _field_section_size {
Subroutine _field_section_size: not called CC=2 SCAR=17.9
4386 0 my ($fields) = @_;
4387  
4388 0 my $size = 0;
4389  
4390 0 for my $field (@$fields) {
4391 0 $size += length($field->[0]) + length($field->[1]) + 32;
4392 }
4393  
4394 0 return $size;
4395 }
4396  
4397 77 ▶sub _assert_peer_field_section_size_value {
Subroutine _assert_peer_field_section_size_value: called CC=2 SCAR=6.9
4398 77 my ($self, $size, $operation) = @_;
4399  
4400 77 my $limit = $self->{peer_max_field_section_size};
4401  
4402 77 ▶ croak "$operation: field section size $size exceeds peer "
Branch: 1 branch
BranchTrueFalseTotal
if _decimal_less_than($limit, $size) 1 76 77
4403 . "SETTINGS_MAX_FIELD_SECTION_SIZE $limit"
4404 if _decimal_less_than($limit, $size);
4405  
4406 76 return $size;
4407 }
4408  
4409 0 ▶sub _assert_peer_field_section_size {
Subroutine _assert_peer_field_section_size: not called CC=1 SCAR=6.9
4410 0 my ($self, $fields, $operation) = @_;
4411  
4412 0 return _assert_peer_field_section_size_value(
4413 $self,
4414 _field_section_size($fields),
4415 $operation,
4416 );
4417 }
4418  
4419 9 ▶sub _wire_headers {
Subroutine _wire_headers: called CC=4 SCAR=14.0
4420 9 my ($source, $context) = @_;
4421  
4422 9 ▶ croak 'internal HTTP/3 header context must be request or response'
Branch: 1 branch
BranchTrueFalseTotal
if $context ne "request" and $context ne "response" 0 9 9
Condition66%2/3
$context ne "request" and $context ne "response"
!ll&&!rl&&r
720
MC/DC0%0/2
$context ne "request" and $context ne "response"
$context ne "request" $context ne "response"
Truth table66%2/3
A and B
A= $context ne "request"B= $context ne "response"
ABresult
0X0
100
111
4423 if $context ne 'request' && $context ne 'response';
4424  
4425 9 my @headers;
4426  
4427 9 for my $field (@$source) {
4428 10 my $name = $field->[0];
4429 10 my $value = $field->[1];
4430  
4431 10 $name =~ tr/A-Z/a-z/;
4432  
4433 10 _validate_wire_field($context, $name, $value);
4434 3 push @headers, [ $name, $value ];
4435 }
4436  
4437 2 return \@headers;
4438 }
4439  
4440 3 ▶sub _wire_trailers {
Subroutine _wire_trailers: called CC=5 SCAR=16.6
4441 3 my ($source) = @_;
4442  
4443 3 my @trailers;
4444  
4445 3 for my $field (@$source) {
4446 3 my $name = $field->[0];
4447 3 my $value = $field->[1];
4448  
4449 3 $name =~ tr/A-Z/a-z/;
4450  
4451 3 _validate_wire_field('trailer', $name, $value);
4452  
4453 2 ▶ croak "HTTP/3 TE is not allowed in trailers"
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "te" 0 2 2
4454 if $name eq 'te';
4455 2 ▶ croak "HTTP/3 Content-Length is not allowed in trailers"
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "content-length" 1 1 2
4456 if $name eq 'content-length';
4457 1 ▶ croak "HTTP/3 Host is not allowed in trailers"
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "host" 1 0 1
4458 if $name eq 'host';
4459  
4460 0 push @trailers, [ $name, $value ];
4461 }
4462  
4463 0 return \@trailers;
4464 }
4465  
4466 41 ▶sub _submit_request {
Subroutine _submit_request: called CC=15 SCAR=32.4
4467 41 my ($self, $request, $streaming) = @_;
4468  
4469 croak 'request submission requires a client HTTP/3 connection'
4470 41 ▶ unless $self->{role} eq 'client';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "client" 0 41 41
4471 croak 'HTTP/3 connection has not been started'
4472 41 ▶ unless $self->{started};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"started"} 0 41 41
4473 41 ▶ croak 'request must implement the Uniform HTTP request contract'
Branch: 1 branch
BranchTrueFalseTotal
unless _request_contract($request) 0 41 41
4474 unless _request_contract($request);
4475 croak 'HTTP/3 peer has begun graceful shutdown'
4476 41 ▶ if defined $self->{remote_shutdown_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"remote_shutdown_id"} 0 41 41
4477 croak 'HTTP/3 connection is shutting down'
4478 41 ▶ if $self->{shutdown_notice_sent} || $self->{shutdown_started};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"shutdown_notice_sent"} or $self->{"shutdown_started"} 0 41 41
Condition33%1/3
$self->{"shutdown_notice_sent"} or $self->{"shutdown_started"}
l!l&&r!l&&!r
0041
MC/DC0%0/2
$self->{"shutdown_notice_sent"} or $self->{"shutdown_started"}
$self->{"shutdown_notice_sent"} $self->{"shutdown_started"}
Truth table33%1/3
A or B
A= $self->{"shutdown_notice_sent"}B= $self->{"shutdown_started"}
ABresult
1X1
011
000
4479  
4480 41 my ($portable_fields, $portable_trailers);
4481  
4482 41 ▶ if (ref($request) eq 'Uniform::HTTP::Request') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $request eq 'Uniform::HTTP::Request') { } 41 0 41
4483 $self->_assert_peer_field_section_size_value(
4484 41 $self->{native}->uniform_request_field_section_size($request),
4485 'request()',
4486 );
4487  
4488 my $trailer_size =
4489 40 $self->{native}->uniform_trailer_field_section_size($request);
4490  
4491 40 ▶ $self->_assert_peer_field_section_size_value(
Branch: 1 branch
BranchTrueFalseTotal
if $trailer_size 2 38 40
4492 $trailer_size,
4493 'request trailers',
4494 ) if $trailer_size;
4495 } else {
4496 0 $portable_fields = _portable_request_fields($request);
4497 0 $portable_trailers = _portable_trailers($request);
4498  
4499 0 $self->_assert_peer_field_section_size_value(
4500 _field_section_size($portable_fields),
4501 'request()',
4502 );
4503 0 ▶ $self->_assert_peer_field_section_size_value(
Branch: 1 branch
BranchTrueFalseTotal
if @$portable_trailers 0 0 0
4504 _field_section_size($portable_trailers),
4505 'request trailers',
4506 ) if @$portable_trailers;
4507 }
4508  
4509 40 my $stream = $self->{quic}->open_bidi_stream;
4510 40 ▶ if (!defined $stream) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $stream) 2 38 40
4511 # No local bidirectional QUIC stream was opened, so no HTTP request
4512 # has been submitted. Notify the caller when credit may return.
4513 2 $self->{request_credit_blocked} = 1;
4514 2 return;
4515 }
4516 38 $self->{request_credit_blocked} = 0;
4517  
4518 38 my $id = $stream->id;
4519 38 $self->{streams}{$id} = $stream;
4520  
4521 38 ▶ $streaming = $streaming ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$streaming ? : 15 23 38
4522  
4523 38 ▶ if (ref($request) eq 'Uniform::HTTP::Request') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $request eq 'Uniform::HTTP::Request') { } 38 0 38
4524 $self->{native}->submit_uniform_request(
4525 38 $id,
4526 $request,
4527 $streaming,
4528 );
4529 38 $request->freeze;
4530 } else {
4531 0 ▶ my $body = $request->has_buffered_body
Branch: 1 branch
BranchTrueFalseTotal
$request->has_buffered_body ? : 0 0 0
4532 ? $request->body
4533 : undef;
4534  
4535 $self->{native}->submit_request(
4536 0 $id,
4537 $portable_fields,
4538 $body,
4539 $streaming,
4540 );
4541  
4542 $self->{native}->submit_trailers(
4543 0 ▶ $id,
Branch: 1 branch
BranchTrueFalseTotal
if @$portable_trailers 0 0 0
4544 $portable_trailers,
4545 ) if @$portable_trailers;
4546 }
4547 38 $self->{outgoing}{$id} = $request;
4548  
4549 38 $self->_drain_output;
4550  
4551 38 return $id;
4552 }
4553  
4554 30 ▶sub _submit_response {
Subroutine _submit_response: called CC=13 SCAR=32.0
4555 30 my ($self, $stream_id, $response) = @_;
4556  
4557 croak 'response submission requires a server HTTP/3 connection'
4558 30 ▶ unless $self->{role} eq 'server';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "server" 0 30 30
4559 croak 'HTTP/3 connection has not been started'
4560 30 ▶ unless $self->{started};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"started"} 0 30 30
4561 30 ▶ croak 'response must implement the Uniform HTTP response contract'
Branch: 1 branch
BranchTrueFalseTotal
unless _response_contract($response) 0 30 30
4562 unless _response_contract($response);
4563 croak 'unknown HTTP/3 request stream'
4564 30 ▶ unless defined $self->{streams}{$stream_id};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"streams"}{$stream_id} 0 30 30
4565  
4566 30 my ($portable_fields, $portable_trailers);
4567  
4568 30 ▶ if (ref($response) eq 'Uniform::HTTP::Response') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $response eq 'Uniform::HTTP::Response') { } 30 0 30
4569 $self->_assert_peer_field_section_size_value(
4570 30 $self->{native}->uniform_response_field_section_size($response),
4571 'respond()',
4572 );
4573  
4574 my $trailer_size =
4575 30 $self->{native}->uniform_trailer_field_section_size($response);
4576  
4577 30 ▶ $self->_assert_peer_field_section_size_value(
Branch: 1 branch
BranchTrueFalseTotal
if $trailer_size 2 28 30
4578 $trailer_size,
4579 'response trailers',
4580 ) if $trailer_size;
4581 } else {
4582 0 $portable_fields = _portable_response_fields($response);
4583 0 $portable_trailers = _portable_trailers($response);
4584  
4585 0 $self->_assert_peer_field_section_size_value(
4586 _field_section_size($portable_fields),
4587 'respond()',
4588 );
4589 0 ▶ $self->_assert_peer_field_section_size_value(
Branch: 1 branch
BranchTrueFalseTotal
if @$portable_trailers 0 0 0
4590 _field_section_size($portable_trailers),
4591 'response trailers',
4592 ) if @$portable_trailers;
4593 }
4594  
4595 30 my $transaction = $self->{transactions}{$stream_id};
4596 30 ▶ my $streaming = defined($transaction)
Branch: 1 branch
BranchTrueFalseTotal
defined $transaction && $transaction->_response_is_streaming ? : 9 21 30
Condition66%2/3
defined $transaction and $transaction->_response_is_streaming
!ll&&!rl&&r
0219
MC/DC50%1/2
defined $transaction and $transaction->_response_is_streaming
defined $transaction $transaction->_response_is_streaming
Truth table66%2/3
A and B
A= defined $transactionB= $transaction->_response_is_streaming
ABresult
0X0
100
111
4597 && $transaction->_response_is_streaming
4598 ? 1
4599 : 0;
4600  
4601 30 ▶ if (ref($response) eq 'Uniform::HTTP::Response') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $response eq 'Uniform::HTTP::Response') { } 30 0 30
4602 $self->{native}->submit_uniform_response(
4603 30 $stream_id,
4604 $response,
4605 $streaming,
4606 );
4607 30 $response->freeze;
4608 } else {
4609 0 ▶ my $body = $response->has_buffered_body
Branch: 1 branch
BranchTrueFalseTotal
$response->has_buffered_body ? : 0 0 0
4610 ? $response->body
4611 : undef;
4612  
4613 $self->{native}->submit_response(
4614 0 $stream_id,
4615 $portable_fields,
4616 $body,
4617 $streaming,
4618 );
4619  
4620 $self->{native}->submit_trailers(
4621 0 ▶ $stream_id,
Branch: 1 branch
BranchTrueFalseTotal
if @$portable_trailers 0 0 0
4622 $portable_trailers,
4623 ) if @$portable_trailers;
4624 }
4625  
4626 30 $self->_drain_output;
4627 30 return $response;
4628 }
4629  
4630 701 ▶sub _drain_output {
Subroutine _drain_output: called CC=20 SCAR=30.3
4631 701 my ($self) = @_;
4632  
4633 701 while (1) {
4634 972 ▶ if (my $pending = $self->{control_settings_pending}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pending = $self->{"control_settings_pending"}) 9 963 972
4635 9 my $id = $pending->{id};
4636 9 ▶ my $stream = $self->{streams}{$id}
Branch: 1 branch
BranchTrueFalseTotal
my $stream = $self->{"streams"}{$id} or croak("missing HTTP/3 control stream $id") 9 0 9
4637 or croak "missing HTTP/3 control stream $id";
4638  
4639 my $remaining = substr(
4640 $pending->{bytes},
4641 $pending->{offset},
4642 9 );
4643 9 my $length = length($remaining);
4644 9 ▶ my $accepted = $length
Branch: 1 branch
BranchTrueFalseTotal
$length ? : 9 0 9
4645 ? $stream->send_some($remaining, limit_to_credit => 1)
4646 : 0;
4647  
4648 9 $pending->{offset} += $accepted;
4649  
4650 9 ▶ last if $pending->{offset} < length($pending->{bytes});
Branch: 1 branch
BranchTrueFalseTotal
if $pending->{"offset"} < length $pending->{"bytes"} 0 9 9
4651  
4652 $self->{native}->add_write_offset(
4653 $id,
4654 $pending->{native_length},
4655 9 );
4656  
4657 9 $self->{control_settings_delta} = $pending->{delta};
4658 9 delete $self->{control_settings_pending};
4659 9 next;
4660 }
4661  
4662 963 my $out = $self->{native}->next_write;
4663 963 ▶ last unless defined $out;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $out 701 262 963
4664  
4665 262 my ($id, $bytes, $fin) = @$out;
4666 262 ▶ my $stream = $self->{streams}{$id}
Branch: 1 branch
BranchTrueFalseTotal
my $stream = $self->{"streams"}{$id} or croak("libnghttp3 selected unknown QUIC stream $id") 262 0 262
4667 or croak "libnghttp3 selected unknown QUIC stream $id";
4668  
4669 262 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"control_settings_rewritten"} and defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"} and keys %{$$self{"extension_settings"};}) 9 253 262
Condition77%7/9
not $self->{"control_settings_rewritten"} and defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"} and keys %{$$self{"extension_settings"};}
!ll&&!rl&&r
239149
not $self->{"control_settings_rewritten"} and defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"}
!ll&&!rl&&r
239023
not $self->{"control_settings_rewritten"} and defined $self->{"control_stream_id"}
!ll&&!rl&&r
239023
MC/DC50%2/4
not $self->{"control_settings_rewritten"} and defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"} and keys %{$$self{"extension_settings"};}
not $self->{"control_settings_rewritten"} defined $self->{"control_stream_id"} $id == $self->{"control_stream_id"} keys %{$$self{"extension_settings"};}
Truth table60%3/5
not(A) and B and C and D
A= not $self->{"control_settings_rewritten"}B= defined $self->{"control_stream_id"}C= $id == $self->{"control_stream_id"}D= keys %{$$self{"extension_settings"};}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
4670 !$self->{control_settings_rewritten}
4671 && defined($self->{control_stream_id})
4672 && $id == $self->{control_stream_id}
4673 23 && keys %{ $self->{extension_settings} }
4674 ) {
4675 9 ▶ croak 'HTTP/3 control stream unexpectedly ended with SETTINGS'
Branch: 1 branch
BranchTrueFalseTotal
if $fin 0 9 9
4676 if $fin;
4677  
4678 my ($rewritten, $native_length, $delta) =
4679 _rewrite_control_settings(
4680 $bytes,
4681 $self->{extension_settings},
4682 9 );
4683  
4684 9 $self->{control_settings_rewritten} = 1;
4685 $self->{control_settings_pending} = {
4686 9 id => $id,
4687 bytes => $rewritten,
4688 offset => 0,
4689 native_length => $native_length,
4690 delta => $delta,
4691 };
4692 9 next;
4693 }
4694  
4695 $self->{control_settings_rewritten} = 1
4696 if defined($self->{control_stream_id})
4697 253 ▶ && $id == $self->{control_stream_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"} 15 238 253
Condition66%2/3
defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"}
!ll&&!rl&&r
023815
MC/DC50%1/2
defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"}
defined $self->{"control_stream_id"} $id == $self->{"control_stream_id"}
Truth table66%2/3
A and B
A= defined $self->{"control_stream_id"}B= $id == $self->{"control_stream_id"}
ABresult
0X0
100
111
4698  
4699 253 my $length = length($bytes);
4700 253 my $accepted = 0;
4701  
4702 253 ▶ if ($length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length) 241 12 253
4703 241 $accepted = $stream->send_some($bytes, limit_to_credit => 1);
4704 }
4705  
4706 253 $self->{native}->add_write_offset($id, $accepted);
4707  
4708 253 ▶ if ($fin && $accepted == $length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fin and $accepted == $length) 65 188 253
Condition100%3/3
$fin and $accepted == $length
!ll&&!rl&&r
187165
MC/DC100%2/2
$fin and $accepted == $length
$fin $accepted == $length
Truth table100%3/3
A and B
A= $finB= $accepted == $length
ABresult
0X0
100
111
4709 65 $stream->finish;
4710 65 $self->{output_finished}{$id} = 1;
4711 65 $self->_maybe_complete_transaction($id);
4712 }
4713  
4714 253 ▶ if ($accepted < $length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($accepted < $length) 10 243 253
4715 # nghttp3 otherwise repeatedly chooses a flow-control-blocked
4716 # stream and prevents other H3 streams from making progress.
4717 10 $self->{native}->block_stream($id);
4718 10 $self->{blocked_output}{$id} = 1;
4719 10 next;
4720 }
4721 243 ▶ last if !$length && !$fin;
Branch: 1 branch
BranchTrueFalseTotal
unless $length or $fin 0 243 243
Condition66%2/3
$length or $fin
l!l&&r!l&&!r
231120
MC/DC0%0/2
$length or $fin
$length $fin
Truth table66%2/3
A or B
A= $lengthB= $fin
ABresult
1X1
011
000
4722 }
4723  
4724 701 return;
4725 }
4726  
4727 22 1;
4728  
4729 __END__
↑ Summary blib/lib/Unblock/HTTP3/Capsule/Stream.pm »