blib/lib/Unblock/HTTP3/Connection.pm

filter: Statementstmt 87.4% 1783 / 2039 Branchbran 66.5% 1036 / 1556 Conditioncond 53.4% 415 / 776 MC/DCmcdc 24.8% 107 / 431 Subroutinesub 86.4% 140 / 162 Podpod 0.0% 0 / 42 totaltotal 69.5% 3481 / 5006 CC 1075 SCAR 43.5
CC
1075
Cov
74%
_new
403.3
_drain_events
271.7
request
192.2
CRAP 77.3
↑ Summary blib/lib/Unblock/HTTP3/Capsule/Stream.pm »
1 package Unblock::HTTP3::Connection;
2  
3 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 21 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 21 ▶use Uniform::HTTP::Request 0.06 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 21 ▶use Uniform::HTTP::Response 0.06 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 21 ▶use Scalar::Util qw(blessed isweak weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 21 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 21 ▶use Unblock::HTTP3 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 21 ▶use Unblock::HTTP3::_Native ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 21 ▶use Unblock::HTTP3::Transaction ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 21 ▶use Net::QUIC::Connection ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 21 our $VERSION = '0.13';
17  
18 21 my $H3_DATAGRAM_ERROR = 0x33;
19 21 my $H3_CLOSED_CRITICAL_STREAM = 0x0104;
20 21 my $H3_EXCESSIVE_LOAD = 0x0107;
21 21 my $H3_ID_ERROR = 0x0108;
22 21 my $H3_SETTINGS_ERROR = 0x0109;
23 21 my $QPACK_DECODER_STREAM_ERROR = 0x0202;
24 21 my $H3_REQUEST_CANCELLED = 0x010c;
25 21 my $H3_MESSAGE_ERROR = 0x010e;
26 21 my $HTTP3_MAX_VARINT = '4611686018427387903';
27 21 my $HTTP3_MAX_QUARTER_STREAM_ID = '1152921504606846975';
28 21 my $SETTINGS_STATE_MAGIC = "UH3S";
29 21 my $SETTINGS_STATE_VERSION = 1;
30  
31 21 my %SETTING_DEFAULT = (
32 1 => '0',
33 6 => $HTTP3_MAX_VARINT,
34 7 => '0',
35 8 => '0',
36 51 => '0',
37 );
38  
39 21 my %CORE_SETTING_ID = map { $_ => 1 } qw(1 6 7 8 51);
40 21 my %RESERVED_SETTING_ID = map { $_ => 1 } qw(0 2 3 4 5);
41 21 my %CORE_STREAM_TYPE = map { $_ => 1 } qw(0 1 2 3);
42 21 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 118 ▶sub _is_peer_extension_setting_id {
Subroutine _is_peer_extension_setting_id: called CC=4 SCAR=13.9
85 118 my ($id) = @_;
86  
87 118 ▶ return 0 if $CORE_SETTING_ID{$id};
Branch: 1 branch
BranchTrueFalseTotal
if $CORE_SETTING_ID{$id} 97 21 118
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 29 ▶sub _normalize_extension_stream_handlers {
Subroutine _normalize_extension_stream_handlers: called CC=6 SCAR=18.1
115 29 my ($handlers) = @_;
116  
117 29 ▶ return {} unless defined $handlers;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $handlers 27 2 29
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 169 ▶sub _exceeds_http3_varint {
Subroutine _exceeds_http3_varint: called CC=5 SCAR=16.2
146 169 my ($value) = @_;
147  
148 169 my $text = "$value";
149 169 $text =~ s/\A0+//;
150 169 ▶ $text = '0' if $text eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $text eq "" 4 165 169
151  
152 169 ▶ return 1 if length($text) > length($HTTP3_MAX_VARINT);
Branch: 1 branch
BranchTrueFalseTotal
if length $text > length $HTTP3_MAX_VARINT 0 169 169
153 169 ▶ return 0 if length($text) < length($HTTP3_MAX_VARINT);
Branch: 1 branch
BranchTrueFalseTotal
if length $text < length $HTTP3_MAX_VARINT 167 2 169
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 552 ▶sub _decode_http3_varint {
Subroutine _decode_http3_varint: called CC=7 SCAR=19.5
195 552 my ($bytes, $offset) = @_;
196 552 ▶ $offset ||= 0;
Condition100%2/2
$offset ||= 0
l!l
166386
MC/DC100%1/1
$offset ||= 0
$offset
Truth table100%2/2
A
A= $offset
Aresult
11
00
197  
198 552 ▶ return if $offset >= length($bytes);
Branch: 1 branch
BranchTrueFalseTotal
if $offset >= length $bytes 63 489 552
199  
200 489 my $first = ord(substr($bytes, $offset, 1));
201 489 my $length = (1, 2, 4, 8)[ $first >> 6 ];
202  
203 489 ▶ return if length($bytes) - $offset < $length;
Branch: 1 branch
BranchTrueFalseTotal
if length($bytes) - $offset < $length 8 481 489
204  
205 481 my $value;
206  
207 481 ▶ if ($length == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($length == 1) { } 362 119 481
elsif ($length == 2) { } 86 33 119
elsif ($length == 4) { } 31 2 33
208 362 $value = $first & 0x3f;
209 } elsif ($length == 2) {
210 86 $value = unpack('n', substr($bytes, $offset, 2)) & 0x3fff;
211 } elsif ($length == 4) {
212 31 $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 481 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
17200
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 41 ▶sub _normalize_extension_settings {
Subroutine _normalize_extension_settings: called CC=5 SCAR=16.2
379 41 my ($settings) = @_;
380  
381 41 ▶ return {} unless defined $settings;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $settings 20 21 41
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 298 ▶sub _inspect_peer_settings_bytes {
Subroutine _inspect_peer_settings_bytes: called CC=25 SCAR=32.6
498 298 my ($self, $id, $bytes) = @_;
499  
500 298 ▶ return unless ($id & 0x2) == 0x2;
Branch: 1 branch
BranchTrueFalseTotal
unless ($id & 2) == 2 159 139 298
501  
502 139 my $state = $self->{peer_settings_parser}{$id};
503  
504 139 ▶ if (!defined $state) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $state) 47 92 139
505 47 $state = {
506 stage => 'stream_type',
507 buffer => '',
508 remaining => undef,
509 settings => {},
510 };
511 47 $self->{peer_settings_parser}{$id} = $state;
512 }
513  
514 return if $state->{stage} eq 'ignore'
515 139 ▶ || $state->{stage} eq 'done';
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"stage"} eq "ignore" or $state->{"stage"} eq "done" 68 71 139
Condition100%3/3
$state->{"stage"} eq "ignore" or $state->{"stage"} eq "done"
l!l&&r!l&&!r
67171
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 71 $state->{buffer} .= $bytes;
518  
519 71 while (1) {
520 273 ▶ if ($state->{stage} eq 'stream_type') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"stage"} eq "stream_type") 47 226 273
521 my ($value, $length) =
522 47 _decode_http3_varint($state->{buffer}, 0);
523 47 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 47 47
524  
525 47 substr($state->{buffer}, 0, $length, '');
526  
527 47 ▶ if ($value ne '0') {
Branch: 1 branch
BranchTrueFalseTotal
if ($value ne 0) 28 19 47
528 28 $state->{stage} = 'ignore';
529 28 $state->{buffer} = '';
530 28 return;
531 }
532  
533 19 $state->{stage} = 'frame_type';
534 19 next;
535 }
536  
537 226 ▶ if ($state->{stage} eq 'frame_type') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"stage"} eq "frame_type") 21 205 226
538 my ($value, $length) =
539 21 _decode_http3_varint($state->{buffer}, 0);
540 21 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 2 19 21
541  
542 19 substr($state->{buffer}, 0, $length, '');
543  
544 19 ▶ if ($value ne '4') {
Branch: 1 branch
BranchTrueFalseTotal
if ($value ne 4) 0 19 19
545 0 $state->{stage} = 'ignore';
546 0 $state->{buffer} = '';
547 0 return;
548 }
549  
550 19 $state->{stage} = 'frame_length';
551 19 next;
552 }
553  
554 205 ▶ if ($state->{stage} eq 'frame_length') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"stage"} eq "frame_length") 21 184 205
555 my ($value, $length) =
556 21 _decode_http3_varint($state->{buffer}, 0);
557 21 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 2 19 21
558  
559 19 substr($state->{buffer}, 0, $length, '');
560 19 $state->{remaining} = 0 + $value;
561 19 $state->{stage} = 'setting_id';
562 19 next;
563 }
564  
565 184 ▶ if ($state->{stage} eq 'setting_id') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"stage"} eq "setting_id") 99 85 184
566 99 ▶ if ($state->{remaining} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"remaining"} == 0) 16 83 99
567 my %extension = map {
568 12 $_ => $state->{settings}{$_}
569 } grep {
570 70 _is_peer_extension_setting_id($_)
571 16 } keys %{ $state->{settings} };
572  
573 $self->{pending_peer_settings} = {
574 16 %{ $state->{settings} },
575 };
576 16 $self->{pending_peer_extension_settings} = \%extension;
577 16 $state->{stage} = 'done';
578 16 $state->{buffer} = '';
579 16 return;
580 }
581  
582 my ($value, $length) =
583 83 _decode_http3_varint($state->{buffer}, 0);
584 83 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 9 74 83
585  
586 74 ▶ if ($length > $state->{remaining}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > $state->{"remaining"}) 0 74 74
587 0 $state->{stage} = 'ignore';
588 0 $state->{buffer} = '';
589 0 return;
590 }
591  
592 74 substr($state->{buffer}, 0, $length, '');
593 74 $state->{remaining} -= $length;
594 74 $state->{setting_id} = $value;
595 74 $state->{stage} = 'setting_value';
596 74 next;
597 }
598  
599 85 ▶ if ($state->{stage} eq 'setting_value') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"stage"} eq "setting_value") 85 0 85
600 my ($value, $length) =
601 85 _decode_http3_varint($state->{buffer}, 0);
602 85 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 11 74 85
603  
604 74 ▶ if ($length > $state->{remaining}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > $state->{"remaining"}) 0 74 74
605 0 $state->{stage} = 'ignore';
606 0 $state->{buffer} = '';
607 0 return;
608 }
609  
610 74 substr($state->{buffer}, 0, $length, '');
611 74 $state->{remaining} -= $length;
612  
613 74 my $setting_id = delete $state->{setting_id};
614  
615 74 ▶ if (exists $state->{settings}{$setting_id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $state->{"settings"}{$setting_id}) 1 73 74
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 73 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($setting_id eq 8 || $setting_id eq 51 and $value ne 0 and $value ne 1) 2 71 73
Condition88%8/9
$setting_id eq 8 || $setting_id eq 51 and $value ne 0 and $value ne 1
!ll&&!rl&&r
58132
$setting_id eq 8 || $setting_id eq 51 and $value ne 0
!ll&&!rl&&r
58015
$setting_id eq 8 or $setting_id eq 51
l!l&&r!l&&!r
6958
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 71 $state->{settings}{$setting_id} = $value;
642 71 $state->{stage} = 'setting_id';
643 71 next;
644 }
645  
646 0 croak "unknown peer SETTINGS parser state '$state->{stage}'";
647 }
648 }
649  
650 15 ▶sub _accept_peer_extension_settings {
Subroutine _accept_peer_extension_settings: called CC=10 SCAR=23.4
651 15 my ($self) = @_;
652  
653 15 my $all_settings = delete $self->{pending_peer_settings};
654 15 ▶ $all_settings = {} unless defined $all_settings;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $all_settings 1 14 15
655  
656 15 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"remembered_peer_settings"} and $self->{"quic"}->early_data_status eq "accepted") 1 14 15
Condition100%3/3
defined $self->{"remembered_peer_settings"} and $self->{"quic"}->early_data_status eq "accepted"
!ll&&!rl&&r
1311
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 15 my $settings = delete $self->{pending_peer_extension_settings};
677 15 ▶ $settings = {} unless defined $settings;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $settings 0 15 15
678  
679 15 $self->{peer_settings_wire} = { %$all_settings };
680 15 $self->{peer_extension_settings} = { %$settings };
681 15 $self->{peer_settings_received} = 1;
682 15 $self->{peer_settings_initialized} = 1;
683  
684 15 my $callback = $self->{on_extension_settings};
685 15 ▶ return 1 unless defined $callback;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $callback 12 3 15
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 110 ▶sub _ascii_lc {
Subroutine _ascii_lc: called CC=1 SCAR=0.0
708 110 my ($value) = @_;
709 110 my $copy = "$value";
710 110 $copy =~ tr/A-Z/a-z/;
711 110 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 101 ▶sub _request_semantic_error {
Subroutine _request_semantic_error: called CC=29 SCAR=35.5
746 101 my (%args) = @_;
747  
748 101 my $method = $args{method};
749 101 my $scheme = $args{scheme};
750 101 my $authority = $args{authority};
751 101 my $target = $args{target};
752 101 my $protocol = $args{protocol};
753 101 ▶ my $host_values = $args{host_values} || [];
Condition50%1/2
$args{'host_values'} || []
l!l
1010
MC/DC0%0/1
$args{'host_values'} || []
$args{'host_values'}
Truth table50%1/2
A
A= $args{'host_values'}
Aresult
11
00
754  
755 101 ▶ return 'multiple Host fields are not allowed'
Branch: 1 branch
BranchTrueFalseTotal
if @$host_values > 1 0 101 101
756 if @$host_values > 1;
757  
758 101 ▶ my $host = @$host_values ? $host_values->[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@$host_values ? : 4 97 101
759  
760 101 ▶ if (defined($authority) && defined($host)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $authority and defined $host) 4 97 101
Condition66%2/3
defined $authority and defined $host
!ll&&!rl&&r
0974
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 98 ▶ if (defined($protocol) && $method ne 'CONNECT') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $protocol and $method ne "CONNECT") 1 97 98
Condition100%3/3
defined $protocol and $method ne "CONNECT"
!ll&&!rl&&r
80171
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 97 ▶ if ($method eq 'CONNECT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "CONNECT") 28 69 97
770 28 ▶ if (defined $protocol) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $protocol) { } 17 11 28
771 17 ▶ return 'Extended CONNECT :protocol must be an HTTP token'
Branch: 1 branch
BranchTrueFalseTotal
unless $protocol =~ /\A[!\#\$%&'*+\-.\^_\x60|~0-9A-Za-z]+\z/ 0 17 17
772 unless $protocol =~ /\A[!\#\$%&'*+\-.\^_\x60|~0-9A-Za-z]+\z/;
773 17 ▶ return 'Extended CONNECT requires :scheme'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $scheme 2 15 17
774 unless defined $scheme;
775 15 ▶ return 'Extended CONNECT requires :path'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target and length $target 2 13 15
Condition66%2/3
defined $target and length $target
!ll&&!rl&&r
2013
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 82 ▶ if (defined($scheme) && _ascii_lc($scheme) =~ /\Ahttps?\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $scheme and _ascii_lc($scheme) =~ /\Ahttps?\z/) 82 0 82
Condition33%1/3
defined $scheme and _ascii_lc($scheme) =~ /\Ahttps?\z/
!ll&&!rl&&r
0082
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 82 ▶ my $effective_authority = defined($authority)
Branch: 1 branch
BranchTrueFalseTotal
defined $authority ? : 82 0 82
793 ? $authority
794 : $host;
795  
796 82 ▶ return 'http and https requests require authority'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $effective_authority and length $effective_authority 0 82 82
Condition33%1/3
defined $effective_authority and length $effective_authority
!ll&&!rl&&r
0082
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 82 ▶ return 'http and https authority must not contain userinfo'
Branch: 1 branch
BranchTrueFalseTotal
if $effective_authority =~ /@/ 1 81 82
800 if $effective_authority =~ /@/;
801  
802 81 ▶ return 'http and https :path must not contain a fragment'
Branch: 1 branch
BranchTrueFalseTotal
if $target =~ /#/ 1 80 81
803 if $target =~ /#/;
804  
805 return
806 80 ▶ if $target =~ m{\A/}
Branch: 1 branch
BranchTrueFalseTotal
if $target =~ m[\A/] or $method eq "OPTIONS" and $target eq "*" 78 2 80
Condition83%5/6
$target =~ m[\A/] or $method eq "OPTIONS" and $target eq "*"
l!l&&r!l&&!r
7712
$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 44 ▶sub _assert_request_semantics {
Subroutine _assert_request_semantics: called CC=2 SCAR=7.0
826 44 my ($self, $request, $operation) = @_;
827  
828 44 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 44 ▶ croak "$operation: $error"
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 44 44
838 if defined $error;
839  
840 44 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 30 ▶sub _normalize_origins {
Subroutine _normalize_origins: called CC=8 SCAR=21.5
864 30 my ($origins) = @_;
865  
866 30 ▶ return undef unless defined $origins;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $origins 27 3 30
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 26 ▶sub _serialize_origins {
Subroutine _serialize_origins: called CC=3 SCAR=11.0
891 26 my ($origins) = @_;
892  
893 26 ▶ return undef unless defined $origins;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $origins 25 1 26
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 30 ▶sub _new {
Subroutine _new: called CC=101 SCAR=60.0
906 30 my ($class, $role, %args) = @_;
907  
908 30 my $quic = delete $args{quic};
909 my $send_buffer_limit = exists $args{send_buffer_limit}
910 ? delete $args{send_buffer_limit}
911 30 ▶ : 4 * 1024 * 1024;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'send_buffer_limit'} ? : 2 28 30
912 my $max_field_section_size = exists $args{max_field_section_size}
913 ? delete $args{max_field_section_size}
914 30 ▶ : 65_536;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'max_field_section_size'} ? : 1 29 30
915 my $max_buffered_body_bytes = exists $args{max_buffered_body_bytes}
916 ? delete $args{max_buffered_body_bytes}
917 30 ▶ : 64 * 1024 * 1024;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'max_buffered_body_bytes'} ? : 2 28 30
918 my $max_streaming_body_bytes = exists $args{max_streaming_body_bytes}
919 ? delete $args{max_streaming_body_bytes}
920 30 ▶ : 4 * 1024 * 1024;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'max_streaming_body_bytes'} ? : 0 30 30
921 my $qpack_max_table_capacity = exists $args{qpack_max_table_capacity}
922 ? delete $args{qpack_max_table_capacity}
923 30 ▶ : 4_096;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'qpack_max_table_capacity'} ? : 2 28 30
924 my $qpack_blocked_streams = exists $args{qpack_blocked_streams}
925 ? delete $args{qpack_blocked_streams}
926 30 ▶ : 100;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'qpack_blocked_streams'} ? : 1 29 30
927 my $receive_body = exists $args{receive_body}
928 ? delete $args{receive_body}
929 30 ▶ : 'buffered';
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'receive_body'} ? : 1 29 30
930 my $enable_extended_connect = exists $args{enable_extended_connect}
931 ? delete $args{enable_extended_connect}
932 30 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'enable_extended_connect'} ? : 5 25 30
933 my $enable_http_datagrams = exists $args{enable_http_datagrams}
934 ? delete $args{enable_http_datagrams}
935 30 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'enable_http_datagrams'} ? : 10 20 30
936 30 my $origins = _normalize_origins(delete $args{origins});
937 29 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 29 ▶ : 1024 * 1024;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'max_buffered_datagram_bytes'} ? : 0 29 29
942 my $max_buffered_datagrams =
943 exists $args{max_buffered_datagrams}
944 ? delete $args{max_buffered_datagrams}
945 29 ▶ : 1024;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'max_buffered_datagrams'} ? : 1 28 29
946 29 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 29 ▶ : 100;
Branch: 1 branch
BranchTrueFalseTotal
$has_quic_max_bidi_streams ? : 0 29 29
950 my $extension_settings = _normalize_extension_settings(
951 delete $args{extension_settings},
952 29 );
953 my $remembered_peer_settings_state =
954 29 delete $args{remembered_peer_settings};
955 my $remembered_local_settings_state =
956 29 delete $args{remembered_local_settings};
957 29 ▶ my $remembered_peer_settings = defined($remembered_peer_settings_state)
Branch: 1 branch
BranchTrueFalseTotal
defined $remembered_peer_settings_state ? : 3 26 29
958 ? _decode_settings_state(
959 $remembered_peer_settings_state,
960 'remembered_peer_settings',
961 )
962 : undef;
963 29 ▶ my $remembered_local_settings = defined($remembered_local_settings_state)
Branch: 1 branch
BranchTrueFalseTotal
defined $remembered_local_settings_state ? : 1 28 29
964 ? _decode_settings_state(
965 $remembered_local_settings_state,
966 'remembered_local_settings',
967 )
968 : undef;
969 29 my $on_extension_settings = delete $args{on_extension_settings};
970 29 my $on_request_available = delete $args{on_request_available};
971 29 my %callbacks;
972 29 for my $name (qw(on_request on_body on_request_end on_error)) {
973 116 ▶ next unless exists $args{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{$name} 110 6 116
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 29 ▶ croak 'new(): request callbacks are only valid for a server connection'
Branch: 1 branch
BranchTrueFalseTotal
if $role ne "server" and keys %callbacks 0 29 29
Condition66%2/3
$role ne "server" and keys %callbacks
!ll&&!rl&&r
13160
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 29 );
987  
988 29 ▶ 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 29 29
Condition66%2/3
$role ne "client" and defined $remembered_peer_settings
!ll&&!rl&&r
16130
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 29 ▶ 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 29 29
Condition66%2/3
$role ne "server" and defined $remembered_local_settings
!ll&&!rl&&r
13160
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 29 ▶ 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 29 29
Condition66%2/3
defined $on_extension_settings and ref $on_extension_settings ne "CODE"
!ll&&!rl&&r
2720
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 29 ▶ 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 29 29
Condition33%1/3
defined $on_request_available and ref $on_request_available ne "CODE"
!ll&&!rl&&r
2900
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 29 ▶ 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 29 29
Condition66%2/3
$role ne "client" and defined $on_request_available
!ll&&!rl&&r
16130
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 29 ▶ 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 29 29
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
0029
not defined $enable_extended_connect or ref $enable_extended_connect
l!l&&r!l&&!r
0029
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 29 ▶ croak 'enable_extended_connect is only valid for a server connection'
Branch: 1 branch
BranchTrueFalseTotal
if $role ne "server" and $enable_extended_connect 0 29 29
Condition66%2/3
$role ne "server" and $enable_extended_connect
!ll&&!rl&&r
13160
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 29 ▶ 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 29 29
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
0029
not defined $enable_http_datagrams or ref $enable_http_datagrams
l!l&&r!l&&!r
0029
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 29 ▶ croak 'datagram_request must be a code reference'
Branch: 1 branch
BranchTrueFalseTotal
if defined $datagram_request and ref $datagram_request ne "CODE" 0 29 29
Condition66%2/3
defined $datagram_request and ref $datagram_request ne "CODE"
!ll&&!rl&&r
2540
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 29 ▶ croak 'datagram_request is only valid for a server connection'
Branch: 1 branch
BranchTrueFalseTotal
if $role ne "server" and defined $datagram_request 0 29 29
Condition66%2/3
$role ne "server" and defined $datagram_request
!ll&&!rl&&r
13160
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 29 ▶ croak 'origins is only valid for a server connection'
Branch: 1 branch
BranchTrueFalseTotal
if $role ne "server" and defined $origins 1 28 29
Condition100%3/3
$role ne "server" and defined $origins
!ll&&!rl&&r
13151
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 28 ▶ 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 28 28
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
0028
not defined $quic_max_bidi_streams or ref $quic_max_bidi_streams
l!l&&r!l&&!r
0028
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 28 ▶ 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 28 28
Condition66%2/3
$role ne "server" and $has_quic_max_bidi_streams
!ll&&!rl&&r
13150
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 28 ▶ croak 'quic is required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $quic 0 28 28
1028 unless defined $quic;
1029 28 ▶ croak 'quic must be a Net::QUIC::Connection object'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($quic) and $quic->isa("Net::QUIC::Connection") 0 28 28
Condition33%1/3
builtin::blessed($quic) and $quic->isa("Net::QUIC::Connection")
!ll&&!rl&&r
0028
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 28 ▶ croak 'enable_http_datagrams requires QUIC DATAGRAM receive support'
Branch: 1 branch
BranchTrueFalseTotal
if $enable_http_datagrams and not $quic->can_receive_datagram 1 27 28
Condition100%3/3
$enable_http_datagrams and not $quic->can_receive_datagram
!ll&&!rl&&r
1891
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 27 ▶ 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 27 27
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
0027
defined $send_buffer_limit and not ref $send_buffer_limit and $send_buffer_limit =~ /\A[0-9]+\z/
!ll&&!rl&&r
0027
defined $send_buffer_limit and not ref $send_buffer_limit
!ll&&!rl&&r
0027
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 27 ▶ 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 27 27
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
0027
defined $max_buffered_datagram_bytes and not ref $max_buffered_datagram_bytes and $max_buffered_datagram_bytes =~ /\A[0-9]+\z/
!ll&&!rl&&r
0027
defined $max_buffered_datagram_bytes and not ref $max_buffered_datagram_bytes
!ll&&!rl&&r
0027
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 27 ▶ 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 27 27
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
0027
defined $max_buffered_datagrams and not ref $max_buffered_datagrams and $max_buffered_datagrams =~ /\A[0-9]+\z/
!ll&&!rl&&r
0027
defined $max_buffered_datagrams and not ref $max_buffered_datagrams
!ll&&!rl&&r
0027
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 27 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 81 ▶ 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 81 81
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
0081
defined $limit->[1] and not ref $limit->[1] and $limit->[1] =~ /\A[0-9]+\z/ and $limit->[1] > 0
!ll&&!rl&&r
0081
defined $limit->[1] and not ref $limit->[1] and $limit->[1] =~ /\A[0-9]+\z/
!ll&&!rl&&r
0081
defined $limit->[1] and not ref $limit->[1]
!ll&&!rl&&r
0081
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 27 for my $setting (
1063 [ qpack_max_table_capacity => $qpack_max_table_capacity ],
1064 [ qpack_blocked_streams => $qpack_blocked_streams ],
1065 ) {
1066 54 ▶ 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 54 54
Condition33%2/6
defined $setting->[1] and not ref $setting->[1] and $setting->[1] =~ /\A[0-9]+\z/
!ll&&!rl&&r
0054
defined $setting->[1] and not ref $setting->[1]
!ll&&!rl&&r
0054
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 27 ▶ croak 'max_field_section_size exceeds the HTTP/3 varint maximum'
Branch: 1 branch
BranchTrueFalseTotal
if _exceeds_http3_varint($max_field_section_size) 0 27 27
1073 if _exceeds_http3_varint($max_field_section_size);
1074 27 ▶ croak 'qpack_max_table_capacity exceeds the HTTP/3 varint maximum'
Branch: 1 branch
BranchTrueFalseTotal
if _exceeds_http3_varint($qpack_max_table_capacity) 1 26 27
1075 if _exceeds_http3_varint($qpack_max_table_capacity);
1076 26 ▶ croak 'qpack_blocked_streams exceeds the HTTP/3 varint maximum'
Branch: 1 branch
BranchTrueFalseTotal
if _exceeds_http3_varint($qpack_blocked_streams) 0 26 26
1077 if _exceeds_http3_varint($qpack_blocked_streams);
1078  
1079 26 ▶ 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 26 26
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
0026
not defined $receive_body or ref $receive_body
l!l&&r!l&&!r
0026
$receive_body ne "buffered" and $receive_body ne "stream"
!ll&&!rl&&r
2600
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 26 ▶ croak 'unknown connection option: ' . join(', ', sort keys %args)
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 26 26
1085 if %args;
1086  
1087 26 my %local_settings = (
1088 1 => "$qpack_max_table_capacity",
1089 6 => "$max_field_section_size",
1090 7 => "$qpack_blocked_streams",
1091 );
1092 26 ▶ $local_settings{8} = '1' if $enable_extended_connect;
Branch: 1 branch
BranchTrueFalseTotal
if $enable_extended_connect 5 21 26
1093 26 ▶ $local_settings{51} = '1' if $enable_http_datagrams;
Branch: 1 branch
BranchTrueFalseTotal
if $enable_http_datagrams 9 17 26
1094 26 @local_settings{keys %$extension_settings}
1095 = values %$extension_settings;
1096  
1097 26 my $origin_list = _serialize_origins($origins);
1098  
1099 26 ▶ if (defined $remembered_local_settings) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $remembered_local_settings) 1 25 26
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 26 ▶ my $native = $role eq 'server'
Branch: 1 branch
BranchTrueFalseTotal
$role eq 'server' ? : 13 13 26
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 26 ▶ $native->set_max_client_streams_bidi($quic_max_bidi_streams)
Branch: 1 branch
BranchTrueFalseTotal
if $role eq "server" 13 13 26
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 26 ▶ _is_peer_extension_setting_id($_)
Branch: 7 branches
BranchTrueFalseTotal
defined $remembered_peer_settings ? : 3 23 26
$enable_extended_connect ? : 5 21 26
defined $remembered_peer_settings && _effective_setting($remembered_peer_settings, 8) eq '1' ? : 3 23 26
$enable_http_datagrams ? : 9 17 26
defined $remembered_peer_settings && _effective_setting($remembered_peer_settings, 51) eq '1' ? : 3 23 26
defined $remembered_peer_settings ? : 3 23 26
defined $remembered_peer_settings ? : 3 23 26
Condition66%4/6
defined $remembered_peer_settings and _effective_setting($remembered_peer_settings, 8) eq 1
!ll&&!rl&&r
2303
defined $remembered_peer_settings and _effective_setting($remembered_peer_settings, 51) eq 1
!ll&&!rl&&r
2303
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 54 ▶sub role {
Subroutine role: called CC=2 SCAR=7.1
Pod undocumented
1221 54 my ($self, @args) = @_;
1222 54 ▶ croak 'role() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 54 54
1223 54 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 32 ▶sub failed {
Subroutine failed: called CC=3 SCAR=11.1
Pod undocumented
1252 32 my ($self, @args) = @_;
1253 32 ▶ croak 'failed() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 32 32
1254 32 ▶ return $self->{failed} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'failed'} ? : 10 22 32
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 22 ▶sub peer_settings_received {
Subroutine peer_settings_received: called CC=3 SCAR=11.1
Pod undocumented
1376 22 my ($self, @args) = @_;
1377 22 ▶ croak 'peer_settings_received() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 22 22
1378 22 ▶ return $self->{peer_settings_received} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'peer_settings_received'} ? : 9 13 22
1379 }
1380  
1381 9 ▶sub peer_origins {
Subroutine peer_origins: called CC=3 SCAR=11.0
Pod undocumented
1382 9 my ($self, @args) = @_;
1383 9 ▶ croak 'peer_origins() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 9 9
1384  
1385 9 ▶ return undef unless defined $self->{peer_origins};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"peer_origins"} 5 4 9
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 3 ▶sub peer_extended_connect_enabled {
Subroutine peer_extended_connect_enabled: called CC=3 SCAR=11.1
Pod undocumented
1396 3 my ($self, @args) = @_;
1397 3 ▶ croak 'peer_extended_connect_enabled() does not accept arguments'
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 3 3
1398 if @args;
1399 3 ▶ return $self->{peer_enable_connect_protocol} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'peer_enable_connect_protocol'} ? : 2 1 3
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 46 ▶sub request {
Subroutine request: called CC=70 SCAR=52.6
Pod undocumented
1541 46 my ($self, $request, %option) = @_;
1542  
1543 46 ▶ $self->_sync_early_data_status if $self->{started};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"started"} 39 7 46
1544  
1545 croak 'request() is only available on a client HTTP/3 connection'
1546 46 ▶ unless $self->{role} eq 'client';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "client" 0 46 46
1547 46 ▶ croak 'request() requires the Uniform HTTP request contract'
Branch: 1 branch
BranchTrueFalseTotal
unless _request_contract($request) 0 46 46
1548 unless _request_contract($request);
1549  
1550 46 my %callbacks;
1551 46 for my $name (qw(
1552 on_informational on_response on_body on_data on_finish on_complete on_error on_drain
1553 )) {
1554 368 ▶ next unless exists $option{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $option{$name} 349 19 368
1555 19 my $callback = delete $option{$name};
1556 19 ▶ croak "request(): $name must be a code reference"
Branch: 1 branch
BranchTrueFalseTotal
if defined $callback and ref $callback ne "CODE" 0 19 19
Condition33%1/3
defined $callback and ref $callback ne "CODE"
!ll&&!rl&&r
0190
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 19 ▶ $callbacks{$name} = $callback if defined $callback;
Branch: 1 branch
BranchTrueFalseTotal
if defined $callback 19 0 19
1559 }
1560  
1561 46 _assert_http3_version($request, 'request()');
1562  
1563 46 ▶ my $is_connect = $request->method eq 'CONNECT' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$request->method eq 'CONNECT' ? : 10 36 46
1564 46 ▶ my $is_extended_connect =
Branch: 1 branch
BranchTrueFalseTotal
$is_connect && defined $request->protocol ? : 7 39 46
Condition100%3/3
$is_connect and defined $request->protocol
!ll&&!rl&&r
3637
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 46 my $stream_body = 0;
1567 46 my $receive_body = $self->{receive_body_mode};
1568 46 my $receive_options = {};
1569 my $datagrams = exists $option{datagrams}
1570 ? delete $option{datagrams}
1571 46 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'datagrams'} ? : 3 43 46
1572 my $early_data = exists $option{early_data}
1573 ? delete $option{early_data}
1574 46 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'early_data'} ? : 2 44 46
1575  
1576 46 ▶ 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 46 46
Condition33%2/6
not defined $early_data or ref $early_data or not "$early_data" =~ /\A[01]\z/
l!l&&r!l&&!r
0046
not defined $early_data or ref $early_data
l!l&&r!l&&!r
0046
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 46 ▶ 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 46 46
Condition33%2/6
not defined $datagrams or ref $datagrams or not "$datagrams" =~ /\A[01]\z/
l!l&&r!l&&!r
0046
not defined $datagrams or ref $datagrams
l!l&&r!l&&!r
0046
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 46 ▶ if ($is_connect) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_connect) 10 36 46
1586 10 ▶ if ($is_extended_connect) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_extended_connect) { } 7 3 10
1587 croak 'request(): peer did not enable Extended CONNECT'
1588 7 ▶ unless $self->{peer_enable_connect_protocol};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"peer_enable_connect_protocol"} 1 6 7
1589 6 ▶ croak 'request(): Extended CONNECT requires scheme'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $request->scheme 0 6 6
1590 unless defined $request->scheme;
1591 6 ▶ croak 'request(): Extended CONNECT requires authority'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $request->authority 0 6 6
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 9 ▶ croak 'request(): CONNECT cannot use a buffered request body'
Branch: 1 branch
BranchTrueFalseTotal
if $request->has_buffered_body 0 9 9
1606 if $request->has_buffered_body;
1607 9 ▶ croak 'request(): CONNECT cannot use request trailers'
Branch: 1 branch
BranchTrueFalseTotal
if $request->trailer_count 0 9 9
1608 if $request->trailer_count;
1609  
1610 9 $receive_body = 'stream';
1611 9 $stream_body = 1;
1612 }
1613  
1614 45 ▶ if (exists $option{stream_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option{"stream_body"}) 7 38 45
1615 7 my $configured = delete $option{stream_body};
1616  
1617 7 ▶ 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 6 7
Condition66%4/6
not defined $configured or ref $configured or not "$configured" =~ /\A[01]\z/
l!l&&r!l&&!r
106
not defined $configured or ref $configured
l!l&&r!l&&!r
016
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 6 ▶ $stream_body = $configured ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$configured ? : 6 0 6
1623  
1624 6 ▶ croak 'request(): CONNECT requires stream_body => 1'
Branch: 1 branch
BranchTrueFalseTotal
if $is_connect and not $stream_body 0 6 6
Condition33%1/3
$is_connect and not $stream_body
!ll&&!rl&&r
600
MC/DC0%0/2
$is_connect and not $stream_body
$is_connect not $stream_body
Truth table33%1/3
A and not(B)
A= $is_connectB= not $stream_body
ABresult
0X0
100
111
1625 if $is_connect && !$stream_body;
1626 6 ▶ croak 'request(): stream_body cannot be combined with a buffered body'
Branch: 1 branch
BranchTrueFalseTotal
if $stream_body and $request->has_buffered_body 0 6 6
Condition33%1/3
$stream_body and $request->has_buffered_body
!ll&&!rl&&r
060
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 44 ▶ if defined $callbacks{on_body};
Branch: 1 branch
BranchTrueFalseTotal
if defined $callbacks{"on_body"} 1 43 44
1632  
1633 croak 'request(): on_drain requires stream_body'
1634 44 ▶ if defined($callbacks{on_drain}) && !$stream_body;
Branch: 1 branch
BranchTrueFalseTotal
if defined $callbacks{"on_drain"} and not $stream_body 0 44 44
Condition33%1/3
defined $callbacks{"on_drain"} and not $stream_body
!ll&&!rl&&r
4400
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 44 ▶ if (exists $option{receive_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option{"receive_body"}) 1 43 44
1637 1 my $value = delete $option{receive_body};
1638  
1639 1 ▶ if (ref($value) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'HASH') { } 1 0 1
1640 1 $receive_body = 'stream';
1641 1 $receive_options = { %$value };
1642 } else {
1643 0 ▶ 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 0 0
Condition0%0/9
not defined $value or ref $value or $value ne "buffered" and $value ne "stream"
l!l&&r!l&&!r
000
not defined $value or ref $value
l!l&&r!l&&!r
000
$value ne "buffered" and $value ne "stream"
!ll&&!rl&&r
000
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 table0%0/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 0 $receive_body = $value;
1648 }
1649 }
1650  
1651 44 ▶ croak 'request(): CONNECT response body must use streaming receive mode'
Branch: 1 branch
BranchTrueFalseTotal
if $is_connect and $receive_body ne "stream" 0 44 44
Condition66%2/3
$is_connect and $receive_body ne "stream"
!ll&&!rl&&r
3590
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 44 ▶ croak 'request(): unknown options: ' . join(', ', sort keys %option)
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 44 44
1655 if %option;
1656  
1657 44 $self->_assert_request_semantics(
1658 $request,
1659 'request()',
1660 );
1661 44 ▶ my $request_streaming = $stream_body ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$stream_body ? : 15 29 44
1662  
1663 44 $self->_assert_request_content_length(
1664 $request,
1665 'request()',
1666 $request_streaming,
1667 );
1668  
1669 38 ▶ my $sending_early = !$self->{quic}->ready ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!$self->{'quic'}->ready ? : 2 36 38
1670  
1671 38 ▶ if ($sending_early) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sending_early) 2 36 38
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 38 ▶ 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 38 38
Condition50%3/6
$callbacks{"on_data"} and $callbacks{"on_body"} || $receive_options->{"on_data"}
!ll&&!rl&&r
3620
$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 38 my $on_data = delete $callbacks{on_data};
1685  
1686 38 my $stream_id = $self->_submit_request(
1687 $request,
1688 $request_streaming,
1689 );
1690 37 ▶ return unless defined $stream_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stream_id 0 37 37
1691  
1692 37 ▶ $request->mark_incomplete if $request_streaming;
Branch: 1 branch
BranchTrueFalseTotal
if $request_streaming 14 23 37
1693  
1694 37 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 37 ▶ $transaction->_enable_datagrams if $datagrams;
Branch: 1 branch
BranchTrueFalseTotal
if $datagrams 3 34 37
1704  
1705 37 ▶ if ($receive_body eq 'stream' && defined $callbacks{on_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($receive_body eq "stream" and defined $callbacks{"on_body"}) 1 36 37
Condition100%3/3
$receive_body eq "stream" and defined $callbacks{"on_body"}
!ll&&!rl&&r
2791
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 37 'response',
1725 $receive_body,
1726 $receive_options,
1727 );
1728  
1729 37 ▶ $transaction->on_data($on_data) if $on_data;
Branch: 1 branch
BranchTrueFalseTotal
if $on_data 2 35 37
1730 37 $self->{transactions}{$stream_id} = $transaction;
1731  
1732 37 ▶ if ($stream_body && defined $callbacks{on_drain}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream_body and defined $callbacks{"on_drain"}) 0 37 37
Condition66%2/3
$stream_body and defined $callbacks{"on_drain"}
!ll&&!rl&&r
23140
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 37 $self->_maybe_complete_transaction($stream_id);
1743  
1744 37 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 1358 ▶sub _enqueue_delivery {
Subroutine _enqueue_delivery: called CC=9 SCAR=22.0
1752 1358 my ($self, $queue_name, $transaction, $callback_owned) = @_;
1753  
1754 1358 my $queue = $self->{$queue_name};
1755 1358 ▶ shift @$queue while @$queue && !defined $queue->[0];
Branch: 1 branch
BranchTrueFalseTotal
@$queue and not defined $queue->[0] and do { shift @$queue } 127 1358 1485
Condition100%3/3
@$queue and not defined $queue->[0]
!ll&&!rl&&r
1711187127
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 1358 push @$queue, $transaction;
1757 1358 ▶ if ($callback_owned) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callback_owned) 1326 32 1358
1758 1326 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 1326 ▶ if (++$self->{weak_delivery_insertions}{$queue_name} >= 64) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$self->{"weak_delivery_insertions"}{$queue_name} >= 64) 20 1306 1326
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 1358 return;
1781 }
1782  
1783 120 ▶sub _next_delivery {
Subroutine _next_delivery: called CC=3 SCAR=11.0
1784 120 my ($self, $queue_name) = @_;
1785 120 my $queue = $self->{$queue_name};
1786 120 ▶ shift @$queue while @$queue && !defined $queue->[0];
Branch: 1 branch
BranchTrueFalseTotal
@$queue and not defined $queue->[0] and do { shift @$queue } 17 120 137
Condition100%3/3
@$queue and not defined $queue->[0]
!ll&&!rl&&r
833717
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 120 return shift @$queue;
1788 }
1789  
1790 113 ▶sub next_transaction {
Subroutine next_transaction: called CC=4 SCAR=14.1
Pod undocumented
1791 113 my ($self, @args) = @_;
1792  
1793 113 ▶ croak 'next_transaction() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 113 113
1794 113 ▶ $self->_service if $self->{started} && !$self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"started"} and not $self->{"failed"} 102 11 113
Condition66%2/3
$self->{"started"} and not $self->{"failed"}
!ll&&!rl&&r
110102
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 113 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 87 ▶sub _request_contract {
Subroutine _request_contract: called CC=4 SCAR=14.3
1807 87 my ($request) = @_;
1808 87 ▶ return unless blessed($request);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($request) 0 87 87
1809  
1810 87 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 1218 ▶ return unless $request->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $request->can($method) 0 1218 1218
1817 }
1818  
1819 87 return 1;
1820 }
1821  
1822 66 ▶sub _response_contract {
Subroutine _response_contract: called CC=4 SCAR=14.3
1823 66 my ($response) = @_;
1824 66 ▶ return unless blessed($response);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($response) 0 66 66
1825  
1826 66 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 660 ▶ return unless $response->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $response->can($method) 0 660 660
1833 }
1834  
1835 66 return 1;
1836 }
1837  
1838 182 ▶sub _message_header_values {
Subroutine _message_header_values: called CC=3 SCAR=11.0
1839 182 my ($message, $wanted) = @_;
1840  
1841 182 $wanted = lc $wanted;
1842 182 my @values;
1843  
1844 182 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 182 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 81 ▶sub _assert_http3_version {
Subroutine _assert_http3_version: called CC=3 SCAR=11.0
1918 81 my ($message, $operation) = @_;
1919  
1920 81 my $version = $message->version;
1921 81 ▶ return unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 63 18 81
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 114 ▶sub _declared_content_length {
Subroutine _declared_content_length: called CC=4 SCAR=13.9
1930 114 my ($message, $operation) = @_;
1931  
1932 114 my $values = _message_header_values($message, 'content-length');
1933 114 ▶ return unless @$values;
Branch: 1 branch
BranchTrueFalseTotal
unless @$values 99 15 114
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 66 ▶sub _assert_request_content_length {
Subroutine _assert_request_content_length: called CC=7 SCAR=20.8
1965 66 my ($self, $request, $operation, $streaming) = @_;
1966  
1967 66 my $declared = _declared_content_length($request, $operation);
1968 62 ▶ return unless defined $declared;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $declared 60 2 62
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 48 ▶sub _assert_response_content_length {
Subroutine _assert_response_content_length: called CC=15 SCAR=28.4
1989 48 my ($self, $transaction, $response, $operation) = @_;
1990  
1991 48 my $declared = _declared_content_length($response, $operation);
1992 48 ▶ return unless defined $declared;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $declared 39 9 48
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 40 ▶sub _assert_incremental_content_length {
Subroutine _assert_incremental_content_length: called CC=13 SCAR=26.0
2026 40 my ($self, $transaction, $kind, $message, $bytes, $final, $operation) = @_;
2027  
2028 40 my $declared;
2029  
2030 40 ▶ if ($kind eq 'request') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq 'request') { } 22 18 40
2031 22 $declared = $self->_assert_request_content_length(
2032 $message,
2033 $operation,
2034 );
2035  
2036 22 ▶ return if $message->method eq 'CONNECT';
Branch: 1 branch
BranchTrueFalseTotal
if $message->method eq "CONNECT" 11 11 22
2037 } else {
2038 18 $declared = $self->_assert_response_content_length(
2039 $transaction,
2040 $message,
2041 $operation,
2042 );
2043  
2044 18 my $status = $message->status;
2045 return
2046 18 ▶ 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 8 10 18
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
0810
$transaction->request->method eq "HEAD" or $status == 304
l!l&&r!l&&!r
0018
$transaction->request->method eq "CONNECT" and $status >= 200 and $status < 300
!ll&&!rl&&r
1008
$transaction->request->method eq "CONNECT" and $status >= 200
!ll&&!rl&&r
1008
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 58 ▶sub _response_content_forbidden_reason {
Subroutine _response_content_forbidden_reason: called CC=5 SCAR=16.1
2159 58 my ($self, $transaction, $response) = @_;
2160  
2161 58 my $method = $transaction->request->method;
2162 58 my $status = $response->status;
2163  
2164 58 ▶ return 'response to HEAD must not contain content'
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "HEAD" 3 55 58
2165 if $method eq 'HEAD';
2166 55 ▶ return '204 response must not contain content'
Branch: 1 branch
BranchTrueFalseTotal
if $status == 204 7 48 55
2167 if $status == 204;
2168 48 ▶ return '205 response must not contain content'
Branch: 1 branch
BranchTrueFalseTotal
if $status == 205 2 46 48
2169 if $status == 205;
2170 46 ▶ return '304 response must not contain content'
Branch: 1 branch
BranchTrueFalseTotal
if $status == 304 2 44 46
2171 if $status == 304;
2172  
2173 44 return;
2174 }
2175  
2176 28 ▶sub _assert_response_body_allowed {
Subroutine _assert_response_body_allowed: called CC=2 SCAR=6.9
2177 28 my ($self, $transaction, $response, $operation) = @_;
2178  
2179 28 my $reason = $self->_response_content_forbidden_reason(
2180 $transaction,
2181 $response,
2182 );
2183  
2184 28 ▶ croak "$operation: $reason"
Branch: 1 branch
BranchTrueFalseTotal
if defined $reason 4 24 28
2185 if defined $reason;
2186  
2187 24 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 37 ▶sub _write_transaction_body {
Subroutine _write_transaction_body: called CC=17 SCAR=31.7
2343 37 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 37 ▶ && $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 37 37
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
0037
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id}
!ll&&!rl&&r
0037
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction")
!ll&&!rl&&r
0037
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 37 my $id = $transaction->stream_id;
2352 37 my $message;
2353  
2354 37 ▶ if ($kind eq 'request') {
Branch: 2 branches
BranchTrueFalseTotal
if ($kind eq 'request') { } 22 15 37
elsif ($kind eq 'response') { } 15 0 15
2355 croak "$operation(): request body production requires a client connection"
2356 22 ▶ unless $self->{role} eq 'client';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "client" 0 22 22
2357  
2358 22 $message = $transaction->request;
2359  
2360 22 ▶ croak "$operation(): Request is not configured for incremental body production"
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->_request_is_streaming 0 22 22
2361 unless $transaction->_request_is_streaming;
2362 } elsif ($kind eq 'response') {
2363 croak "$operation(): response body production requires a server connection"
2364 15 ▶ unless $self->{role} eq 'server';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "server" 0 15 15
2365  
2366 15 ▶ $message = $transaction->response
Branch: 1 branch
BranchTrueFalseTotal
$message = $transaction->response or croak("$operation(): Transaction has no Response") 15 0 15
2367 or croak "$operation(): Transaction has no Response";
2368  
2369 15 $self->_assert_response_body_allowed(
2370 $transaction,
2371 $message,
2372 $operation,
2373 );
2374  
2375 15 ▶ croak "$operation(): Response is not configured for incremental body production"
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->_response_is_streaming 0 15 15
2376 unless $transaction->_response_is_streaming;
2377  
2378 15 ▶ if (!$self->{response_sent}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"response_sent"}{$id}) 7 8 15
2379 7 $self->{response_sent}{$id} = 1;
2380  
2381 7 my $ok = eval {
2382 7 $self->_submit_response($id, $message);
2383 7 1;
2384 };
2385  
2386 7 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 7 7
2387 0 delete $self->{response_sent}{$id};
2388 0 delete $self->{body_bytes_sent}{$id};
2389 0 die $@;
2390 }
2391  
2392 7 $transaction->_mark_response_started;
2393 }
2394 } else {
2395 0 croak "$operation(): unsupported HTTP body producer '$kind'";
2396 }
2397  
2398 37 ▶ $self->_assert_incremental_content_length(
Branch: 1 branch
BranchTrueFalseTotal
$final ? : 18 19 37
2399 $transaction,
2400 $kind,
2401 $message,
2402 $bytes,
2403 $final ? 1 : 0,
2404 $operation,
2405 );
2406  
2407 $self->{native}->append_body(
2408 37 ▶ $id,
Branch: 1 branch
BranchTrueFalseTotal
$final ? : 18 19 37
2409 $bytes,
2410 $final ? 1 : 0,
2411 );
2412  
2413 37 $self->_drain_output;
2414 37 $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 37 ▶ 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 ? : 35 2 37
2422 < $self->_streaming_share_limit ? 1 : 0;
2423 }
2424  
2425 450 ▶sub _streaming_share_limit {
Subroutine _streaming_share_limit: called CC=3 SCAR=11.0
2426 450 my ($self) = @_;
2427 450 my $count = $self->{native}->active_streaming_body_count;
2428 450 ▶ return $self->{send_buffer_limit} if $count < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $count < 2 448 2 450
2429 2 my $share = int($self->{send_buffer_limit} / $count);
2430 2 ▶ return $share || 1;
Condition50%1/2
$share || 1
l!l
20
MC/DC0%0/1
$share || 1
$share
Truth table50%1/2
A
A= $share
Aresult
11
00
2431 }
2432  
2433 413 ▶sub _drain_body_producers {
Subroutine _drain_body_producers: called CC=6 SCAR=17.9
2434 413 my ($self) = @_;
2435  
2436 413 my $share = $self->_streaming_share_limit;
2437 413 for my $transaction (values %{ $self->{transactions} }) {
2438 647 ▶ next if $transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal 226 421 647
2439 421 my $id = $transaction->stream_id;
2440 421 ▶ next if $self->{native}->streaming_retained_bytes_for_stream($id)
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"native"}->streaming_retained_bytes_for_stream($id) >= $share 8 413 421
2441 >= $share;
2442  
2443 413 ▶ if (my $body = $transaction->_request_body_object) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $transaction->_request_body_object) 113 300 413
2444 113 $body->_drain;
2445 }
2446  
2447 413 ▶ if (my $body = $transaction->_response_body_object) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $transaction->_response_body_object) 56 357 413
2448 56 $body->_drain;
2449 }
2450 }
2451  
2452 413 return;
2453 }
2454  
2455 28 ▶sub _consume_received_body {
Subroutine _consume_received_body: called CC=18 SCAR=35.4
2456 28 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 28 ▶ && $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 28 28
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
0028
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction") and defined $self->{"transactions"}{$transaction->stream_id}
!ll&&!rl&&r
0028
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction")
!ll&&!rl&&r
0028
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 28 ▶ 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 28 28
Condition33%2/6
defined $amount and not ref $amount and $amount =~ /\A[0-9]+\z/
!ll&&!rl&&r
0028
defined $amount and not ref $amount
!ll&&!rl&&r
0028
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 28 ▶ return if $amount == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $amount == 0 0 28 28
2470  
2471 croak 'request receive bodies exist only on server connections'
2472 28 ▶ if $kind eq 'request' && $self->{role} ne 'server';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "request" and $self->{"role"} ne "server" 0 28 28
Condition66%2/3
$kind eq "request" and $self->{"role"} ne "server"
!ll&&!rl&&r
1990
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 28 ▶ if $kind eq 'response' && $self->{role} ne 'client';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "response" and $self->{"role"} ne "client" 0 28 28
Condition66%2/3
$kind eq "response" and $self->{"role"} ne "client"
!ll&&!rl&&r
9190
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 28 ▶ croak "unsupported received body kind '$kind'"
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "request" and $kind ne "response" 0 28 28
Condition66%2/3
$kind ne "request" and $kind ne "response"
!ll&&!rl&&r
9190
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 28 ▶ 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") 28 0 28
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 28 ▶ return if $transaction->is_terminal
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal and defined $stream->local_stop_sending_code 1 27 28
Condition100%3/3
$transaction->is_terminal and defined $stream->local_stop_sending_code
!ll&&!rl&&r
2611
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 27 $stream->consume(0 + $amount);
2487 27 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 10 ▶sub _transaction_priority {
Subroutine _transaction_priority: called CC=8 SCAR=23.1
2512 10 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 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
2519  
2520 10 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"role"} eq "server" and not $transaction->is_terminal) 7 3 10
Condition66%2/3
$self->{"role"} eq "server" and not $transaction->is_terminal
!ll&&!rl&&r
307
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 7 $transaction->stream_id,
2526 );
2527  
2528 return {
2529 7 ▶ urgency => 0 + $priority->[0],
Branch: 1 branch
BranchTrueFalseTotal
$priority->[1] ? : 5 2 7
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 64 ▶sub _release_peer_bidi_stream_credit {
Subroutine _release_peer_bidi_stream_credit: called CC=7 SCAR=20.2
2865 64 my ($self, $id, $stream) = @_;
2866  
2867 64 ▶ return unless $self->{role} eq 'server';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "server" 32 32 64
2868 32 ▶ return unless defined $stream;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stream 0 32 32
2869 32 ▶ return if $stream->local_initiated;
Branch: 1 branch
BranchTrueFalseTotal
if $stream->local_initiated 0 32 32
2870 32 ▶ return unless $stream->bidirectional;
Branch: 1 branch
BranchTrueFalseTotal
unless $stream->bidirectional 0 32 32
2871  
2872 32 ▶ my $lifecycle = $self->{stream_lifecycle}{$id} ||= {};
Condition50%1/2
$self->{"stream_lifecycle"}{$id} ||= {}
l!l
320
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 32 ▶ return if $lifecycle->{peer_bidi_credit_released};
Branch: 1 branch
BranchTrueFalseTotal
if $lifecycle->{"peer_bidi_credit_released"} 0 32 32
2874  
2875 32 $lifecycle->{peer_bidi_credit_released} = 1;
2876 32 ++$self->{native_max_client_streams_bidi};
2877  
2878 $self->{native}->set_max_client_streams_bidi(
2879 $self->{native_max_client_streams_bidi},
2880 32 );
2881  
2882 32 return;
2883 }
2884  
2885 117 ▶sub _cleanup_stream_if_done {
Subroutine _cleanup_stream_if_done: called CC=5 SCAR=16.1
2886 117 my ($self, $id) = @_;
2887  
2888 117 my $lifecycle = $self->{stream_lifecycle}{$id};
2889 117 ▶ return unless defined($lifecycle) && $lifecycle->{closed_seen};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lifecycle and $lifecycle->{"closed_seen"} 53 64 117
Condition66%2/3
defined $lifecycle and $lifecycle->{"closed_seen"}
!ll&&!rl&&r
05364
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 64 my $transaction = $self->{transactions}{$id};
2892 64 ▶ return if defined($transaction) && !$transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if defined $transaction and not $transaction->is_terminal 0 64 64
Condition66%2/3
defined $transaction and not $transaction->is_terminal
!ll&&!rl&&r
2620
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 64 delete $self->{streams}{$id};
2895 64 delete $self->{messages}{$id};
2896 64 delete $self->{outgoing}{$id};
2897 64 delete $self->{stream_lifecycle}{$id};
2898 64 delete $self->{trailer_field_section_size}{$id};
2899 64 delete $self->{output_finished}{$id};
2900 64 delete $self->{blocked_output}{$id};
2901 64 delete $self->{response_sent}{$id};
2902 64 delete $self->{body_bytes_sent}{$id};
2903 64 delete $self->{rejected_streams}{$id};
2904 64 delete $self->{peer_uni_probe}{$id};
2905 64 delete $self->{core_uni_streams}{$id};
2906 64 delete $self->{ignored_uni_streams}{$id};
2907 64 delete $self->{extension_stream_objects}{$id};
2908 64 delete $self->{transactions}{$id};
2909  
2910 64 return;
2911 }
2912  
2913 231 ▶sub _maybe_complete_transaction {
Subroutine _maybe_complete_transaction: called CC=17 SCAR=28.6
2914 231 my ($self, $id) = @_;
2915  
2916 231 my $transaction = $self->{transactions}{$id};
2917 231 ▶ return unless defined $transaction;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $transaction 24 207 231
2918 207 ▶ return if $transaction->is_terminal || $transaction->{callback_depth};
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal or $transaction->{"callback_depth"} 39 168 207
Condition100%3/3
$transaction->is_terminal or $transaction->{"callback_depth"}
l!l&&r!l&&!r
2910168
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 168 ▶ if ($self->{role} eq 'client') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"role"} eq "client") 97 71 168
2921 97 my $response = $transaction->response;
2922 97 ▶ return unless defined $response;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $response 54 43 97
2923 43 ▶ return unless $response->is_complete;
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_complete 17 26 43
2924  
2925 26 my $reader = $transaction->_incoming_body_reader('response');
2926 26 ▶ return if defined($reader) && !$reader->is_complete;
Branch: 1 branch
BranchTrueFalseTotal
if defined $reader and not $reader->is_complete 0 26 26
Condition66%2/3
defined $reader and not $reader->is_complete
!ll&&!rl&&r
1880
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 26 ▶ if ($transaction->request->method eq 'CONNECT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($transaction->request->method eq "CONNECT") 5 21 26
2929 5 my $writer = $transaction->_request_body_object;
2930 5 ▶ return unless defined($writer) && $writer->is_complete;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $writer and $writer->is_complete 0 5 5
Condition33%1/3
defined $writer and $writer->is_complete
!ll&&!rl&&r
005
MC/DC0%0/2
defined $writer and $writer->is_complete
defined $writer $writer->is_complete
Truth table33%1/3
A and B
A= defined $writerB= $writer->is_complete
ABresult
0X0
100
111
2931 }
2932  
2933 26 $transaction->_mark_complete;
2934 26 $self->_cleanup_stream_if_done($id);
2935 26 return;
2936 }
2937  
2938 71 my $request = $transaction->request;
2939 71 ▶ return unless $request->is_complete;
Branch: 1 branch
BranchTrueFalseTotal
unless $request->is_complete 16 55 71
2940 55 ▶ return unless $transaction->{request_end_callback_called};
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->{"request_end_callback_called"} 1 54 55
2941  
2942 54 my $reader = $transaction->_incoming_body_reader('request');
2943 54 ▶ return if defined($reader) && !$reader->is_complete;
Branch: 1 branch
BranchTrueFalseTotal
if defined $reader and not $reader->is_complete 0 54 54
Condition66%2/3
defined $reader and not $reader->is_complete
!ll&&!rl&&r
39150
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 54 ▶ return unless $self->{output_finished}{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"output_finished"}{$id} 27 27 54
2946  
2947 27 $transaction->_mark_complete;
2948 27 $self->_cleanup_stream_if_done($id);
2949 27 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 21 ▶sub _bind_local_streams {
Subroutine _bind_local_streams: called CC=6 SCAR=18.9
3015 21 my ($self) = @_;
3016  
3017 21 ▶ return 1 if defined $self->{control_stream_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"control_stream_id"} 0 21 21
3018  
3019 21 my $control = $self->{quic}->open_uni_stream;
3020 21 my $qenc = $self->{quic}->open_uni_stream;
3021 21 my $qdec = $self->{quic}->open_uni_stream;
3022  
3023 21 ▶ 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 21 21
Condition33%2/6
defined $control and defined $qenc and defined $qdec
!ll&&!rl&&r
0021
defined $control and defined $qenc
!ll&&!rl&&r
0021
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 21 for my $stream ($control, $qenc, $qdec) {
3027 63 $self->{streams}{ $stream->id } = $stream;
3028 }
3029  
3030 $self->{native}->bind_streams(
3031 21 $control->id,
3032 $qenc->id,
3033 $qdec->id,
3034 );
3035  
3036 21 $self->{control_stream_id} = $control->id;
3037 21 $self->{qpack_encoder_stream_id} = $qenc->id;
3038 21 $self->{qpack_decoder_stream_id} = $qdec->id;
3039 21 return 1;
3040 }
3041  
3042 21 ▶sub start {
Subroutine start: called CC=15 SCAR=29.5
Pod undocumented
3043 21 my ($self) = @_;
3044  
3045 21 ▶ if ($self->{started}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"started"}) 0 21 21
3046 0 $self->_sync_early_data_status;
3047 0 return $self;
3048 }
3049  
3050 21 ▶ my $ready = $self->{quic}->ready ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'quic'}->ready ? : 18 3 21
3051 21 my $early_status = $self->{quic}->early_data_status;
3052  
3053 21 ▶ if (!$ready) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $ready) { } 3 18 21
elsif ($self->{'role'} eq 'server' and $early_status eq 'accepted' and not defined $self->{'remembered_local_settings'}) { } 0 36 36
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
1800
$self->{"role"} eq "server" and $early_status eq "accepted"
!ll&&!rl&&r
8100
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 21 ▶ if (!defined $self->{quic}->send_buffer_limit) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"quic"}->send_buffer_limit) 20 1 21
3074 20 $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 21 ▶ if ($ready || $self->{role} eq 'client') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ready or $self->{"role"} eq "client") 20 1 21
Condition100%3/3
$ready or $self->{"role"} eq "client"
l!l&&r!l&&!r
1821
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 20 $self->_bind_local_streams;
3083 }
3084  
3085 21 $self->{started} = 1;
3086  
3087 21 my $weak = $self;
3088 21 weaken($weak);
3089  
3090 458 ▶ $self->{quic}->on_stream_activity(sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
3091 458 ▶ return unless defined $weak;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $weak 0 458 458
3092 458 $weak->_service;
3093 21 });
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 21 });
3101  
3102 21 ▶ if ($self->{quic}->can_receive_datagram) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"quic"}->can_receive_datagram) 9 12 21
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 21 $self->_service;
3111  
3112 21 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 318 ▶sub _promote_accepted_early_transactions {
Subroutine _promote_accepted_early_transactions: called CC=18 SCAR=34.8
3224 318 my ($self) = @_;
3225  
3226 318 ▶ return unless $self->{role} eq 'server';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "server" 0 318 318
3227 318 ▶ return unless $self->{quic}->ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"quic"}->ready 0 318 318
3228 318 ▶ return if $self->{quic}->early_data_status eq 'rejected';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"quic"}->early_data_status eq "rejected" 0 318 318
3229 318 ▶ return unless @{ $self->{pending_early_transactions} };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"pending_early_transactions"};} 317 1 318
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 626 ▶sub _sync_early_data_status {
Subroutine _sync_early_data_status: called CC=7 SCAR=19.5
3310 626 my ($self) = @_;
3311  
3312 626 my $status = $self->{quic}->early_data_status;
3313 626 my $previous = $self->{early_data_status};
3314 626 $self->{early_data_status} = $status;
3315  
3316 626 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"role"} eq "client" and $self->{"early_data_started"} and $status eq "rejected") 1 625 626
Condition100%6/6
$self->{"role"} eq "client" and $self->{"early_data_started"} and $status eq "rejected"
!ll&&!rl&&r
612131
$self->{"role"} eq "client" and $self->{"early_data_started"}
!ll&&!rl&&r
33827414
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 625 ▶ if ($self->{role} eq 'server') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"role"} eq "server") 338 287 625
3325 338 ▶ if ($status eq 'rejected') {
Branch: 2 branches
BranchTrueFalseTotal
if ($status eq 'rejected') { } 0 338 338
elsif ($self->{'quic'}->ready) { } 318 20 338
3326 0 $self->_reject_pending_early_transactions;
3327 } elsif ($self->{quic}->ready) {
3328 318 $self->_promote_accepted_early_transactions;
3329 }
3330 }
3331  
3332 625 return 0;
3333 }
3334  
3335 268 ▶sub _now_ns {
Subroutine _now_ns: called CC=1 SCAR=0.0
3336 return int(
3337 268 Time::HiRes::clock_gettime(Time::HiRes::CLOCK_MONOTONIC())
3338 * 1_000_000_000
3339 );
3340 }
3341  
3342 586 ▶sub _service {
Subroutine _service: called CC=20 SCAR=31.0
3343 586 my ($self) = @_;
3344  
3345 586 ▶ return unless $self->{started};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"started"} 0 586 586
3346 586 ▶ return if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 0 586 586
3347  
3348 586 my $restarted = $self->_sync_early_data_status;
3349 return if !$self->{quic}->ready
3350 586 ▶ && $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 586 586
Condition66%2/3
not $self->{"quic"}->ready and $self->{"quic"}->early_data_status eq "rejected"
!ll&&!rl&&r
564220
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 586 ▶ return if $restarted;
Branch: 1 branch
BranchTrueFalseTotal
if $restarted 0 586 586
3352  
3353 586 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"role"} eq "server" and $self->{"quic"}->ready and not defined $self->{"control_stream_id"}) 1 585 586
Condition100%6/6
$self->{"role"} eq "server" and $self->{"quic"}->ready and not defined $self->{"control_stream_id"}
!ll&&!rl&&r
2683171
$self->{"role"} eq "server" and $self->{"quic"}->ready
!ll&&!rl&&r
24820318
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 586 ▶ if ($self->{servicing}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"servicing"}) 0 586 586
3362 0 $self->{service_again} = 1;
3363 0 return;
3364 }
3365  
3366 586 $self->{servicing} = 1;
3367  
3368 586 my $ok = eval {
3369 do {
3370 586 $self->{service_again} = 0;
3371  
3372 586 my @new_ids;
3373  
3374 586 ▶ while (my $stream = $self->{quic}->next_stream) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $stream = $self->{"quic"}->next_stream) 84 586 670
3375 84 $self->{streams}{ $stream->id } = $stream;
3376 84 push @new_ids, $stream->id;
3377 }
3378  
3379 586 for my $id (@new_ids) {
3380 84 ▶ last if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 0 84 84
3381 84 $self->_service_stream($id);
3382 }
3383  
3384 586 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"failed"} and defined(my $id = $self->{"quic"}->next_active_stream_id)) 526 586 1112
Condition100%3/3
not $self->{"failed"} and defined(my $id = $self->{"quic"}->next_active_stream_id)
!ll&&!rl&&r
6580526
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 526 $self->_service_stream($id);
3389 }
3390  
3391 586 ▶ if (!$self->{failed}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"failed"}) 580 6 586
3392 580 $self->_drain_events;
3393 $self->_drain_output
3394 580 ▶ if defined $self->{control_stream_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"control_stream_id"} 560 20 580
3395 }
3396 586 ▶ } 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 586 586
Condition33%1/3
$self->{"service_again"} and not $self->{"failed"}
!ll&&!rl&&r
58600
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 586 1;
3399 };
3400  
3401 586 my $error = $@;
3402 586 $self->{servicing} = 0;
3403  
3404 586 ▶ die $error unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 586 586
3405 586 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 46 ▶sub _classify_peer_uni_stream {
Subroutine _classify_peer_uni_stream: called CC=22 SCAR=37.1
3457 46 my ($self, $id, $stream) = @_;
3458  
3459 46 ▶ my $state = $self->{peer_uni_probe}{$id} ||= {
Condition50%1/2
$self->{"peer_uni_probe"}{$id} ||= {"buffer", "", "fin", 0}
l!l
460
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 46 while (1) {
3465 my ($type, $type_length) =
3466 92 _decode_http3_varint($state->{buffer}, 0);
3467  
3468 92 ▶ if (defined $type) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type) 46 46 92
3469 46 ▶ if ($self->{role} eq 'client' && $type eq '1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"role"} eq "client" and $type eq 1) 1 45 46
Condition100%3/3
$self->{"role"} eq "client" and $type eq 1
!ll&&!rl&&r
25201
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 45 ▶ if ($CORE_STREAM_TYPE{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CORE_STREAM_TYPE{$type}) 42 3 45
3484 42 my $bytes = $state->{buffer};
3485 42 my $fin = $state->{fin};
3486  
3487 42 delete $self->{peer_uni_probe}{$id};
3488 42 $self->{core_uni_streams}{$id} = 1;
3489  
3490 42 $self->_inspect_peer_settings_bytes($id, $bytes);
3491 42 ▶ return 'failed' if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 1 41 42
3492  
3493 my $result = $self->{native}->read_stream(
3494 41 ▶ $id,
Branch: 1 branch
BranchTrueFalseTotal
$fin ? : 0 41 41
3495 $bytes,
3496 $fin ? 1 : 0,
3497 _now_ns(),
3498 );
3499  
3500 41 ▶ if (@$result > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$result > 1) 0 41 41
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 41 my $consumed = $result->[0];
3512 41 ▶ $stream->consume($consumed) if $consumed;
Branch: 1 branch
BranchTrueFalseTotal
if $consumed 41 0 41
3513 41 $self->_drain_events;
3514  
3515 41 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 46 my $chunk = $stream->next_data_chunk;
3569  
3570 46 ▶ if (!defined $chunk) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $chunk) 0 46 46
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 46 my ($bytes, $fin) = @$chunk;
3585 46 $state->{buffer} .= $bytes;
3586 46 ▶ $state->{fin} ||= $fin ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$fin ? : 0 46 46
Condition33%1/3
$state->{"fin"} ||= $fin ? 1 : 0
l!l&&r!l&&!r
0046
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 46 ▶ if ($fin && !length($state->{buffer})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fin and not length $state->{"buffer"}) 0 46 46
Condition33%1/3
$fin and not length $state->{"buffer"}
!ll&&!rl&&r
4600
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 6 ▶sub _is_local_critical_stream {
Subroutine _is_local_critical_stream: called CC=7 SCAR=22.1
3597 6 my ($self, $id) = @_;
3598  
3599 return 1
3600 if defined($self->{control_stream_id})
3601 6 ▶ && $id == $self->{control_stream_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"} 0 6 6
Condition33%1/3
defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"}
!ll&&!rl&&r
060
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 6 ▶ && $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 5 6
Condition66%2/3
defined $self->{"qpack_encoder_stream_id"} and $id == $self->{"qpack_encoder_stream_id"}
!ll&&!rl&&r
051
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 5 ▶ && $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 5 5
Condition33%1/3
defined $self->{"qpack_decoder_stream_id"} and $id == $self->{"qpack_decoder_stream_id"}
!ll&&!rl&&r
050
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 5 return 0;
3610 }
3611  
3612 610 ▶sub _service_stream {
Subroutine _service_stream: called CC=46 SCAR=38.8
3613 610 my ($self, $id) = @_;
3614  
3615 610 my $stream = $self->{streams}{$id};
3616 610 ▶ return unless defined $stream;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stream 0 610 610
3617  
3618 610 ▶ if (my $extension = $self->{extension_stream_objects}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $extension = $self->{"extension_stream_objects"}{$id}) 12 598 610
3619 12 $self->_service_extension_stream(
3620 $id,
3621 $stream,
3622 $extension,
3623 );
3624 12 return;
3625 }
3626  
3627 598 ▶ if ($self->{ignored_uni_streams}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ignored_uni_streams"}{$id}) 3 595 598
3628 3 $self->_service_ignored_uni_stream($id, $stream);
3629 3 return;
3630 }
3631  
3632 595 ▶ 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}) 46 549 595
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
549046
$stream->bidirectional or $stream->local_initiated or $self->{"core_uni_streams"}{$id}
l!l&&r!l&&!r
43911046
$stream->bidirectional or $stream->local_initiated
l!l&&r!l&&!r
338101156
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 46 $self->{peer_uni_probe}{$id} = {
3639 buffer => '',
3640 fin => 0,
3641 };
3642 }
3643  
3644 595 ▶ if (exists $self->{peer_uni_probe}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"peer_uni_probe"}{$id}) 46 549 595
3645 46 my $kind = $self->_classify_peer_uni_stream(
3646 $id,
3647 $stream,
3648 );
3649  
3650 46 ▶ if ($kind eq 'extension') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "extension") 2 44 46
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 44 ▶ if ($kind eq 'ignored') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "ignored") 1 43 44
3661 1 $self->_service_ignored_uni_stream($id, $stream);
3662 1 return;
3663 }
3664  
3665 43 ▶ return if $kind ne 'core';
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "core" 2 41 43
3666 41 ▶ return if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 0 41 41
3667 }
3668  
3669 590 ▶ if ($stream->can_receive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream->can_receive) 489 101 590
3670 489 while (1) {
3671 714 my $chunk = $stream->next_data_chunk;
3672 714 ▶ last unless defined $chunk;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $chunk 487 227 714
3673  
3674 227 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 227 ▶ if ($self->{rejected_streams}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"rejected_streams"}{$id}) 0 227 227
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 227 $self->_inspect_peer_settings_bytes($id, $bytes);
3684 227 ▶ return if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 0 227 227
3685  
3686 my $result = $self->{native}->read_stream(
3687 227 ▶ $id,
Branch: 1 branch
BranchTrueFalseTotal
$fin ? : 57 170 227
3688 $bytes,
3689 $fin ? 1 : 0,
3690 _now_ns(),
3691 );
3692  
3693 227 ▶ if (@$result > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$result > 1) 2 225 227
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 225 my $consumed = $result->[0];
3704 225 ▶ $stream->consume($consumed) if $consumed;
Branch: 1 branch
BranchTrueFalseTotal
if $consumed 161 64 225
3705 225 $self->_drain_events;
3706 225 ▶ return if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 0 225 225
3707 }
3708 }
3709  
3710 588 ▶ if ($stream->can_send && !$self->{rejected_streams}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream->can_send and not $self->{"rejected_streams"}{$id}) 413 175 588
Condition100%3/3
$stream->can_send and not $self->{"rejected_streams"}{$id}
!ll&&!rl&&r
15025413
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 413 ▶ if (delete $self->{blocked_output}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $self->{"blocked_output"}{$id}) 9 404 413
3715 9 $self->{native}->unblock_stream($id);
3716 }
3717 413 my $acked_offset = $stream->acked_offset;
3718  
3719 413 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"}) 14 399 413
Condition100%3/3
defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"}
!ll&&!rl&&r
339614
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 14 ▶ if (defined $self->{control_settings_pending}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'control_settings_pending'}) { } 0 14 14
elsif ($self->{'control_settings_delta'}) { } 9 5 14
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 413 $id,
3735 $acked_offset,
3736 );
3737 413 $self->_drain_events;
3738 413 ▶ return if $self->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 0 413 413
3739 413 $self->_drain_body_producers;
3740 }
3741  
3742 588 ▶ my $lifecycle = $self->{stream_lifecycle}{$id} ||= {};
Condition100%2/2
$self->{"stream_lifecycle"}{$id} ||= {}
l!l
435153
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 588 my $remote_reset = $stream->remote_reset_code;
3745 588 ▶ if (defined($remote_reset) && !$lifecycle->{remote_reset_seen}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $remote_reset and not $lifecycle->{"remote_reset_seen"}) 12 576 588
Condition100%3/3
defined $remote_reset and not $lifecycle->{"remote_reset_seen"}
!ll&&!rl&&r
568812
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 587 my $remote_stop = $stream->remote_stop_sending_code;
3768 587 ▶ if (defined($remote_stop) && !$lifecycle->{remote_stop_seen}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $remote_stop and not $lifecycle->{"remote_stop_seen"}) 6 581 587
Condition100%3/3
defined $remote_stop and not $lifecycle->{"remote_stop_seen"}
!ll&&!rl&&r
569126
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 6 $lifecycle->{remote_stop_seen} = 1;
3770 6 $lifecycle->{remote_stop_sending_code} = 0 + $remote_stop;
3771  
3772 6 ▶ if ($self->_is_local_critical_stream($id)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_local_critical_stream($id)) 1 5 6
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 5 $self->{native}->shutdown_stream_write($id);
3781 5 $self->{native}->discard_body($id);
3782  
3783 5 my $transaction = $self->{transactions}{$id};
3784 5 ▶ if (defined $transaction) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $transaction) 4 1 5
3785 4 $transaction->_mark_remote_stop_sending($remote_stop);
3786 4 ▶ $transaction->_mark_cancelled
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->is_terminal 4 0 4
3787 unless $transaction->is_terminal;
3788 }
3789 }
3790  
3791 586 ▶ if ($stream->closed && !$lifecycle->{closed_seen}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream->closed and not $lifecycle->{"closed_seen"}) 64 522 586
Condition66%2/3
$stream->closed and not $lifecycle->{"closed_seen"}
!ll&&!rl&&r
522064
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 64 $lifecycle->{closed_seen} = 1;
3793  
3794 64 ▶ if ($self->{core_uni_streams}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"core_uni_streams"}{$id}) 0 64 64
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 64 $id,
3804 $stream,
3805 );
3806  
3807 $self->{native}->close_stream(
3808 64 $id,
3809 $remote_reset,
3810 $stream->local_reset_code,
3811 );
3812  
3813 64 $self->_cleanup_stream_if_done($id);
3814 }
3815  
3816 586 return;
3817 }
3818  
3819 1259 ▶sub _drain_events {
Subroutine _drain_events: called CC=61 SCAR=56.0
3820 1259 my ($self) = @_;
3821  
3822 1259 ▶ while (!$self->{failed} && (my $event = $self->{native}->next_event)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"failed"} and my $event = $self->{"native"}->next_event) 275 1259 1534
Condition66%2/3
not $self->{"failed"} and my $event = $self->{"native"}->next_event
!ll&&!rl&&r
01259275
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 275 my ($type, $id, @args) = @$event;
3824  
3825 275 ▶ if ($type eq 'settings') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "settings") 14 261 275
3826 14 $self->{peer_max_field_section_size} = "$args[0]";
3827 14 ▶ $self->{peer_enable_connect_protocol} = $args[1] ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$args[1] ? : 5 9 14
3828 14 ▶ $self->{peer_h3_datagram} = $args[2] ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$args[2] ? : 8 6 14
3829 14 $self->_accept_peer_extension_settings;
3830 14 next;
3831 }
3832  
3833 261 ▶ if ($type eq 'origin') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "origin") 2 259 261
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 259 ▶ if ($type eq 'end_origin') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "end_origin") 1 258 259
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 258 ▶ if ($self->{rejected_streams}{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"rejected_streams"}{$id}) 2 256 258
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 256 ▶ if ($type eq 'headers') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "headers") 68 188 256
3866 68 my ($field_section_size, $fin) = @args;
3867  
3868 68 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($field_section_size > $self->{"max_field_section_size"}) 0 68 68
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 68 ▶ $id,
Branch: 1 branch
BranchTrueFalseTotal
$fin ? : 0 68 68
3881 $fin ? 1 : 0,
3882 );
3883 68 next;
3884 }
3885  
3886 188 ▶ if ($type eq 'data') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "data") 54 134 188
3887 54 my $bytes = $args[0];
3888 54 my $message = $self->{messages}{$id};
3889  
3890 54 ▶ croak "received HTTP/3 DATA before message headers"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message 0 54 54
3891 unless defined $message;
3892  
3893 54 ▶ my $transaction = $self->{transactions}{$id}
Branch: 1 branch
BranchTrueFalseTotal
my $transaction = $self->{"transactions"}{$id} or croak("received HTTP/3 DATA for unknown Transaction") 54 0 54
3894 or croak "received HTTP/3 DATA for unknown Transaction";
3895 54 ▶ if ($transaction->is_terminal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($transaction->is_terminal) 0 54 54
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 54 $transaction->{receive_started} = 1;
3901 54 ▶ my $kind = $self->{role} eq 'server'
Branch: 1 branch
BranchTrueFalseTotal
$self->{'role'} eq 'server' ? : 24 30 54
3902 ? 'request'
3903 : 'response';
3904 54 my $reader = $transaction->_incoming_body_reader($kind);
3905  
3906 54 ▶ if (defined $reader) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $reader) 28 26 54
3907 28 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($reader->pending_bytes + length($bytes) > $self->{"max_streaming_body_bytes"}) 0 28 28
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 28 $reader->_push_owned($bytes);
3917 28 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 134 ▶ if ($type eq 'deferred_consume') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "deferred_consume") 0 134 134
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 134 ▶ if ($type eq 'end_stream') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "end_stream") 56 78 134
3949 56 my $transaction = $self->{transactions}{$id};
3950 56 ▶ if (defined $transaction && !$transaction->is_terminal) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $transaction and not $transaction->is_terminal) 56 0 56
Condition33%1/3
defined $transaction and not $transaction->is_terminal
!ll&&!rl&&r
0056
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 56 ▶ my $kind = $self->{role} eq 'server'
Branch: 1 branch
BranchTrueFalseTotal
$self->{'role'} eq 'server' ? : 30 26 56
3952 ? 'request'
3953 : 'response';
3954 56 my $reader = $transaction->_incoming_body_reader($kind);
3955  
3956 56 ▶ if (defined $reader) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $reader) { } 16 40 56
3957 16 my $message = $self->{messages}{$id};
3958 16 ▶ if (defined $message) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $message) 16 0 16
3959 16 $message->freeze_trailers;
3960 16 $message->freeze;
3961 16 $message->mark_complete;
3962 }
3963 16 $reader->_mark_end;
3964 } else {
3965 40 $transaction->_finish_received_message($kind);
3966 }
3967 }
3968  
3969 56 $self->_maybe_complete_transaction($id);
3970 56 next;
3971 }
3972  
3973 78 ▶ if ($type eq 'stop_sending') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "stop_sending") 0 78 78
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 78 ▶ if ($type eq 'reset_stream') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "reset_stream") 0 78 78
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 78 ▶ if ($type eq 'begin_trailers') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "begin_trailers") 4 74 78
3996 4 $self->{trailer_field_section_size}{$id} = 0;
3997 4 next;
3998 }
3999  
4000 74 ▶ if ($type eq 'trailer') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "trailer") 6 68 74
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 68 ▶ if ($type eq 'end_trailers') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "end_trailers") 4 64 68
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 64 ▶ if ($type eq 'shutdown') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "shutdown") 0 64 64
4041 0 $self->{remote_shutdown_id} = 0 + $id;
4042 0 next;
4043 }
4044  
4045 64 ▶ if ($type eq 'stream_close') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "stream_close") 64 0 64
4046 64 next;
4047 }
4048  
4049 0 croak "unknown native HTTP/3 event '$type'";
4050 }
4051  
4052 1259 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 68 ▶sub _finish_headers {
Subroutine _finish_headers: called CC=64 SCAR=48.9
4070 68 my ($self, $id, $fin) = @_;
4071  
4072 68 my $message;
4073  
4074 68 ▶ if ($self->{role} eq 'server') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'role'} eq 'server') { } 37 31 68
4075 37 my $method = $self->{native}->header_pseudo($id, ':method');
4076  
4077 37 ▶ croak 'HTTP/3 request is missing :method'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $method 0 37 37
4078 unless defined $method;
4079  
4080 37 my $scheme = $self->{native}->header_pseudo($id, ':scheme');
4081 37 my $authority = $self->{native}->header_pseudo($id, ':authority');
4082 37 my $path = $self->{native}->header_pseudo($id, ':path');
4083 37 my $protocol = $self->{native}->header_pseudo($id, ':protocol');
4084 37 ▶ my $is_connect = $method eq 'CONNECT' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$method eq 'CONNECT' ? : 8 29 37
4085 37 ▶ my $is_extended_connect =
Branch: 1 branch
BranchTrueFalseTotal
$is_connect && defined $protocol ? : 6 31 37
Condition100%3/3
$is_connect and defined $protocol
!ll&&!rl&&r
2926
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 37 my $target;
4088 37 my $host_values = $self->{native}->header_values($id, 'host');
4089  
4090 37 ▶ if ($is_connect && !$is_extended_connect) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_connect and not $is_extended_connect) { } 2 35 37
Condition100%3/3
$is_connect and not $is_extended_connect
!ll&&!rl&&r
2962
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 35 ▶ if ($is_extended_connect && !$self->{enable_extended_connect}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_extended_connect and not $self->{"enable_extended_connect"}) 0 35 35
Condition66%2/3
$is_extended_connect and not $self->{"enable_extended_connect"}
!ll&&!rl&&r
2960
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 35 ▶ if ($is_extended_connect && !defined $path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_extended_connect and not defined $path) 0 35 35
Condition66%2/3
$is_extended_connect and not defined $path
!ll&&!rl&&r
2960
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 35 ▶ croak 'HTTP/3 request is missing :path'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 35 35
4131 unless defined $path;
4132  
4133 35 $target = $path;
4134  
4135 35 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 35 ▶ if (defined $semantic_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $semantic_error) 1 34 35
4145 1 $self->_reject_message_stream($id, $semantic_error);
4146 1 return;
4147 }
4148  
4149 34 ▶ if (!defined($authority) && @$host_values == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $authority and @$host_values == 1) 0 34 34
Condition33%1/3
not defined $authority and @$host_values == 1
!ll&&!rl&&r
3400
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 36 $id,
4156 $method,
4157 $target,
4158 $scheme,
4159 $authority,
4160 $protocol,
4161 $fin,
4162 );
4163  
4164 36 my $response = Uniform::HTTP::Response->new(
4165 status => 200,
4166 version => '3',
4167 );
4168  
4169 36 my $stream = $self->{streams}{$id};
4170 36 ▶ my $stream_is_early = defined($stream) && $stream->early_data ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $stream && $stream->early_data ? : 1 35 36
Condition66%2/3
defined $stream and $stream->early_data
!ll&&!rl&&r
0351
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 36 ▶ 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 36 36
Condition66%2/3
$stream_is_early and not defined $self->{"remembered_local_settings"}
!ll&&!rl&&r
3510
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 36 );
4188  
4189 my $request_receive_mode = $is_connect
4190 || defined($self->{callbacks}{on_body})
4191 ? 'stream'
4192 36 ▶ : $self->{receive_body_mode};
Branch: 1 branch
BranchTrueFalseTotal
$is_connect || defined $self->{'callbacks'}{'on_body'} ? : 8 28 36
Condition66%2/3
$is_connect or defined $self->{"callbacks"}{"on_body"}
l!l&&r!l&&!r
8028
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 36 my %request_receive_options;
4195 36 ▶ if (defined $self->{callbacks}{on_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"callbacks"}{"on_body"}) 0 36 36
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 36 'request',
4208 $request_receive_mode,
4209 \%request_receive_options,
4210 );
4211 36 ▶ $transaction->_ensure_receive_reader('request')
Branch: 1 branch
BranchTrueFalseTotal
if $request_receive_mode eq "stream" 9 27 36
4212 if $request_receive_mode eq 'stream';
4213  
4214 36 $self->{transactions}{$id} = $transaction;
4215  
4216 36 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($stream_is_early and not $self->{'quic'}->ready) { } 1 35 36
Condition66%2/3
$stream_is_early and not $self->{"quic"}->ready
!ll&&!rl&&r
3501
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 35 my $datagrams = 0;
4223 35 ▶ if (defined $self->{datagram_request}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"datagram_request"}) 3 32 35
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 35 ▶ $transaction->_enable_datagrams if $datagrams;
Branch: 1 branch
BranchTrueFalseTotal
if $datagrams 1 34 35
4229 $self->_enqueue_delivery(
4230 'ready_transactions',
4231 $transaction,
4232 35 ▶ defined($self->{callbacks}{on_request}) ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'callbacks'}{'on_request'} ? : 32 3 35
4233 );
4234  
4235 35 ▶ if (defined $self->{callbacks}{on_request}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"callbacks"}{"on_request"}) 32 3 35
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 31 my $status = $self->{native}->header_pseudo($id, ':status');
4245  
4246 31 ▶ croak 'HTTP/3 response is missing :status'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status 0 31 31
4247 unless defined $status;
4248  
4249 31 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"native"}->has_header($id, "capsule-protocol") and not 0 + $status >= 200 && 0 + $status < 300) 0 31 31
Condition50%3/6
$self->{"native"}->has_header($id, "capsule-protocol") and not 0 + $status >= 200 && 0 + $status < 300
!ll&&!rl&&r
2920
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 31 $id,
4262 0 + $status,
4263 $fin,
4264 );
4265  
4266 31 ▶ my $transaction = $self->{transactions}{$id}
Branch: 1 branch
BranchTrueFalseTotal
my $transaction = $self->{"transactions"}{$id} or croak("received HTTP/3 response for unknown Transaction") 31 0 31
4267 or croak "received HTTP/3 response for unknown Transaction";
4268  
4269 31 ▶ if ($message->status < 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($message->status < 200) 2 29 31
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 29 $transaction->_set_response($message);
4293 29 my $response_result = $transaction->_invoke(
4294 'on_response',
4295 $message,
4296 );
4297 29 ▶ die $response_result unless $response_result eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $response_result eq 1 0 29 29
4298 29 ▶ return if $transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal 1 28 29
4299  
4300 28 $transaction->_ensure_receive_reader('response');
4301  
4302 28 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($transaction->request->method eq "CONNECT" and $message->status < 200 || $message->status >= 300) 2 26 28
Condition83%5/6
$transaction->request->method eq "CONNECT" and $message->status < 200 || $message->status >= 300
!ll&&!rl&&r
2242
$message->status < 200 or $message->status >= 300
l!l&&r!l&&!r
024
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 28 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 28 ▶ || $callback->{on_finish}) ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
$callback->{'on_response'} || $callback->{'on_complete'} || $callback->{'on_body'} || $callback->{'on_data'} || $callback->{'on_finish'} ? : 5 23 28
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
2323
$callback->{"on_response"} or $callback->{"on_complete"} or $callback->{"on_body"} or $callback->{"on_data"}
l!l&&r!l&&!r
2026
$callback->{"on_response"} or $callback->{"on_complete"} or $callback->{"on_body"}
l!l&&r!l&&!r
2026
$callback->{"on_response"} or $callback->{"on_complete"}
l!l&&r!l&&!r
1126
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 64 my $lifecycle = $self->{stream_lifecycle}{$id};
4322  
4323 64 my $transaction = $self->{transactions}{$id};
4324  
4325 64 ▶ if (defined($lifecycle) && defined($transaction)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lifecycle and defined $transaction) 27 37 64
Condition66%2/3
defined $lifecycle and defined $transaction
!ll&&!rl&&r
37027
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 27 ▶ if (defined $lifecycle->{remote_reset_code}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lifecycle->{"remote_reset_code"}) 0 27 27
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 27 ▶ if (defined $lifecycle->{remote_stop_sending_code}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lifecycle->{"remote_stop_sending_code"}) 0 27 27
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 64 $self->{messages}{$id} = $message;
4344 64 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 108 ▶sub _decimal_less_than {
Subroutine _decimal_less_than: called CC=6 SCAR=17.9
4369 108 my ($left, $right) = @_;
4370  
4371 108 $left = "$left";
4372 108 $right = "$right";
4373  
4374 108 $left =~ s/\A0+//;
4375 108 $right =~ s/\A0+//;
4376 108 ▶ $left = '0' if $left eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $left eq "" 1 107 108
4377 108 ▶ $right = '0' if $right eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $right eq "" 7 101 108
4378  
4379 108 ▶ return 1 if length($left) < length($right);
Branch: 1 branch
BranchTrueFalseTotal
if length $left < length $right 0 108 108
4380 108 ▶ return 0 if length($left) > length($right);
Branch: 1 branch
BranchTrueFalseTotal
if length $left > length $right 83 25 108
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 75 ▶sub _assert_peer_field_section_size_value {
Subroutine _assert_peer_field_section_size_value: called CC=2 SCAR=6.9
4398 75 my ($self, $size, $operation) = @_;
4399  
4400 75 my $limit = $self->{peer_max_field_section_size};
4401  
4402 75 ▶ croak "$operation: field section size $size exceeds peer "
Branch: 1 branch
BranchTrueFalseTotal
if _decimal_less_than($limit, $size) 1 74 75
4403 . "SETTINGS_MAX_FIELD_SECTION_SIZE $limit"
4404 if _decimal_less_than($limit, $size);
4405  
4406 74 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 40 ▶sub _submit_request {
Subroutine _submit_request: called CC=15 SCAR=32.4
4467 40 my ($self, $request, $streaming) = @_;
4468  
4469 croak 'request submission requires a client HTTP/3 connection'
4470 40 ▶ unless $self->{role} eq 'client';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "client" 0 40 40
4471 croak 'HTTP/3 connection has not been started'
4472 40 ▶ unless $self->{started};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"started"} 0 40 40
4473 40 ▶ croak 'request must implement the Uniform HTTP request contract'
Branch: 1 branch
BranchTrueFalseTotal
unless _request_contract($request) 0 40 40
4474 unless _request_contract($request);
4475 croak 'HTTP/3 peer has begun graceful shutdown'
4476 40 ▶ if defined $self->{remote_shutdown_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"remote_shutdown_id"} 0 40 40
4477 croak 'HTTP/3 connection is shutting down'
4478 40 ▶ if $self->{shutdown_notice_sent} || $self->{shutdown_started};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"shutdown_notice_sent"} or $self->{"shutdown_started"} 0 40 40
Condition33%1/3
$self->{"shutdown_notice_sent"} or $self->{"shutdown_started"}
l!l&&r!l&&!r
0040
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 40 my ($portable_fields, $portable_trailers);
4481  
4482 40 ▶ if (ref($request) eq 'Uniform::HTTP::Request') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $request eq 'Uniform::HTTP::Request') { } 40 0 40
4483 $self->_assert_peer_field_section_size_value(
4484 40 $self->{native}->uniform_request_field_section_size($request),
4485 'request()',
4486 );
4487  
4488 my $trailer_size =
4489 39 $self->{native}->uniform_trailer_field_section_size($request);
4490  
4491 39 ▶ $self->_assert_peer_field_section_size_value(
Branch: 1 branch
BranchTrueFalseTotal
if $trailer_size 2 37 39
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 39 my $stream = $self->{quic}->open_bidi_stream;
4510 39 ▶ if (!defined $stream) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $stream) 2 37 39
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 37 $self->{request_credit_blocked} = 0;
4517  
4518 37 my $id = $stream->id;
4519 37 $self->{streams}{$id} = $stream;
4520  
4521 37 ▶ $streaming = $streaming ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$streaming ? : 14 23 37
4522  
4523 37 ▶ if (ref($request) eq 'Uniform::HTTP::Request') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $request eq 'Uniform::HTTP::Request') { } 37 0 37
4524 $self->{native}->submit_uniform_request(
4525 37 $id,
4526 $request,
4527 $streaming,
4528 );
4529 37 $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 37 $self->{outgoing}{$id} = $request;
4548  
4549 37 $self->_drain_output;
4550  
4551 37 return $id;
4552 }
4553  
4554 29 ▶sub _submit_response {
Subroutine _submit_response: called CC=13 SCAR=32.0
4555 29 my ($self, $stream_id, $response) = @_;
4556  
4557 croak 'response submission requires a server HTTP/3 connection'
4558 29 ▶ unless $self->{role} eq 'server';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"role"} eq "server" 0 29 29
4559 croak 'HTTP/3 connection has not been started'
4560 29 ▶ unless $self->{started};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"started"} 0 29 29
4561 29 ▶ croak 'response must implement the Uniform HTTP response contract'
Branch: 1 branch
BranchTrueFalseTotal
unless _response_contract($response) 0 29 29
4562 unless _response_contract($response);
4563 croak 'unknown HTTP/3 request stream'
4564 29 ▶ unless defined $self->{streams}{$stream_id};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"streams"}{$stream_id} 0 29 29
4565  
4566 29 my ($portable_fields, $portable_trailers);
4567  
4568 29 ▶ if (ref($response) eq 'Uniform::HTTP::Response') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $response eq 'Uniform::HTTP::Response') { } 29 0 29
4569 $self->_assert_peer_field_section_size_value(
4570 29 $self->{native}->uniform_response_field_section_size($response),
4571 'respond()',
4572 );
4573  
4574 my $trailer_size =
4575 29 $self->{native}->uniform_trailer_field_section_size($response);
4576  
4577 29 ▶ $self->_assert_peer_field_section_size_value(
Branch: 1 branch
BranchTrueFalseTotal
if $trailer_size 2 27 29
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 29 my $transaction = $self->{transactions}{$stream_id};
4596 29 ▶ my $streaming = defined($transaction)
Branch: 1 branch
BranchTrueFalseTotal
defined $transaction && $transaction->_response_is_streaming ? : 8 21 29
Condition66%2/3
defined $transaction and $transaction->_response_is_streaming
!ll&&!rl&&r
0218
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 29 ▶ if (ref($response) eq 'Uniform::HTTP::Response') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $response eq 'Uniform::HTTP::Response') { } 29 0 29
4602 $self->{native}->submit_uniform_response(
4603 29 $stream_id,
4604 $response,
4605 $streaming,
4606 );
4607 29 $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 29 $self->_drain_output;
4627 29 return $response;
4628 }
4629  
4630 666 ▶sub _drain_output {
Subroutine _drain_output: called CC=20 SCAR=30.3
4631 666 my ($self) = @_;
4632  
4633 666 while (1) {
4634 922 ▶ if (my $pending = $self->{control_settings_pending}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pending = $self->{"control_settings_pending"}) 9 913 922
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 913 my $out = $self->{native}->next_write;
4663 913 ▶ last unless defined $out;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $out 666 247 913
4664  
4665 247 my ($id, $bytes, $fin) = @$out;
4666 247 ▶ my $stream = $self->{streams}{$id}
Branch: 1 branch
BranchTrueFalseTotal
my $stream = $self->{"streams"}{$id} or croak("libnghttp3 selected unknown QUIC stream $id") 247 0 247
4667 or croak "libnghttp3 selected unknown QUIC stream $id";
4668  
4669 247 ▶ 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 238 247
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
226129
not $self->{"control_settings_rewritten"} and defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"}
!ll&&!rl&&r
226021
not $self->{"control_settings_rewritten"} and defined $self->{"control_stream_id"}
!ll&&!rl&&r
226021
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 21 && 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 238 ▶ && $id == $self->{control_stream_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"} 13 225 238
Condition66%2/3
defined $self->{"control_stream_id"} and $id == $self->{"control_stream_id"}
!ll&&!rl&&r
022513
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 238 my $length = length($bytes);
4700 238 my $accepted = 0;
4701  
4702 238 ▶ if ($length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length) 228 10 238
4703 228 $accepted = $stream->send_some($bytes, limit_to_credit => 1);
4704 }
4705  
4706 238 $self->{native}->add_write_offset($id, $accepted);
4707  
4708 238 ▶ if ($fin && $accepted == $length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fin and $accepted == $length) 63 175 238
Condition100%3/3
$fin and $accepted == $length
!ll&&!rl&&r
173263
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 63 $stream->finish;
4710 63 $self->{output_finished}{$id} = 1;
4711 63 $self->_maybe_complete_transaction($id);
4712 }
4713  
4714 238 ▶ if ($accepted < $length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($accepted < $length) 10 228 238
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 228 ▶ last if !$length && !$fin;
Branch: 1 branch
BranchTrueFalseTotal
unless $length or $fin 0 228 228
Condition66%2/3
$length or $fin
l!l&&r!l&&!r
218100
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 666 return;
4725 }
4726  
4727 21 1;
4728  
4729 __END__
↑ Summary blib/lib/Unblock/HTTP3/Capsule/Stream.pm »