HTTP/Client.pm

filter: Statementstmt 80.9% 602 / 744 Branchbran 63.7% 352 / 552 Conditioncond 52.2% 283 / 542 MC/DCmcdc 31.3% 88 / 281 Subroutinesub 80.3% 49 / 61 Podpod 0.0% 0 / 11 totaltotal 62.7% 1374 / 2191 CC 479 SCAR 47.7
CC
479
Cov
67%
connect_websocket
756.0
request
229.5
_dispatch
210.6
CRAP 118.2
↑ Summary HTTP/Server.pm »
1 package Unblock::HTTP::Client;
2  
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use Scalar::Util qw(blessed refaddr weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use Uniform::HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use Unblock::HTTP::_Policy;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use Unblock::HTTP::_EngineFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 10 ▶use Unblock::HTTP::_ClientOperation;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶use Unblock::HTTP::_AltSvc;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 10 our $VERSION = '0.02';
15  
16 53 ▶sub new {
Subroutine new: called CC=31 SCAR=35.1
Pod undocumented
17 53 my ($class, @args) = @_;
18 53 ▶ croak 'new(): expected named arguments' if @args % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 53 53
19 53 my %option = @args;
20 53 my %protocols;
21 53 for my $name (qw(http1 http2 http3)) {
22 159 ▶ $protocols{$name} = delete $option{$name} if exists $option{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $option{$name} 59 100 159
23 }
24 53 my $policy = Unblock::HTTP::_Policy->new(%protocols, _websocket_role => 'client');
25 53 my %factory;
26 53 for my $name (qw(connect_stream connect_quic defer schedule_timer release_connection)) {
27 265 ▶ $factory{$name} = delete $option{$name} if exists $option{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $option{$name} 126 139 265
28 croak "new(): $name must be a coderef"
29 265 ▶ if exists($factory{$name}) && ref($factory{$name}) ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if exists $factory{$name} and ref $factory{$name} ne "CODE" 0 265 265
Condition66%2/3
exists $factory{$name} and ref $factory{$name} ne "CODE"
!ll&&!rl&&r
1391260
MC/DC0%0/2
exists $factory{$name} and ref $factory{$name} ne "CODE"
exists $factory{$name} ref $factory{$name} ne "CODE"
Truth table66%2/3
A and B
A= exists $factory{$name}B= ref $factory{$name} ne "CODE"
ABresult
0X0
100
111
30 }
31 53 ▶ croak 'new(): defer callback is required' unless $factory{defer};
Branch: 1 branch
BranchTrueFalseTotal
unless $factory{"defer"} 1 52 53
32 croak 'new(): connect_stream is required for HTTP/1 or HTTP/2'
33 if ($policy->enabled('http/1.1') || $policy->enabled('h2'))
34 52 ▶ && !$factory{connect_stream};
Branch: 1 branch
BranchTrueFalseTotal
if $policy->enabled("http/1.1") || $policy->enabled("h2") and not $factory{"connect_stream"} 1 51 52
Condition100%6/6
$policy->enabled("http/1.1") || $policy->enabled("h2") and not $factory{"connect_stream"}
!ll&&!rl&&r
10411
$policy->enabled("http/1.1") or $policy->enabled("h2")
l!l&&r!l&&!r
311110
MC/DC66%2/3
$policy->enabled("http/1.1") || $policy->enabled("h2") and not $factory{"connect_stream"}
$policy->enabled("http/1.1") $policy->enabled("h2") not $factory{"connect_stream"}
Truth table80%4/5
A or B and not(C)
A= $policy->enabled("http/1.1")B= $policy->enabled("h2")C= not $factory{"connect_stream"}
ABCresult
00X0
1X00
0100
1X11
0111
35 croak 'new(): connect_quic is required for HTTP/3'
36 51 ▶ if $policy->enabled('h3') && !$factory{connect_quic};
Branch: 1 branch
BranchTrueFalseTotal
if $policy->enabled("h3") and not $factory{"connect_quic"} 1 50 51
Condition100%3/3
$policy->enabled("h3") and not $factory{"connect_quic"}
!ll&&!rl&&r
39111
MC/DC100%2/2
$policy->enabled("h3") and not $factory{"connect_quic"}
$policy->enabled("h3") not $factory{"connect_quic"}
Truth table100%3/3
A and not(B)
A= $policy->enabled("h3")B= not $factory{"connect_quic"}
ABresult
0X0
100
111
37  
38 50 my $clock = delete $option{alt_svc_clock};
39 50 ▶ croak 'new(): alt_svc_clock must be a coderef'
Branch: 1 branch
BranchTrueFalseTotal
if defined $clock and ref $clock ne "CODE" 0 50 50
Condition66%2/3
defined $clock and ref $clock ne "CODE"
!ll&&!rl&&r
4910
MC/DC0%0/2
defined $clock and ref $clock ne "CODE"
defined $clock ref $clock ne "CODE"
Truth table66%2/3
A and B
A= defined $clockB= ref $clock ne "CODE"
ABresult
0X0
100
111
40 if defined($clock) && ref($clock) ne 'CODE';
41 50 ▶ my $alt_svc = Unblock::HTTP::_AltSvc->new(
Branch: 1 branch
BranchTrueFalseTotal
defined $clock ? : 1 49 50
42 (defined($clock) ? (clock => $clock) : ()),
43 );
44  
45 50 my $idle_timeout = delete $option{idle_timeout};
46 50 ▶ if (defined $idle_timeout) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $idle_timeout) 13 37 50
47 13 ▶ croak 'new(): idle_timeout must be a positive number of seconds'
Branch: 1 branch
BranchTrueFalseTotal
if ref $idle_timeout or not $idle_timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/ or $idle_timeout <= 0 5 8 13
Condition100%6/6
ref $idle_timeout or not $idle_timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/ or $idle_timeout <= 0
l!l&&r!l&&!r
418
ref $idle_timeout or not $idle_timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/
l!l&&r!l&&!r
139
MC/DC100%3/3
ref $idle_timeout or not $idle_timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/ or $idle_timeout <= 0
ref $idle_timeout not $idle_timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/ $idle_timeout <= 0
Truth table100%4/4
A or not(B) or C
A= ref $idle_timeoutB= not $idle_timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/C= $idle_timeout <= 0
ABCresult
1XX1
01X1
0011
0000
48 if ref($idle_timeout)
49 || $idle_timeout !~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/
50 || $idle_timeout <= 0;
51 croak 'new(): idle_timeout requires schedule_timer callback'
52 8 ▶ unless $factory{schedule_timer};
Branch: 1 branch
BranchTrueFalseTotal
unless $factory{"schedule_timer"} 1 7 8
53 7 $idle_timeout += 0;
54 }
55  
56 44 my %limit;
57 44 for my $key (qw(max_pending_requests max_connections_per_origin max_streams_per_connection)) {
58 132 ▶ my $default = $key eq 'max_pending_requests' ? 128
Branch: 2 branches
BranchTrueFalseTotal
$key eq 'max_pending_requests' ? : 44 88 132
$key eq 'max_connections_per_origin' ? : 44 44 88
59 : $key eq 'max_connections_per_origin' ? 4 : 32;
60 132 ▶ my $value = exists($option{$key}) ? delete($option{$key}) : $default;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{$key} ? : 30 102 132
61 132 ▶ croak "new(): $key must be a positive integer"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and not ref $value and $value =~ /\A[0-9]+\z/ and $value > 0 0 132 132
Condition33%3/9
defined $value and not ref $value and $value =~ /\A[0-9]+\z/ and $value > 0
!ll&&!rl&&r
00132
defined $value and not ref $value and $value =~ /\A[0-9]+\z/
!ll&&!rl&&r
00132
defined $value and not ref $value
!ll&&!rl&&r
00132
MC/DC0%0/4
defined $value and not ref $value and $value =~ /\A[0-9]+\z/ and $value > 0
defined $value not ref $value $value =~ /\A[0-9]+\z/ $value > 0
Truth table20%1/5
A and not(B) and C and D
A= defined $valueB= not ref $valueC= $value =~ /\A[0-9]+\z/D= $value > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
62 unless defined($value) && !ref($value)
63 && $value =~ /\A[0-9]+\z/ && $value > 0;
64 132 $limit{$key} = $value;
65 }
66 44 ▶ croak 'new(): unknown option: ' . join(', ', sort keys %option) if %option;
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 44 44
67 44 return bless {
68 policy => $policy,
69 factory => \%factory,
70 limit => \%limit,
71 pending_count => 0,
72 active_operations => {},
73 shutdown => 0,
74 pools => {},
75 alt_svc => $alt_svc,
76 idle_timeout => $idle_timeout,
77 }, $class;
78 }
79  
80 1 ▶sub protocols { $_[0]{policy}->protocols }
Subroutine protocols: called CC=1 SCAR=0.0
Pod undocumented
81 47 ▶sub alpn_protocols { $_[0]{policy}->alpn_protocols }
Subroutine alpn_protocols: called CC=1 SCAR=0.0
Pod undocumented
82 0 ▶sub supports { $_[0]{policy}->enabled($_[1]) }
Subroutine supports: not called CC=1 SCAR=6.9
Pod undocumented
83 24 ▶sub pending_count { $_[0]{pending_count} }
Subroutine pending_count: called CC=1 SCAR=0.0
Pod undocumented
84 2 ▶sub is_shutdown { $_[0]{shutdown} ? 1 : 0 }
Subroutine is_shutdown: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'shutdown'} ? : 1 1 2
85  
86 # A copied, observational-only snapshot. No transport or engine objects
87 # escape, and taking a snapshot never runs scheduler or timer callbacks.
88 17 ▶sub pool_stats {
Subroutine pool_stats: called CC=13 SCAR=25.8
Pod undocumented
89 17 my ($self) = @_;
90 my $total = {
91 origins => 0, connections => 0, active => 0, idle => 0,
92 retiring => 0, credit_blocked => 0, connecting => 0,
93 pending => $self->{pending_count},
94 17 by_origin => [],
95 };
96 17 for my $key (sort keys %{ $self->{pools} }) {
97 13 my $pool = $self->{pools}{$key};
98 my $one = {
99 scheme => $pool->{info}{scheme},
100 host => $pool->{info}{host},
101 port => $pool->{info}{port},
102 connections => 0, active => 0, idle => 0,
103 retiring => 0, credit_blocked => 0,
104 connecting => $pool->{connecting} ? 1 : 0,
105 13 ▶ pending => scalar @{ $pool->{pending} },
Branch: 1 branch
BranchTrueFalseTotal
$pool->{'connecting'} ? : 5 8 13
106 };
107 13 for my $conn (@{ $pool->{connections} }) {
108 7 $one->{connections}++;
109 7 $one->{active} += $conn->{active};
110 7 ▶ $one->{retiring}++ if $conn->{stale} || _retired($conn);
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"stale"} or _retired($conn) 3 4 7
Condition66%2/3
$conn->{"stale"} or _retired($conn)
l!l&&r!l&&!r
304
MC/DC50%1/2
$conn->{"stale"} or _retired($conn)
$conn->{"stale"} _retired($conn)
Truth table66%2/3
A or B
A= $conn->{"stale"}B= _retired($conn)
ABresult
1X1
011
000
111 7 ▶ $one->{credit_blocked}++ if $conn->{credit_blocked};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"credit_blocked"} 1 6 7
112 $one->{idle}++ if !$conn->{active} && !$conn->{credit_blocked}
113 7 ▶ && !$conn->{released} && !_closed($conn)
Branch: 1 branch
BranchTrueFalseTotal
unless $conn->{"active"} or $conn->{"credit_blocked"} or $conn->{"released"} or _closed($conn) or _retired($conn) 2 5 7
Condition75%9/12
$conn->{"active"} or $conn->{"credit_blocked"} or $conn->{"released"} or _closed($conn) or _retired($conn)
l!l&&r!l&&!r
502
$conn->{"active"} or $conn->{"credit_blocked"} or $conn->{"released"} or _closed($conn)
l!l&&r!l&&!r
502
$conn->{"active"} or $conn->{"credit_blocked"} or $conn->{"released"}
l!l&&r!l&&!r
502
$conn->{"active"} or $conn->{"credit_blocked"}
l!l&&r!l&&!r
412
MC/DC40%2/5
$conn->{"active"} or $conn->{"credit_blocked"} or $conn->{"released"} or _closed($conn) or _retired($conn)
$conn->{"active"} $conn->{"credit_blocked"} $conn->{"released"} _closed($conn) _retired($conn)
Truth table50%3/6
A or B or C or D or E
A= $conn->{"active"}B= $conn->{"credit_blocked"}C= $conn->{"released"}D= _closed($conn)E= _retired($conn)
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
114 && !_retired($conn);
115 }
116 13 for my $count (qw(connections active idle retiring credit_blocked connecting)) {
117 78 $total->{$count} += $one->{$count};
118 }
119 13 push @{ $total->{by_origin} }, $one;
120 13 $total->{origins}++;
121 }
122 17 return $total;
123 }
124  
125 # A framework explicitly invokes this when its network identity changes.
126 # No active transaction is replayed, cancelled or moved between engines.
127 # Stop new admission, cancel unsent work, and retire live connections.
128 # Accepted transactions finish normally; idle transports are released now.
129 5 ▶sub shutdown {
Subroutine shutdown: called CC=10 SCAR=23.1
Pod undocumented
130 5 my ($self) = @_;
131 5 ▶ return $self if $self->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"shutdown"} 1 4 5
132 4 $self->{shutdown} = 1;
133 4 $self->{alt_svc}->clear;
134 4 for my $pool (values %{ $self->{pools} }) {
135 local $pool->{callback_depth} =
136 4 ▶ ($pool->{callback_depth} || 0) + 1;
Condition50%1/2
$pool->{'callback_depth'} || 0
l!l
04
MC/DC0%0/1
$pool->{'callback_depth'} || 0
$pool->{'callback_depth'}
Truth table50%1/2
A
A= $pool->{'callback_depth'}
Aresult
11
00
137 4 for my $op (@{ [ @{ $pool->{pending} } ] }) {
138 2 ▶ $op->cancel unless $op->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $op->is_terminal 2 0 2
139 }
140 4 my @live;
141 4 for my $conn (@{ $pool->{connections} }) {
142 3 ▶ next if $conn->{released};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"released"} 0 3 3
143 3 $conn->{stale} = 1;
144 3 ▶ $self->_cancel_idle($conn) if $conn->{idle_cancel};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"idle_cancel"} 1 2 3
145 3 ▶ if ($conn->{active}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conn->{'active'}) { } 2 1 3
146 2 push @live, $conn;
147 } else {
148 1 $self->_release_connection($conn, 'shutdown');
149 }
150 }
151 4 $pool->{connections} = \@live;
152 4 $self->_delete_empty_pool($pool);
153 }
154 4 return $self;
155 }
156  
157 7 ▶sub network_changed {
Subroutine network_changed: called CC=14 SCAR=26.4
Pod undocumented
158 7 my ($self) = @_;
159 7 ▶ return if $self->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"shutdown"} 1 6 7
160 6 $self->{alt_svc}->clear;
161 6 for my $pool (values %{ $self->{pools} }) {
162 # Suppress synchronous reentry from user-owned release hooks.
163 6 ▶ local $pool->{callback_depth} = ($pool->{callback_depth} || 0) + 1;
Condition50%1/2
$pool->{'callback_depth'} || 0
l!l
06
MC/DC0%0/1
$pool->{'callback_depth'} || 0
$pool->{'callback_depth'}
Truth table50%1/2
A
A= $pool->{'callback_depth'}
Aresult
11
00
164 6 ▶ if (my $attempt = $pool->{attempt}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $attempt = $pool->{"attempt"}) 2 4 6
165 2 my $op = $attempt->{op};
166 2 $self->_abandon_connect($pool, $op);
167 2 ▶ $op->{state} = 'queued' unless $op->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $op->is_terminal 2 0 2
168 }
169 6 for my $op (@{ $pool->{pending} }) {
170 6 ▶ next if $op->is_terminal || !$op->{alt_svc};
Branch: 1 branch
BranchTrueFalseTotal
if $op->is_terminal or not $op->{"alt_svc"} 5 1 6
Condition66%2/3
$op->is_terminal or not $op->{"alt_svc"}
l!l&&r!l&&!r
051
MC/DC50%1/2
$op->is_terminal or not $op->{"alt_svc"}
$op->is_terminal not $op->{"alt_svc"}
Truth table66%2/3
A or not(B)
A= $op->is_terminalB= not $op->{"alt_svc"}
ABresult
1X1
011
000
171 1 delete $op->{alt_svc};
172 1 $op->{version} = 'tcp';
173 1 $op->{state} = 'queued';
174 }
175 6 my (@keep, @release);
176 6 for my $conn (@{ $pool->{connections} }) {
177 3 $conn->{stale} = 1;
178 3 ▶ $self->_cancel_idle($conn) if $conn->{idle_cancel};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"idle_cancel"} 1 2 3
179 3 ▶ if ($conn->{active}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conn->{'active'}) { } 1 2 3
180 1 push @keep, $conn;
181 } else {
182 2 push @release, $conn;
183 }
184 }
185 6 $pool->{connections} = \@keep;
186 6 $self->_release_connection($_, 'network_changed') for @release;
187 6 ▶ $self->_schedule($pool) if @{ $pool->{pending} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$pool->{"pending"};} 4 2 6
188 6 $self->_delete_empty_pool($pool);
189 }
190 6 return;
191 }
192  
193 # HTTP1 upgrades transfer the socket out of the pool. HTTP2 and HTTP3
194 # CONNECT use independent streams on a multiplexed pooled connection.
195 0 ▶sub connect_websocket {
Subroutine connect_websocket: not called CC=27 SCAR=66.3
Pod undocumented
196 0 my ($self, @args) = @_;
197 0 ▶ croak 'connect_websocket(): expected named arguments' if @args % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 0 0
198 0 my %option = @args;
199 0 my $http_version = delete $option{http_version};
200 $http_version = $self->{policy}->websocket_enabled('http/1.1') ? '1.1'
201 0 ▶ : $self->{policy}->websocket_enabled('h2') ? '2' : '3'
Branch: 3 branches
BranchTrueFalseTotal
unless defined $http_version 0 0 0
$self->{'policy'}->websocket_enabled('http/1.1') ? : 0 0 0
$self->{'policy'}->websocket_enabled('h2') ? : 0 0 0
202 unless defined $http_version;
203 0 ▶ croak 'connect_websocket(): http_version must be 1.1, 2 or 3'
Branch: 1 branch
BranchTrueFalseTotal
if ref $http_version or not $http_version =~ /\A(?:1\.1|2|3)\z/ 0 0 0
Condition0%0/3
ref $http_version or not $http_version =~ /\A(?:1\.1|2|3)\z/
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $http_version or not $http_version =~ /\A(?:1\.1|2|3)\z/
ref $http_version not $http_version =~ /\A(?:1\.1|2|3)\z/
Truth table0%0/3
A or not(B)
A= ref $http_versionB= not $http_version =~ /\A(?:1\.1|2|3)\z/
ABresult
1X1
011
000
204 if ref($http_version) || $http_version !~ /\A(?:1\.1|2|3)\z/;
205 0 ▶ my $ws_protocol = $http_version eq '3' ? 'h3'
Branch: 2 branches
BranchTrueFalseTotal
$http_version eq '3' ? : 0 0 0
$http_version eq '2' ? : 0 0 0
206 : $http_version eq '2' ? 'h2' : 'http/1.1';
207 croak "connect_websocket(): $ws_protocol websocket support is disabled"
208 0 ▶ unless $self->{policy}->websocket_enabled($ws_protocol);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"policy"}->websocket_enabled($ws_protocol) 0 0 0
209 0 my $url = delete $option{url};
210 0 ▶ croak 'connect_websocket(): url is required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url and not ref $url and length $url 0 0 0
Condition0%0/6
defined $url and not ref $url and length $url
!ll&&!rl&&r
000
defined $url and not ref $url
!ll&&!rl&&r
000
MC/DC0%0/3
defined $url and not ref $url and length $url
defined $url not ref $url length $url
Truth table0%0/4
A and not(B) and C
A= defined $urlB= not ref $urlC= length $url
ABCresult
0XX0
10X0
1100
1111
211 unless defined($url) && !ref($url) && length($url);
212 0 my %handshake_option;
213 0 for my $name (qw(headers origin subprotocols permessage_deflate)) {
214 $handshake_option{$name} = delete $option{$name}
215 0 ▶ if exists $option{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $option{$name} 0 0 0
216 }
217 0 my %session_option;
218 0 for my $name (qw(
219 backend max_message_size high_water low_water random_bytes
220 on_message on_ping on_pong on_close on_drain
221 )) {
222 $session_option{$name} = delete $option{$name}
223 0 ▶ if exists $option{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $option{$name} 0 0 0
224 }
225 0 my $on_open = delete $option{on_open};
226 0 ▶ croak 'connect_websocket(): on_open must be a coderef'
Branch: 1 branch
BranchTrueFalseTotal
if defined $on_open and ref $on_open ne "CODE" 0 0 0
Condition0%0/3
defined $on_open and ref $on_open ne "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $on_open and ref $on_open ne "CODE"
defined $on_open ref $on_open ne "CODE"
Truth table0%0/3
A and B
A= defined $on_openB= ref $on_open ne "CODE"
ABresult
0X0
100
111
227 if defined($on_open) && ref($on_open) ne 'CODE';
228 0 my $on_error = delete $option{on_error};
229 0 ▶ croak 'connect_websocket(): on_error must be a coderef'
Branch: 1 branch
BranchTrueFalseTotal
if defined $on_error and ref $on_error ne "CODE" 0 0 0
Condition0%0/3
defined $on_error and ref $on_error ne "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $on_error and ref $on_error ne "CODE"
defined $on_error ref $on_error ne "CODE"
Truth table0%0/3
A and B
A= defined $on_errorB= ref $on_error ne "CODE"
ABresult
0X0
100
111
230 if defined($on_error) && ref($on_error) ne 'CODE';
231 0 my $on_finish = delete $option{on_finish};
232 0 ▶ croak 'connect_websocket(): on_finish must be a coderef'
Branch: 1 branch
BranchTrueFalseTotal
if defined $on_finish and ref $on_finish ne "CODE" 0 0 0
Condition0%0/3
defined $on_finish and ref $on_finish ne "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $on_finish and ref $on_finish ne "CODE"
defined $on_finish ref $on_finish ne "CODE"
Truth table0%0/3
A and B
A= defined $on_finishB= ref $on_finish ne "CODE"
ABresult
0X0
100
111
233 if defined($on_finish) && ref($on_finish) ne 'CODE';
234 0 my $timeout = delete $option{timeout};
235 0 ▶ croak 'connect_websocket(): unknown option: ' . join(', ', sort keys %option)
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 0 0
236 if %option;
237  
238 0 require Unblock::WebSocket::Handshake;
239 0 my ($handshake, $request) =
240 Unblock::WebSocket::Handshake->client_request(
241 $url, http_version => $http_version, %handshake_option,
242 );
243 0 my $http_url = "$url";
244 0 $http_url =~ s/\Aws:/http:/i;
245 0 $http_url =~ s/\Awss:/https:/i;
246 0 my $spec = {
247 handshake => $handshake,
248 options => \%session_option,
249 on_open => $on_open,
250 };
251 0 ▶ return $self->request(
Branch: 3 branches
BranchTrueFalseTotal
defined $on_error ? : 0 0 0
defined $on_finish ? : 0 0 0
defined $timeout ? : 0 0 0
252 url => $http_url,
253 http_version => $http_version,
254 _websocket_request => $request,
255 _websocket_connect => $spec,
256 (defined($on_error) ? (on_error => $on_error) : ()),
257 (defined($on_finish) ? (on_finish => $on_finish) : ()),
258 (defined($timeout) ? (timeout => $timeout) : ()),
259 );
260 }
261  
262 522 ▶sub request {
Subroutine request: called CC=91 SCAR=54.4
Pod undocumented
263 522 my ($self, @args) = @_;
264 522 ▶ croak 'request(): Client is shut down' if $self->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"shutdown"} 1 521 522
265 521 ▶ croak 'request(): expected named arguments' if @args % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 521 521
266 521 my %field = @args;
267 521 my $ws_spec = delete $field{_websocket_connect};
268 521 my $ws_request = delete $field{_websocket_request};
269 521 ▶ croak 'request(): internal WebSocket options must occur together'
Branch: 1 branch
BranchTrueFalseTotal
if (!!$ws_spec) != !!$ws_request 0 521 521
270 if (!!$ws_spec) != (!!$ws_request);
271 croak 'request(): WebSocket option is disabled'
272 if $ws_spec && !$self->{policy}->websocket_enabled(
273 521 ▶ $ws_request->version eq '3' ? 'h3'
Branch: 3 branches
BranchTrueFalseTotal
if $ws_spec and not $self->{"policy"}->websocket_enabled($ws_request->version eq 3 ? "h3" : ($ws_request->version eq 2 ? "h2" : "http/1.1")) 0 521 521
$ws_request->version eq '3' ? : 0 0 0
$ws_request->version eq '2' ? : 0 0 0
Condition33%1/3
$ws_spec and not $self->{"policy"}->websocket_enabled($ws_request->version eq 3 ? "h3" : ($ws_request->version eq 2 ? "h2" : "http/1.1"))
!ll&&!rl&&r
52100
MC/DC0%0/2
$ws_spec and not $self->{"policy"}->websocket_enabled($ws_request->version eq 3 ? "h3" : ($ws_request->version eq 2 ? "h2" : "http/1.1"))
$ws_spec not $self->{"policy"}->websocket_enabled($ws_request->version eq 3 ? "h3" : ($ws_request->version eq 2 ? "h2" : "http/1.1"))
Truth table33%1/3
A and not(B)
A= $ws_specB= not $self->{"policy"}->websocket_enabled($ws_request->version eq 3 ? "h3" : ($ws_request->version eq 2 ? "h2" : "http/1.1"))
ABresult
0X0
100
111
274 : $ws_request->version eq '2' ? 'h2' : 'http/1.1'
275 );
276 521 my $url = delete $field{url};
277 521 ▶ croak 'request(): url is required' unless defined($url) && !ref($url) && length($url);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url and not ref $url and length $url 0 521 521
Condition33%2/6
defined $url and not ref $url and length $url
!ll&&!rl&&r
00521
defined $url and not ref $url
!ll&&!rl&&r
00521
MC/DC0%0/3
defined $url and not ref $url and length $url
defined $url not ref $url length $url
Truth table25%1/4
A and not(B) and C
A= defined $urlB= not ref $urlC= length $url
ABCresult
0XX0
10X0
1100
1111
278 521 my ($scheme, $host, $port, $authority, $target);
279 # Common canonical ASCII URLs need no URI object. Keep this match
280 # intentionally restrictive: noncanonical schemes/hosts, IPv6,
281 # escaping, fragments and exotic targets still use URI below.
282 # No URL cache, shared parser state or persistent allocation.
283 521 ▶ if ($url =~ m{
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ m[ \A (https?):// ([a-z0-9]+(?:[a-z0-9-]*[a-z0-9])? (?:\.[a-z0-9]+(?:[a-z0-9-]*[a-z0-9])?)*) (?::([1-9][0-9]{0,4}))? ([/?][A-Za-z0-9._~/?&=+\-]*)? \z ]x and !defined($3) || $3 <= 65535) { } 506 15 521
Condition100%6/6
$url =~ m[ \A (https?):// ([a-z0-9]+(?:[a-z0-9-]*[a-z0-9])? (?:\.[a-z0-9]+(?:[a-z0-9-]*[a-z0-9])?)*) (?::([1-9][0-9]{0,4}))? ([/?][A-Za-z0-9._~/?&=+\-]*)? \z ]x and !defined($3) || $3 <= 65535
!ll&&!rl&&r
141506
not defined $3 or $3 <= 65535
l!l&&r!l&&!r
50061
MC/DC100%3/3
$url =~ m[ \A (https?):// ([a-z0-9]+(?:[a-z0-9-]*[a-z0-9])? (?:\.[a-z0-9]+(?:[a-z0-9-]*[a-z0-9])?)*) (?::([1-9][0-9]{0,4}))? ([/?][A-Za-z0-9._~/?&=+\-]*)? \z ]x and !defined($3) || $3 <= 65535
$url =~ m[ \A (https?):// ([a-z0-9]+(?:[a-z0-9-]*[a-z0-9])? (?:\.[a-z0-9]+(?:[a-z0-9-]*[a-z0-9])?)*) (?::([1-9][0-9]{0,4}))? ([/?][A-Za-z0-9._~/?&=+\-]*)? \z ]x not defined $3 $3 <= 65535
Truth table100%4/4
A and not(B) or C
A= $url =~ m[ \A (https?):// ([a-z0-9]+(?:[a-z0-9-]*[a-z0-9])? (?:\.[a-z0-9]+(?:[a-z0-9-]*[a-z0-9])?)*) (?::([1-9][0-9]{0,4}))? ([/?][A-Za-z0-9._~/?&=+\-]*)? \z ]xB= not defined $3C= $3 <= 65535
ABCresult
0XX0
1000
11X1
1011
284 \A (https?)://
285 ([a-z0-9]+(?:[a-z0-9-]*[a-z0-9])?
286 (?:\.[a-z0-9]+(?:[a-z0-9-]*[a-z0-9])?)*)
287 (?::([1-9][0-9]{0,4}))?
288 ([/?][A-Za-z0-9._~/?&=+\-]*)?
289 \z
290 }x && (!defined($3) || $3 <= 65535)) {
291 506 my $given_port = $3;
292 506 ($scheme, $host) = ($1, $2);
293 506 ▶ $port = defined($given_port) ? $given_port
Branch: 2 branches
BranchTrueFalseTotal
defined $given_port ? : 6 500 506
$scheme eq 'https' ? : 456 44 500
294 : $scheme eq 'https' ? 443 : 80;
295 506 $authority = $host;
296 506 ▶ $authority .= ":$given_port" if defined $given_port;
Branch: 1 branch
BranchTrueFalseTotal
if defined $given_port 6 500 506
297 506 ▶ $target = defined($4) ? $4 : '/';
Branch: 1 branch
BranchTrueFalseTotal
defined $4 ? : 504 2 506
298 506 ▶ $target = '/' . $target if substr($target, 0, 1) eq '?';
Branch: 1 branch
BranchTrueFalseTotal
if substr($target, 0, 1) eq "?" 1 505 506
299 } else {
300 15 my $uri = URI->new($url);
301 15 ▶ $scheme = lc($uri->scheme || '');
Condition50%1/2
$uri->scheme || ''
l!l
150
MC/DC0%0/1
$uri->scheme || ''
$uri->scheme
Truth table50%1/2
A
A= $uri->scheme
Aresult
11
00
302 15 ▶ croak 'request(): URL scheme must be http or https'
Branch: 1 branch
BranchTrueFalseTotal
unless $scheme eq "http" or $scheme eq "https" 2 13 15
Condition100%3/3
$scheme eq "http" or $scheme eq "https"
l!l&&r!l&&!r
3102
MC/DC100%2/2
$scheme eq "http" or $scheme eq "https"
$scheme eq "http" $scheme eq "https"
Truth table100%3/3
A or B
A= $scheme eq "http"B= $scheme eq "https"
ABresult
1X1
011
000
303 unless $scheme eq 'http' || $scheme eq 'https';
304 13 ▶ croak 'request(): URL must not contain userinfo or a fragment'
Branch: 1 branch
BranchTrueFalseTotal
if defined $uri->userinfo or defined $uri->fragment 4 9 13
Condition100%3/3
defined $uri->userinfo or defined $uri->fragment
l!l&&r!l&&!r
229
MC/DC100%2/2
defined $uri->userinfo or defined $uri->fragment
defined $uri->userinfo defined $uri->fragment
Truth table100%3/3
A or B
A= defined $uri->userinfoB= defined $uri->fragment
ABresult
1X1
011
000
305 if defined($uri->userinfo) || defined($uri->fragment);
306 9 $host = $uri->host;
307 9 ▶ croak 'request(): URL must include a host'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host and length $host 0 9 9
Condition33%1/3
defined $host and length $host
!ll&&!rl&&r
009
MC/DC0%0/2
defined $host and length $host
defined $host length $host
Truth table33%1/3
A and B
A= defined $hostB= length $host
ABresult
0X0
100
111
308 unless defined($host) && length($host);
309 9 $port = $uri->port;
310 9 ▶ croak 'request(): invalid URL port'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $port and $port =~ /\A[0-9]+\z/ and $port > 0 and $port <= 65535 2 7 9
Condition66%6/9
defined $port and $port =~ /\A[0-9]+\z/ and $port > 0 and $port <= 65535
!ll&&!rl&&r
117
defined $port and $port =~ /\A[0-9]+\z/ and $port > 0
!ll&&!rl&&r
018
defined $port and $port =~ /\A[0-9]+\z/
!ll&&!rl&&r
009
MC/DC50%2/4
defined $port and $port =~ /\A[0-9]+\z/ and $port > 0 and $port <= 65535
defined $port $port =~ /\A[0-9]+\z/ $port > 0 $port <= 65535
Truth table60%3/5
A and B and C and D
A= defined $portB= $port =~ /\A[0-9]+\z/C= $port > 0D= $port <= 65535
ABCDresult
0XXX0
10XX0
110X0
11100
11111
311 unless defined($port) && $port =~ /\A[0-9]+\z/
312 && $port > 0 && $port <= 65535;
313 7 $authority = $uri->authority;
314 7 $target = $uri->path_query;
315 7 ▶ $target = '/' unless defined($target) && length($target);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target and length $target 0 7 7
Condition33%1/3
defined $target and length $target
!ll&&!rl&&r
007
MC/DC0%0/2
defined $target and length $target
defined $target length $target
Truth table33%1/3
A and B
A= defined $targetB= length $target
ABresult
0X0
100
111
316 7 ▶ $target = '/' . $target if substr($target, 0, 1) eq '?';
Branch: 1 branch
BranchTrueFalseTotal
if substr($target, 0, 1) eq "?" 0 7 7
317 }
318  
319 513 my $version = delete $field{http_version};
320 513 ▶ my $strict_version = defined($version) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $version ? : 40 473 513
321 513 ▶ if (defined $version) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $version) { } 40 473 513
322 40 ▶ croak 'request(): http_version must be 1.1, 2 or 3'
Branch: 1 branch
BranchTrueFalseTotal
if ref $version or not $version =~ /\A(?:1\.1|2|3)\z/ 1 39 40
Condition66%2/3
ref $version or not $version =~ /\A(?:1\.1|2|3)\z/
l!l&&r!l&&!r
0139
MC/DC50%1/2
ref $version or not $version =~ /\A(?:1\.1|2|3)\z/
ref $version not $version =~ /\A(?:1\.1|2|3)\z/
Truth table66%2/3
A or not(B)
A= ref $versionB= not $version =~ /\A(?:1\.1|2|3)\z/
ABresult
1X1
011
000
323 if ref($version) || $version !~ /\A(?:1\.1|2|3)\z/;
324 39 $version = { '1.1' => 'http/1.1', '2' => 'h2', '3' => 'h3' }->{$version};
325 croak "request(): required protocol '$version' is disabled"
326 39 ▶ unless $self->{policy}->enabled($version);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"policy"}->enabled($version) 1 38 39
327 38 ▶ croak 'request(): HTTP/3 requires https'
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "h3" and $scheme ne "https" 0 38 38
Condition66%2/3
$version eq "h3" and $scheme ne "https"
!ll&&!rl&&r
25130
MC/DC0%0/2
$version eq "h3" and $scheme ne "https"
$version eq "h3" $scheme ne "https"
Truth table66%2/3
A and B
A= $version eq "h3"B= $scheme ne "https"
ABresult
0X0
100
111
328 if $version eq 'h3' && $scheme ne 'https';
329 } else {
330 $version = ($self->{policy}->enabled('h2')
331 473 ▶ || $self->{policy}->enabled('http/1.1')) ? 'tcp' : 'h3';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'policy'}->enabled('h2') || $self->{'policy'}->enabled('http/1.1') ? : 340 133 473
Condition100%3/3
$self->{"policy"}->enabled("h2") or $self->{"policy"}->enabled("http/1.1")
l!l&&r!l&&!r
162178133
MC/DC100%2/2
$self->{"policy"}->enabled("h2") or $self->{"policy"}->enabled("http/1.1")
$self->{"policy"}->enabled("h2") $self->{"policy"}->enabled("http/1.1")
Truth table100%3/3
A or B
A= $self->{"policy"}->enabled("h2")B= $self->{"policy"}->enabled("http/1.1")
ABresult
1X1
011
000
332 473 ▶ croak 'request(): HTTP/3 requires https'
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "h3" and $scheme ne "https" 1 472 473
Condition100%3/3
$version eq "h3" and $scheme ne "https"
!ll&&!rl&&r
3401321
MC/DC100%2/2
$version eq "h3" and $scheme ne "https"
$version eq "h3" $scheme ne "https"
Truth table100%3/3
A and B
A= $version eq "h3"B= $scheme ne "https"
ABresult
0X0
100
111
333 if $version eq 'h3' && $scheme ne 'https';
334 }
335  
336 510 my %callbacks;
337 510 for my $name (qw(
338 on_response on_data on_end on_error on_finish on_informational on_drain
339 )) {
340 3570 ▶ next unless exists $field{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $field{$name} 3528 42 3570
341 42 my $cb = delete $field{$name};
342 42 ▶ croak "request(): $name must be a coderef" unless ref($cb) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cb eq "CODE" 0 42 42
343 42 $callbacks{$name} = $cb;
344 }
345 510 my $timeout = delete $field{timeout};
346 510 ▶ if (defined $timeout) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $timeout) 13 497 510
347 13 ▶ croak 'request(): timeout must be a positive number of seconds'
Branch: 1 branch
BranchTrueFalseTotal
if ref $timeout or not $timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/ or $timeout <= 0 4 9 13
Condition100%6/6
ref $timeout or not $timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/ or $timeout <= 0
l!l&&r!l&&!r
319
ref $timeout or not $timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/
l!l&&r!l&&!r
1210
MC/DC100%3/3
ref $timeout or not $timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/ or $timeout <= 0
ref $timeout not $timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/ $timeout <= 0
Truth table100%4/4
A or not(B) or C
A= ref $timeoutB= not $timeout =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/C= $timeout <= 0
ABCresult
1XX1
01X1
0011
0000
348 if ref($timeout) || $timeout !~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/
349 || $timeout <= 0;
350 croak 'request(): timeout requires schedule_timer callback'
351 9 ▶ unless $self->{factory}{schedule_timer};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"factory"}{"schedule_timer"} 1 8 9
352 }
353 505 ▶ my $stream_body = delete($field{stream_body}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $field{'stream_body'} ? : 0 505 505
354 croak 'request(): on_drain requires stream_body'
355 505 ▶ if $callbacks{on_drain} && !$stream_body;
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks{"on_drain"} and not $stream_body 0 505 505
Condition33%1/3
$callbacks{"on_drain"} and not $stream_body
!ll&&!rl&&r
50500
MC/DC0%0/2
$callbacks{"on_drain"} and not $stream_body
$callbacks{"on_drain"} not $stream_body
Truth table33%1/3
A and not(B)
A= $callbacks{"on_drain"}B= not $stream_body
ABresult
0X0
100
111
356 croak 'request(): pending queue is full'
357 505 ▶ if $self->{pending_count} >= $self->{limit}{max_pending_requests};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"pending_count"} >= $self->{"limit"}{"max_pending_requests"} 2 503 505
358 croak 'request(): do not pass scheme, authority or target with url'
359 503 ▶ if grep { exists($field{$_}) } qw(scheme authority target);
Branch: 1 branch
BranchTrueFalseTotal
if grep {exists $field{$_};} "scheme", "authority", "target" 0 503 503
360 503 ▶ $field{method} = 'GET' unless exists $field{method};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $field{"method"} 482 21 503
361 503 ▶ croak 'request(): internal WebSocket request cannot override HTTP fields'
Branch: 1 branch
BranchTrueFalseTotal
if $ws_request and keys %field > 1 0 503 503
Condition33%1/3
$ws_request and keys %field > 1
!ll&&!rl&&r
50300
MC/DC0%0/2
$ws_request and keys %field > 1
$ws_request keys %field > 1
Truth table33%1/3
A and B
A= $ws_requestB= keys %field > 1
ABresult
0X0
100
111
362 if $ws_request && keys %field > 1;
363 503 ▶ my $request = $ws_request || Uniform::HTTP::Request->new(
Condition33%1/3
$ws_request || 'Uniform::HTTP::Request'->new(%field, 'scheme', $scheme, 'authority', $authority, 'target', $target)
l!l&&r!l&&!r
05030
MC/DC0%0/2
$ws_request || 'Uniform::HTTP::Request'->new(%field, 'scheme', $scheme, 'authority', $authority, 'target', $target)
$ws_request 'Uniform::HTTP::Request'->new(%field, 'scheme', $scheme, 'authority', $authority, 'target', $target)
Truth table33%1/3
A || B
A= $ws_requestB= 'Uniform::HTTP::Request'->new(%field, 'scheme', $scheme, 'authority', $authority, 'target', $target)
ABresult
1X1
011
000
364 %field, scheme => $scheme, authority => $authority, target => $target,
365 );
366 503 ▶ if ($ws_request) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ws_request) 0 503 503
367 0 ▶ croak 'request(): WebSocket protocol and handshake version disagree'
Branch: 1 branch
BranchTrueFalseTotal
unless $version eq "http/1.1" and $request->version eq "1.1" or $version eq "h2" and $request->version eq 2 or $version eq "h3" and $request->version eq 3 0 0 0
Condition0%0/15
$version eq "http/1.1" and $request->version eq "1.1" or $version eq "h2" and $request->version eq 2 or $version eq "h3" and $request->version eq 3
l!l&&r!l&&!r
000
$version eq "http/1.1" and $request->version eq "1.1" or $version eq "h2" and $request->version eq 2
l!l&&r!l&&!r
000
$version eq "http/1.1" and $request->version eq "1.1"
!ll&&!rl&&r
000
$version eq "h2" and $request->version eq 2
!ll&&!rl&&r
000
$version eq "h3" and $request->version eq 3
!ll&&!rl&&r
000
MC/DC0%0/6
$version eq "http/1.1" and $request->version eq "1.1" or $version eq "h2" and $request->version eq 2 or $version eq "h3" and $request->version eq 3
$version eq "http/1.1" $request->version eq "1.1" $version eq "h2" $request->version eq 2 $version eq "h3" $request->version eq 3
Truth table0%0/15
A and B or C and D or E and F
A= $version eq "http/1.1"B= $request->version eq "1.1"C= $version eq "h2"D= $request->version eq 2E= $version eq "h3"F= $request->version eq 3
ABCDEFresult
11XXXX1
0X11XX1
1011XX1
0X0X111
0X10111
100X111
1010111
0X0X0X0
0X0X100
0X100X0
0X10100
100X0X0
100X100
10100X0
1010100
368 unless ($version eq 'http/1.1' && $request->version eq '1.1')
369 || ($version eq 'h2' && $request->version eq '2')
370 || ($version eq 'h3' && $request->version eq '3');
371 0 ▶ croak 'request(): WebSocket URL and handshake request disagree'
Branch: 1 branch
BranchTrueFalseTotal
unless $request->scheme eq $scheme and $request->authority eq $authority and $request->target eq $target 0 0 0
Condition0%0/6
$request->scheme eq $scheme and $request->authority eq $authority and $request->target eq $target
!ll&&!rl&&r
000
$request->scheme eq $scheme and $request->authority eq $authority
!ll&&!rl&&r
000
MC/DC0%0/3
$request->scheme eq $scheme and $request->authority eq $authority and $request->target eq $target
$request->scheme eq $scheme $request->authority eq $authority $request->target eq $target
Truth table0%0/4
A and B and C
A= $request->scheme eq $schemeB= $request->authority eq $authorityC= $request->target eq $target
ABCresult
0XX0
10X0
1100
1111
372 unless $request->scheme eq $scheme
373 && $request->authority eq $authority
374 && $request->target eq $target;
375 }
376 503 my $key = join('|', $scheme, lc($host), $port);
377 503 ▶ my $origin = $self->{pools}{$key} ||= {
Condition100%2/2
$self->{"pools"}{$key} ||= {"info", {"scheme", $scheme, "host", $host, "port", 0 + $port, "authority", $authority, "key", $key}, "pending", [], "connections", [], "connecting", 0, "pumping", 0, "scheduled", 0}
l!l
43865
MC/DC100%1/1
$self->{"pools"}{$key} ||= {"info", {"scheme", $scheme, "host", $host, "port", 0 + $port, "authority", $authority, "key", $key}, "pending", [], "connections", [], "connecting", 0, "pumping", 0, "scheduled", 0}
$self->{"pools"}{$key}
Truth table100%2/2
A
A= $self->{"pools"}{$key}
Aresult
11
00
378 info => {
379 scheme => $scheme, host => $host, port => 0 + $port,
380 authority => $authority,
381 key => $key,
382 },
383 pending => [],
384 connections => [],
385 connecting => 0,
386 pumping => 0,
387 scheduled => 0,
388 };
389 503 my $op = Unblock::HTTP::_ClientOperation->new(
390 $self, $request, \%callbacks, $version, $origin,
391 );
392 503 ▶ $op->{stream_body} = $ws_spec
Branch: 1 branch
BranchTrueFalseTotal
$ws_spec && ($version eq 'h2' || $version eq 'h3') ? : 0 503 503
Condition16%1/6
$ws_spec and $version eq "h2" || $version eq "h3"
!ll&&!rl&&r
50300
$version eq "h2" or $version eq "h3"
l!l&&r!l&&!r
000
MC/DC0%0/3
$ws_spec and $version eq "h2" || $version eq "h3"
$ws_spec $version eq "h2" $version eq "h3"
Truth table25%1/4
A and B or C
A= $ws_specB= $version eq "h2"C= $version eq "h3"
ABCresult
0XX0
1000
11X1
1011
393 && ($version eq 'h2' || $version eq 'h3') ? 1 : $stream_body;
394 503 ▶ $op->{websocket_connect} = $ws_spec if $ws_spec;
Branch: 1 branch
BranchTrueFalseTotal
if $ws_spec 0 503 503
395 503 ▶ if (!$strict_version && $scheme eq 'https'
Branch: 1 branch
BranchTrueFalseTotal
if (not $strict_version and $scheme eq "https" and $version eq "tcp" and $self->{"policy"}->enabled("h3")) 14 489 503
Condition100%9/9
not $strict_version and $scheme eq "https" and $version eq "tcp" and $self->{"policy"}->enabled("h3")
!ll&&!rl&&r
20428514
not $strict_version and $scheme eq "https" and $version eq "tcp"
!ll&&!rl&&r
72132299
not $strict_version and $scheme eq "https"
!ll&&!rl&&r
3834431
MC/DC100%4/4
not $strict_version and $scheme eq "https" and $version eq "tcp" and $self->{"policy"}->enabled("h3")
not $strict_version $scheme eq "https" $version eq "tcp" $self->{"policy"}->enabled("h3")
Truth table100%5/5
not(A) and B and C and D
A= not $strict_versionB= $scheme eq "https"C= $version eq "tcp"D= $self->{"policy"}->enabled("h3")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
396 && $version eq 'tcp' && $self->{policy}->enabled('h3')) {
397 14 my $advertised = $self->{alt_svc}->lookup($key);
398 14 ▶ if ($advertised) {
Branch: 1 branch
BranchTrueFalseTotal
if ($advertised) 5 9 14
399 5 $op->{alt_svc} = $advertised;
400 5 $op->{version} = 'h3';
401 }
402 }
403 503 ▶ if (defined $timeout) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $timeout) 8 495 503
404 my $cancel = $self->{factory}{schedule_timer}->(
405 6 ▶ 0 + $timeout, sub { $self->_request_timeout($op, $timeout) },
Subroutine __ANON__: called CC=1 SCAR=0.0
406 8 );
407 7 ▶ croak 'request(): schedule_timer must return a cancellation coderef'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cancel eq "CODE" 0 7 7
408 unless ref($cancel) eq 'CODE';
409 7 $op->{timer_cancel} = $cancel;
410 }
411 # A healthy, immediately admissible pooled connection needs no
412 # queue insertion, full pool scan or scheduler allocation. This is
413 # strictly an application-request path, never the per-byte path.
414 # Keep the general pump for pending work, reentrant callbacks,
415 # connecting factories and idle-expiration lifecycle management.
416 502 ▶ if (!defined($self->{idle_timeout})
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"idle_timeout"} || @{$origin->{"pending"};} || $origin->{"connecting"} || $origin->{"pumping"} || $origin->{"callback_depth"} || $origin->{"scheduled"} and @{$origin->{"connections"};} == 1) 417 85 502
Condition83%15/18
not defined $self->{"idle_timeout"} || @{$origin->{"pending"};} || $origin->{"connecting"} || $origin->{"pumping"} || $origin->{"callback_depth"} || $origin->{"scheduled"} and @{$origin->{"connections"};} == 1
!ll&&!rl&&r
2659417
defined $self->{'idle_timeout'} || @{$origin->{'pending'};} || $origin->{'connecting'} || $origin->{'pumping'} || $origin->{'callback_depth'} || $origin->{'scheduled'}
l!l&&r!l&&!r
260476
defined $self->{"idle_timeout"} or @{$origin->{"pending"};} or $origin->{"connecting"} or $origin->{"pumping"} or $origin->{"callback_depth"}
l!l&&r!l&&!r
251476
defined $self->{"idle_timeout"} or @{$origin->{"pending"};} or $origin->{"connecting"} or $origin->{"pumping"}
l!l&&r!l&&!r
250477
defined $self->{"idle_timeout"} or @{$origin->{"pending"};} or $origin->{"connecting"}
l!l&&r!l&&!r
250477
defined $self->{"idle_timeout"} or @{$origin->{"pending"};}
l!l&&r!l&&!r
1114477
MC/DC57%4/7
not defined $self->{"idle_timeout"} || @{$origin->{"pending"};} || $origin->{"connecting"} || $origin->{"pumping"} || $origin->{"callback_depth"} || $origin->{"scheduled"} and @{$origin->{"connections"};} == 1
defined $self->{"idle_timeout"} @{$origin->{"pending"};} $origin->{"connecting"} $origin->{"pumping"} $origin->{"callback_depth"} $origin->{'scheduled'} @{$origin->{"connections"};} == 1
Truth table62%5/8
not(A or B or C or D or E || F) and G
A= defined $self->{"idle_timeout"}B= @{$origin->{"pending"};}C= $origin->{"connecting"}D= $origin->{"pumping"}E= $origin->{"callback_depth"}F= $origin->{'scheduled'}G= @{$origin->{"connections"};} == 1
ABCDEFGresult
1XXXXXX0
01XXXXX0
001XXXX0
0001XXX0
00001XX0
000001X0
00000000
00000011
417 491 && !@{ $origin->{pending} }
418 && !$origin->{connecting}
419 && !$origin->{pumping}
420 && !$origin->{callback_depth}
421 && !$origin->{scheduled}
422 476 && @{ $origin->{connections} } == 1) {
423 417 my $conn = $origin->{connections}[0];
424 417 ▶ if ($self->_usable($conn, $op->{version}, $op)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_usable($conn, $op->{"version"}, $op)) 405 12 417
425 405 $self->_dispatch($origin, $conn, $op);
426 405 return $op;
427 }
428 }
429 97 push @{ $origin->{pending} }, $op;
430 97 $self->{pending_count}++;
431 97 $self->_pump($origin);
432 97 return $op;
433 }
434  
435 606 ▶sub _compatible {
Subroutine _compatible: called CC=3 SCAR=11.0
436 606 my ($version, $protocol) = @_;
437 606 ▶ return $protocol eq $version if $version ne 'tcp';
Branch: 1 branch
BranchTrueFalseTotal
if $version ne "tcp" 219 387 606
438 387 ▶ return $protocol eq 'h2' || $protocol eq 'http/1.1';
Condition100%3/3
$protocol eq 'h2' || $protocol eq 'http/1.1'
l!l&&r!l&&!r
1911951
MC/DC100%2/2
$protocol eq 'h2' || $protocol eq 'http/1.1'
$protocol eq 'h2' $protocol eq 'http/1.1'
Truth table100%3/3
A || B
A= $protocol eq 'h2'B= $protocol eq 'http/1.1'
ABresult
1X1
011
000
439 }
440  
441 # Connection retirement and temporary peer stream exhaustion are different.
442 # A SETTINGS limit of zero can later increase; do not close an idle H2
443 # connection merely because it cannot currently open a request.
444 1081 ▶sub _retired {
Subroutine _retired: called CC=13 SCAR=26.1
445 1081 my ($conn) = @_;
446 1081 my $engine = $conn->{engine};
447 1081 ▶ return 1 if $conn->{stale};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"stale"} 3 1078 1081
448 1078 ▶ return 1 if $conn->{protocol} eq 'http/1.1'
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"protocol"} eq "http/1.1" and $engine->can("is_switched") and $engine->is_switched 0 1078 1078
Condition50%3/6
$conn->{"protocol"} eq "http/1.1" and $engine->can("is_switched") and $engine->is_switched
!ll&&!rl&&r
107800
$conn->{"protocol"} eq "http/1.1" and $engine->can("is_switched")
!ll&&!rl&&r
6764020
MC/DC0%0/3
$conn->{"protocol"} eq "http/1.1" and $engine->can("is_switched") and $engine->is_switched
$conn->{"protocol"} eq "http/1.1" $engine->can("is_switched") $engine->is_switched
Truth table50%2/4
A and B and C
A= $conn->{"protocol"} eq "http/1.1"B= $engine->can("is_switched")C= $engine->is_switched
ABCresult
0XX0
10X0
1100
1111
449 && $engine->can('is_switched') && $engine->is_switched;
450 1078 ▶ if ($conn->{protocol} eq 'h2') {
Branch: 1 branch
BranchTrueFalseTotal
if ($conn->{"protocol"} eq "h2") 363 715 1078
451 363 ▶ return $engine->can('draining') && $engine->draining ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$engine->can('draining') && $engine->draining ? : 8 355 363
Condition100%3/3
$engine->can("draining") and $engine->draining
!ll&&!rl&&r
327288
MC/DC100%2/2
$engine->can("draining") and $engine->draining
$engine->can("draining") $engine->draining
Truth table100%3/3
A and B
A= $engine->can("draining")B= $engine->draining
ABresult
0X0
100
111
452 }
453 715 ▶ if ($conn->{protocol} eq 'h3') {
Branch: 1 branch
BranchTrueFalseTotal
if ($conn->{"protocol"} eq "h3") 313 402 715
454 313 ▶ return 1 if $engine->can('shutdown_started') && $engine->shutdown_started;
Branch: 1 branch
BranchTrueFalseTotal
if $engine->can("shutdown_started") and $engine->shutdown_started 0 313 313
Condition66%2/3
$engine->can("shutdown_started") and $engine->shutdown_started
!ll&&!rl&&r
287260
MC/DC0%0/2
$engine->can("shutdown_started") and $engine->shutdown_started
$engine->can("shutdown_started") $engine->shutdown_started
Truth table66%2/3
A and B
A= $engine->can("shutdown_started")B= $engine->shutdown_started
ABresult
0X0
100
111
455 313 ▶ return 1 if $engine->can('remote_shutdown_id')
Branch: 1 branch
BranchTrueFalseTotal
if $engine->can("remote_shutdown_id") and defined $engine->remote_shutdown_id 2 311 313
Condition100%3/3
$engine->can("remote_shutdown_id") and defined $engine->remote_shutdown_id
!ll&&!rl&&r
287242
MC/DC100%2/2
$engine->can("remote_shutdown_id") and defined $engine->remote_shutdown_id
$engine->can("remote_shutdown_id") defined $engine->remote_shutdown_id
Truth table100%3/3
A and B
A= $engine->can("remote_shutdown_id")B= defined $engine->remote_shutdown_id
ABresult
0X0
100
111
456 && defined $engine->remote_shutdown_id;
457 }
458 713 return 0;
459 }
460  
461 1081 ▶sub _closed {
Subroutine _closed: called CC=3 SCAR=11.7
462 1081 my ($conn) = @_;
463 return $conn->{protocol} eq 'h3'
464 ? ($conn->{engine}->failed || $conn->{host}->closed)
465 1081 ▶ : $conn->{engine}->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
$conn->{'protocol'} eq 'h3' ? : 313 768 1081
Condition33%1/3
$conn->{"engine"}->failed or $conn->{"host"}->closed
l!l&&r!l&&!r
00313
MC/DC0%0/2
$conn->{"engine"}->failed or $conn->{"host"}->closed
$conn->{"engine"}->failed $conn->{"host"}->closed
Truth table33%1/3
A or B
A= $conn->{"engine"}->failedB= $conn->{"host"}->closed
ABresult
1X1
011
000
466 }
467  
468 542 ▶sub _usable {
Subroutine _usable: called CC=19 SCAR=39.3
469 542 my ($self, $conn, $version, $op) = @_;
470 542 ▶ return 0 unless _compatible($version, $conn->{protocol});
Branch: 1 branch
BranchTrueFalseTotal
unless _compatible($version, $conn->{"protocol"}) 20 522 542
471 return 0 if $conn->{released} || _closed($conn) || _retired($conn)
472 522 ▶ || $conn->{credit_blocked};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"released"} or _closed($conn) or _retired($conn) or $conn->{"credit_blocked"} 9 513 522
Condition66%6/9
$conn->{"released"} or _closed($conn) or _retired($conn) or $conn->{"credit_blocked"}
l!l&&r!l&&!r
81513
$conn->{"released"} or _closed($conn) or _retired($conn)
l!l&&r!l&&!r
08514
$conn->{"released"} or _closed($conn)
l!l&&r!l&&!r
00522
MC/DC50%2/4
$conn->{"released"} or _closed($conn) or _retired($conn) or $conn->{"credit_blocked"}
$conn->{"released"} _closed($conn) _retired($conn) $conn->{"credit_blocked"}
Truth table60%3/5
A or B or C or D
A= $conn->{"released"}B= _closed($conn)C= _retired($conn)D= $conn->{"credit_blocked"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
473 513 ▶ if ($op && $op->{websocket_connect}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op and $op->{"websocket_connect"}) 0 513 513
Condition33%1/3
$op and $op->{"websocket_connect"}
!ll&&!rl&&r
05130
MC/DC0%0/2
$op and $op->{"websocket_connect"}
$op $op->{"websocket_connect"}
Truth table33%1/3
A and B
A= $opB= $op->{"websocket_connect"}
ABresult
0X0
100
111
474 return 0 if $version eq 'h2'
475 && (!$conn->{h2_settings_seen}
476 0 ▶ || $conn->{engine}->peer_setting('enable_connect_protocol') != 1);
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "h2" and !$conn->{"h2_settings_seen"} || $conn->{"engine"}->peer_setting("enable_connect_protocol") != 1 0 0 0
Condition0%0/6
$version eq "h2" and !$conn->{"h2_settings_seen"} || $conn->{"engine"}->peer_setting("enable_connect_protocol") != 1
!ll&&!rl&&r
000
not $conn->{"h2_settings_seen"} or $conn->{"engine"}->peer_setting("enable_connect_protocol") != 1
l!l&&r!l&&!r
000
MC/DC0%0/3
$version eq "h2" and !$conn->{"h2_settings_seen"} || $conn->{"engine"}->peer_setting("enable_connect_protocol") != 1
$version eq "h2" not $conn->{"h2_settings_seen"} $conn->{"engine"}->peer_setting("enable_connect_protocol") != 1
Truth table0%0/4
A and not(B) or C
A= $version eq "h2"B= not $conn->{"h2_settings_seen"}C= $conn->{"engine"}->peer_setting("enable_connect_protocol") != 1
ABCresult
0XX0
1000
11X1
1011
477 return 0 if $version eq 'h3'
478 && (!$conn->{engine}->peer_settings_received
479 0 ▶ || !$conn->{engine}->peer_extended_connect_enabled);
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "h3" and not $conn->{"engine"}->peer_settings_received && $conn->{"engine"}->peer_extended_connect_enabled 0 0 0
Condition0%0/6
$version eq "h3" and not $conn->{"engine"}->peer_settings_received && $conn->{"engine"}->peer_extended_connect_enabled
!ll&&!rl&&r
000
$conn->{'engine'}->peer_settings_received && $conn->{'engine'}->peer_extended_connect_enabled
!ll&&!rl&&r
000
MC/DC0%0/3
$version eq "h3" and not $conn->{"engine"}->peer_settings_received && $conn->{"engine"}->peer_extended_connect_enabled
$version eq "h3" $conn->{'engine'}->peer_settings_received $conn->{'engine'}->peer_extended_connect_enabled
Truth table0%0/4
A and not(B && C)
A= $version eq "h3"B= $conn->{'engine'}->peer_settings_receivedC= $conn->{'engine'}->peer_extended_connect_enabled
ABCresult
0XX0
1110
10X1
1101
480 }
481 my $capacity = $conn->{protocol} eq 'http/1.1'
482 513 ▶ ? 1 : $self->{limit}{max_streams_per_connection};
Branch: 1 branch
BranchTrueFalseTotal
$conn->{'protocol'} eq 'http/1.1' ? : 194 319 513
483 513 ▶ return 0 if $conn->{active} >= $capacity;
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"active"} >= $capacity 14 499 513
484 return 0 if $conn->{protocol} eq 'h2'
485 && $conn->{engine}->can('can_open_transaction')
486 499 ▶ && !$conn->{engine}->can_open_transaction;
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"protocol"} eq "h2" and $conn->{"engine"}->can("can_open_transaction") and not $conn->{"engine"}->can_open_transaction 4 495 499
Condition83%5/6
$conn->{"protocol"} eq "h2" and $conn->{"engine"}->can("can_open_transaction") and not $conn->{"engine"}->can_open_transaction
!ll&&!rl&&r
3341614
$conn->{"protocol"} eq "h2" and $conn->{"engine"}->can("can_open_transaction")
!ll&&!rl&&r
3340165
MC/DC66%2/3
$conn->{"protocol"} eq "h2" and $conn->{"engine"}->can("can_open_transaction") and not $conn->{"engine"}->can_open_transaction
$conn->{"protocol"} eq "h2" $conn->{"engine"}->can("can_open_transaction") not $conn->{"engine"}->can_open_transaction
Truth table75%3/4
A and B and not(C)
A= $conn->{"protocol"} eq "h2"B= $conn->{"engine"}->can("can_open_transaction")C= not $conn->{"engine"}->can_open_transaction
ABCresult
0XX0
10X0
1100
1111
487 495 return 1;
488 }
489  
490 # A pooled transport is released once. The framework may own the socket
491 # and its close semantics, so allow its adapter to perform final cleanup.
492 20 ▶sub _cancel_idle {
Subroutine _cancel_idle: called CC=3 SCAR=11.0
493 20 my ($self, $conn) = @_;
494 20 $conn->{idle_generation}++;
495 20 ▶ my $cancel = delete $conn->{idle_cancel} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $cancel = delete $conn->{"idle_cancel"} or return 3 17 20
496 3 ▶ eval { $cancel->(); 1 } or warn "idle timer cancellation failed: $@";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { &$cancel(); 1 } } or warn "idle timer cancellation failed: $@" 3 0 3
497 3 return;
498 }
499  
500 17 ▶sub _release_connection {
Subroutine _release_connection: called CC=6 SCAR=18.2
501 17 my ($self, $conn, $reason) = @_;
502 17 ▶ return if $conn->{released};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"released"} 0 17 17
503 17 $conn->{released} = 1;
504 17 $self->_cancel_idle($conn);
505 17 my $release = $self->{factory}{release_connection};
506 17 my $ok = eval {
507 17 ▶ if ($release) {
Branch: 3 branches
BranchTrueFalseTotal
if ($release) { } 10 7 17
elsif ($conn->{'engine'}->can('close')) { } 6 1 7
elsif ($conn->{'host'}->can('close')) { } 0 1 1
508 10 $release->($conn->{host}, $conn->{engine}, $conn->{protocol}, $reason);
509 } elsif ($conn->{engine}->can('close')) {
510 6 $conn->{engine}->close;
511 } elsif ($conn->{host}->can('close')) {
512 # Current HTTP/3 Client has no close(), but Net::QUIC does.
513 0 $conn->{host}->close;
514 }
515 17 1;
516 };
517 17 ▶ warn "connection release failed: $@" unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 17 17
518 17 return;
519 }
520  
521 7 ▶sub _drop_connection {
Subroutine _drop_connection: called CC=2 SCAR=7.0
522 7 my ($self, $pool, $conn, $reason) = @_;
523 7 ▶ return if $conn->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"active"} 0 7 7
524 $pool->{connections} = [
525 7 grep { $_ != $conn } @{ $pool->{connections} }
526 ];
527 7 $self->_release_connection($conn, $reason);
528 7 $self->_delete_empty_pool($pool);
529 7 return;
530 }
531  
532 185 ▶sub _delete_empty_pool {
Subroutine _delete_empty_pool: called CC=6 SCAR=18.1
533 185 my ($self, $pool) = @_;
534 return if $pool->{connecting}
535 185 ▶ || @{ $pool->{pending} } || @{ $pool->{connections} };
Branch: 1 branch
BranchTrueFalseTotal
if $pool->{"connecting"} or @{$pool->{"pending"};} or @{$pool->{"connections"};} 173 12 185
Condition100%6/6
$pool->{"connecting"} or @{$pool->{"pending"};} or @{$pool->{"connections"};}
l!l&&r!l&&!r
848912
$pool->{"connecting"} or @{$pool->{"pending"};}
l!l&&r!l&&!r
5826101
MC/DC100%3/3
$pool->{"connecting"} or @{$pool->{"pending"};} or @{$pool->{"connections"};}
$pool->{"connecting"} @{$pool->{"pending"};} @{$pool->{"connections"};}
Truth table100%4/4
A or B or C
A= $pool->{"connecting"}B= @{$pool->{"pending"};}C= @{$pool->{"connections"};}
ABCresult
1XX1
01X1
0011
0000
536 12 my $key = $pool->{info}{key};
537 delete $self->{pools}{$key}
538 if exists $self->{pools}{$key}
539 12 ▶ && $self->{pools}{$key} == $pool;
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"pools"}{$key} and $self->{"pools"}{$key} == $pool 12 0 12
Condition33%1/3
exists $self->{"pools"}{$key} and $self->{"pools"}{$key} == $pool
!ll&&!rl&&r
0012
MC/DC0%0/2
exists $self->{"pools"}{$key} and $self->{"pools"}{$key} == $pool
exists $self->{"pools"}{$key} $self->{"pools"}{$key} == $pool
Truth table33%1/3
A and B
A= exists $self->{"pools"}{$key}B= $self->{"pools"}{$key} == $pool
ABresult
0X0
100
111
540 12 return;
541 }
542  
543 336 ▶sub _sync_idle {
Subroutine _sync_idle: called CC=11 SCAR=24.5
544 336 my ($self, $pool) = @_;
545 336 my $idle_timeout = $self->{idle_timeout};
546 336 ▶ return unless defined $idle_timeout;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $idle_timeout 294 42 336
547 42 ▶ my $waiting = $pool->{connecting} || @{ $pool->{pending} };
Condition100%3/3
$pool->{'connecting'} || @{$pool->{'pending'};}
l!l&&r!l&&!r
11328
MC/DC100%2/2
$pool->{'connecting'} || @{$pool->{'pending'};}
$pool->{'connecting'} @{$pool->{'pending'};}
Truth table100%3/3
A || B
A= $pool->{'connecting'}B= @{$pool->{'pending'};}
ABresult
1X1
011
000
548 42 for my $conn (@{ $pool->{connections} }) {
549 33 ▶ if ($waiting || $conn->{active} || $conn->{released}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($waiting or $conn->{"active"} or $conn->{"released"}) 17 16 33
Condition83%5/6
$waiting or $conn->{"active"} or $conn->{"released"}
l!l&&r!l&&!r
17016
$waiting or $conn->{"active"}
l!l&&r!l&&!r
51216
MC/DC66%2/3
$waiting or $conn->{"active"} or $conn->{"released"}
$waiting $conn->{"active"} $conn->{"released"}
Truth table75%3/4
A or B or C
A= $waitingB= $conn->{"active"}C= $conn->{"released"}
ABCresult
1XX1
01X1
0011
0000
550 17 ▶ $self->_cancel_idle($conn) if $conn->{idle_cancel};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"idle_cancel"} 1 16 17
551 17 next;
552 }
553 16 ▶ next if $conn->{idle_cancel};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"idle_cancel"} 8 8 16
554 8 my $generation = ++$conn->{idle_generation};
555 8 my $weak_self = $self;
556 8 my $weak_pool = $pool;
557 8 my $weak_conn = $conn;
558 8 weaken($weak_self);
559 8 weaken($weak_pool);
560 8 weaken($weak_conn);
561 8 my $ok = eval {
562 my $cancel = $self->{factory}{schedule_timer}->(
563 $idle_timeout,
564 9 ▶ sub {
Subroutine __ANON__: called CC=9 SCAR=24.8
565 9 ▶ return unless $weak_self && $weak_pool && $weak_conn;
Branch: 1 branch
BranchTrueFalseTotal
unless $weak_self and $weak_pool and $weak_conn 3 6 9
Condition66%4/6
$weak_self and $weak_pool and $weak_conn
!ll&&!rl&&r
306
$weak_self and $weak_pool
!ll&&!rl&&r
036
MC/DC33%1/3
$weak_self and $weak_pool and $weak_conn
$weak_self $weak_pool $weak_conn
Truth table50%2/4
A and B and C
A= $weak_selfB= $weak_poolC= $weak_conn
ABCresult
0XX0
10X0
1100
1111
566 6 ▶ return unless $weak_conn->{idle_generation} == $generation;
Branch: 1 branch
BranchTrueFalseTotal
unless $weak_conn->{"idle_generation"} == $generation 1 5 6
567 5 delete $weak_conn->{idle_cancel};
568 return if $weak_conn->{released}
569 || $weak_conn->{active}
570 || $weak_pool->{connecting}
571 5 ▶ || @{ $weak_pool->{pending} };
Branch: 1 branch
BranchTrueFalseTotal
if $weak_conn->{"released"} or $weak_conn->{"active"} or $weak_pool->{"connecting"} or @{$weak_pool->{"pending"};} 0 5 5
Condition33%3/9
$weak_conn->{"released"} or $weak_conn->{"active"} or $weak_pool->{"connecting"} or @{$weak_pool->{"pending"};}
l!l&&r!l&&!r
005
$weak_conn->{"released"} or $weak_conn->{"active"} or $weak_pool->{"connecting"}
l!l&&r!l&&!r
005
$weak_conn->{"released"} or $weak_conn->{"active"}
l!l&&r!l&&!r
005
MC/DC0%0/4
$weak_conn->{"released"} or $weak_conn->{"active"} or $weak_pool->{"connecting"} or @{$weak_pool->{"pending"};}
$weak_conn->{"released"} $weak_conn->{"active"} $weak_pool->{"connecting"} @{$weak_pool->{"pending"};}
Truth table20%1/5
A or B or C or D
A= $weak_conn->{"released"}B= $weak_conn->{"active"}C= $weak_pool->{"connecting"}D= @{$weak_pool->{"pending"};}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
572 5 $weak_self->_drop_connection(
573 $weak_pool, $weak_conn, 'idle_timeout',
574 );
575 },
576 8 );
577 8 ▶ die "schedule_timer must return cancellation coderef\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cancel eq "CODE" 0 8 8
578 unless ref($cancel) eq 'CODE';
579 8 $conn->{idle_cancel} = $cancel;
580 8 1;
581 };
582 8 ▶ warn "idle timer setup failed: $@" unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 8 8
583 }
584 42 return;
585 }
586  
587 205 ▶sub _pump {
Subroutine _pump: called CC=35 SCAR=46.7
588 205 my ($self, $pool) = @_;
589 205 ▶ return if $self->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"shutdown"} 0 205 205
590 # Application on_finish can synchronously enqueue another request.
591 # Wait for the engine terminal callback to unwind before reusing H1.
592 205 ▶ return if $pool->{pumping} || $pool->{callback_depth};
Branch: 1 branch
BranchTrueFalseTotal
if $pool->{"pumping"} or $pool->{"callback_depth"} 37 168 205
Condition100%3/3
$pool->{"pumping"} or $pool->{"callback_depth"}
l!l&&r!l&&!r
361168
MC/DC100%2/2
$pool->{"pumping"} or $pool->{"callback_depth"}
$pool->{"pumping"} $pool->{"callback_depth"}
Truth table100%3/3
A or B
A= $pool->{"pumping"}B= $pool->{"callback_depth"}
ABresult
1X1
011
000
593 168 local $pool->{pumping} = 1;
594 168 my $attempt_budget = $self->{limit}{max_connections_per_origin};
595 168 my @kept;
596 168 for my $conn (@{ $pool->{connections} }) {
597 93 ▶ if ($conn->{active} || (!_closed($conn) && !_retired($conn))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conn->{'active'} or not _closed($conn) || _retired($conn)) { } 89 4 93
Condition83%5/6
$conn->{"active"} or not _closed($conn) || _retired($conn)
l!l&&r!l&&!r
8814
_closed($conn) || _retired($conn)
l!l&&r!l&&!r
0481
MC/DC66%2/3
$conn->{"active"} or not _closed($conn) || _retired($conn)
$conn->{"active"} _closed($conn) _retired($conn)
Truth table75%3/4
A or not(B || C)
A= $conn->{"active"}B= _closed($conn)C= _retired($conn)
ABCresult
1XX1
0001
01X0
0010
598 89 push @kept, $conn;
599 } else {
600 $self->_release_connection($conn,
601 _closed($conn) ? 'closed'
602 4 ▶ : $conn->{stale} ? 'network_changed' : 'draining');
Branch: 2 branches
BranchTrueFalseTotal
_closed($conn) ? : 0 4 4
$conn->{'stale'} ? : 1 3 4
603 }
604 }
605 168 $pool->{connections} = \@kept;
606 # Pending demand is not idle, even if the peer temporarily offers no
607 # H2/H3 request stream credit.
608 168 $self->_sync_idle($pool);
609 168 ▶ while (@{ $pool->{pending} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$pool->{"pending"};}) 201 89 290
610 201 my $op = $pool->{pending}[0];
611 201 ▶ if ($op->is_terminal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->is_terminal) 0 201 201
612 0 shift @{ $pool->{pending} };
613 0 $self->{pending_count}--;
614 0 next;
615 }
616 # Extended CONNECT is only legal after current peer SETTINGS.
617 # Wait on an existing protocol connection without opening more
618 # sockets. If its peer explicitly disables Extended CONNECT,
619 # reject this unsent operation rather than downgrading/replaying.
620 201 ▶ if ($op->{websocket_connect}
Branch: 1 branch
BranchTrueFalseTotal
if ($op->{"websocket_connect"} and $op->{"version"} eq "h2" || $op->{"version"} eq "h3") 0 201 201
Condition16%1/6
$op->{"websocket_connect"} and $op->{"version"} eq "h2" || $op->{"version"} eq "h3"
!ll&&!rl&&r
20100
$op->{"version"} eq "h2" or $op->{"version"} eq "h3"
l!l&&r!l&&!r
000
MC/DC0%0/3
$op->{"websocket_connect"} and $op->{"version"} eq "h2" || $op->{"version"} eq "h3"
$op->{"websocket_connect"} $op->{"version"} eq "h2" $op->{"version"} eq "h3"
Truth table25%1/4
A and B or C
A= $op->{"websocket_connect"}B= $op->{"version"} eq "h2"C= $op->{"version"} eq "h3"
ABCresult
0XX0
1000
11X1
1011
621 && ($op->{version} eq 'h2' || $op->{version} eq 'h3')) {
622 0 my $version = $op->{version};
623 my @existing = grep {
624 $_->{protocol} eq $version && !$_->{released}
625 0 ▶ && !_closed($_) && !_retired($_)
Condition0%0/9
$_->{'protocol'} eq $version && !$_->{'released'} && !_closed($_) && !_retired($_)
!ll&&!rl&&r
000
$_->{"protocol"} eq $version and not $_->{"released"} and not _closed($_)
!ll&&!rl&&r
000
$_->{"protocol"} eq $version and not $_->{"released"}
!ll&&!rl&&r
000
MC/DC0%0/4
$_->{'protocol'} eq $version && !$_->{'released'} && !_closed($_) && !_retired($_)
$_->{"protocol"} eq $version not $_->{"released"} not _closed($_) !_retired($_)
Truth table0%0/5
A and not(B) and not(C) && not(D)
A= $_->{"protocol"} eq $versionB= not $_->{"released"}C= not _closed($_)D= !_retired($_)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
626 0 } @{ $pool->{connections} };
627 0 ▶ my $ready = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
628 0 my ($conn) = @_;
629 return $version eq 'h2'
630 ? ($conn->{h2_settings_seen}
631 && $conn->{engine}->peer_setting(
632 'enable_connect_protocol') == 1)
633 : ($conn->{engine}->peer_settings_received
634 0 ▶ && $conn->{engine}->peer_extended_connect_enabled);
Branch: 1 branch
BranchTrueFalseTotal
$version eq 'h2' ? : 0 0 0
Condition0%0/6
$conn->{"h2_settings_seen"} and $conn->{"engine"}->peer_setting("enable_connect_protocol") == 1
!ll&&!rl&&r
000
$conn->{"engine"}->peer_settings_received and $conn->{"engine"}->peer_extended_connect_enabled
!ll&&!rl&&r
000
MC/DC0%0/2
$conn->{"h2_settings_seen"} and $conn->{"engine"}->peer_setting("enable_connect_protocol") == 1
$conn->{"h2_settings_seen"} $conn->{"engine"}->peer_setting("enable_connect_protocol") == 1
MC/DC0%0/2
$conn->{"engine"}->peer_settings_received and $conn->{"engine"}->peer_extended_connect_enabled
$conn->{"engine"}->peer_settings_received $conn->{"engine"}->peer_extended_connect_enabled
Truth table0%0/3
A and B
A= $conn->{"h2_settings_seen"}B= $conn->{"engine"}->peer_setting("enable_connect_protocol") == 1
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $conn->{"engine"}->peer_settings_receivedB= $conn->{"engine"}->peer_extended_connect_enabled
ABresult
0X0
100
111
635 0 };
636 0 ▶ if (@existing && !grep { $ready->($_) } @existing) {
Branch: 1 branch
BranchTrueFalseTotal
if (@existing and not grep({&$ready($_);} @existing)) 0 0 0
Condition0%0/3
@existing and not grep({&$ready($_);} @existing)
!ll&&!rl&&r
000
MC/DC0%0/2
@existing and not grep({&$ready($_);} @existing)
@existing not grep({&$ready($_);} @existing)
Truth table0%0/3
A and not(B)
A= @existingB= not grep({&$ready($_);} @existing)
ABresult
0X0
100
111
637 last if grep {
638 0 ▶ $version eq 'h2' ? !$_->{h2_settings_seen}
Branch: 1 branch
BranchTrueFalseTotal
if grep {$version eq "h2" ? !$_->{"h2_settings_seen"} : !$_->{"engine"}->peer_settings_received;} @existing 0 0 0
639 : !$_->{engine}->peer_settings_received
640 0 ▶ } @existing;
Branch: 1 branch
BranchTrueFalseTotal
$version eq 'h2' ? : 0 0 0
641 0 shift @{ $pool->{pending} };
642 0 $self->{pending_count}--;
643 0 ▶ $self->_fail_pending(
Branch: 1 branch
BranchTrueFalseTotal
$version eq 'h2' ? : 0 0 0
644 $pool, $op, 'peer has not enabled HTTP/'
645 . ($version eq 'h2' ? '2' : '3')
646 . ' WebSocket Extended CONNECT',
647 );
648 0 next;
649 }
650 }
651 125 my ($conn) = grep { $self->_usable($_, $op->{version}, $op) }
652 201 @{ $pool->{connections} };
653 201 ▶ if ($conn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conn) 90 111 201
654 90 shift @{ $pool->{pending} };
655 90 $self->{pending_count}--;
656 90 ▶ last unless $self->_dispatch($pool, $conn, $op);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_dispatch($pool, $conn, $op) 4 86 90
657 86 next;
658 }
659 111 ▶ last if $pool->{connecting};
Branch: 1 branch
BranchTrueFalseTotal
if $pool->{"connecting"} 12 99 111
660 99 ▶ if (@{ $pool->{connections} } >= $self->{limit}{max_connections_per_origin}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$pool->{"connections"};} >= $self->{"limit"}{"max_connections_per_origin"}) 20 79 99
661 # Never strand a strict request behind an idle, unusable engine.
662 20 ▶ for (my $i = 0; $i < @{ $pool->{connections} }; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$pool->{"connections"};}) 20 17 37
663 20 my $idle = $pool->{connections}[$i];
664 20 ▶ next if $idle->{active};
Branch: 1 branch
BranchTrueFalseTotal
if $idle->{"active"} 13 7 20
665 my $unusable = !_compatible($op->{version}, $idle->{protocol})
666 7 ▶ || _closed($idle) || _retired($idle);
Condition83%5/6
!_compatible($op->{'version'}, $idle->{'protocol'}) || _closed($idle) || _retired($idle)
l!l&&r!l&&!r
214
not _compatible($op->{"version"}, $idle->{"protocol"}) or _closed($idle)
l!l&&r!l&&!r
205
MC/DC66%2/3
!_compatible($op->{'version'}, $idle->{'protocol'}) || _closed($idle) || _retired($idle)
not _compatible($op->{"version"}, $idle->{"protocol"}) _closed($idle) _retired($idle)
Truth table75%3/4
not(A) or B || C
A= not _compatible($op->{"version"}, $idle->{"protocol"})B= _closed($idle)C= _retired($idle)
ABCresult
1XX1
01X1
0011
0000
667 7 ▶ next unless $unusable;
Branch: 1 branch
BranchTrueFalseTotal
unless $unusable 4 3 7
668 3 splice @{ $pool->{connections} }, $i, 1;
669 3 $self->_release_connection($idle, 'evicted');
670 3 last;
671 }
672 }
673 99 ▶ last if @{ $pool->{connections} } >= $self->{limit}{max_connections_per_origin};
Branch: 1 branch
BranchTrueFalseTotal
if @{$pool->{"connections"};} >= $self->{"limit"}{"max_connections_per_origin"} 17 82 99
674 # A synchronous factory can produce a connection that immediately
675 # refuses streams. Never spin forever creating/replacing engines.
676 82 ▶ last unless $attempt_budget--;
Branch: 1 branch
BranchTrueFalseTotal
unless $attempt_budget-- 1 81 82
677 81 $self->_connect($pool, $op);
678 81 ▶ last if $pool->{connecting};
Branch: 1 branch
BranchTrueFalseTotal
if $pool->{"connecting"} 45 36 81
679 }
680 168 $self->_sync_idle($pool);
681 168 $self->_delete_empty_pool($pool);
682 }
683  
684 81 ▶sub _connect {
Subroutine _connect: called CC=13 SCAR=26.4
685 81 my ($self, $pool, $op) = @_;
686 81 my $version = $op->{version};
687 81 my $quic = $version eq 'h3';
688 81 my $alt = $op->{alt_svc};
689 81 ▶ my $factory = $self->{factory}{ $quic ? 'connect_quic' : 'connect_stream' };
Branch: 1 branch
BranchTrueFalseTotal
$quic ? : 16 65 81
690 81 my $attempt = { op => $op, cancelled => 0, completed => 0 };
691 81 $pool->{connecting} = 1;
692 81 $pool->{attempt} = $attempt;
693 81 $op->{state} = 'connecting';
694 81 my $called = 0;
695 79 ▶ my $ready = sub {
Subroutine __ANON__: called CC=8 SCAR=20.9
696 79 ▶ return if $called++;
Branch: 1 branch
BranchTrueFalseTotal
if $called++ 0 79 79
697 # A cancelled/timed-out factory must not attach its late transport.
698 79 ▶ return unless $pool->{attempt} && $pool->{attempt} == $attempt;
Branch: 1 branch
BranchTrueFalseTotal
unless $pool->{"attempt"} and $pool->{"attempt"} == $attempt 6 73 79
Condition100%3/3
$pool->{"attempt"} and $pool->{"attempt"} == $attempt
!ll&&!rl&&r
2473
MC/DC100%2/2
$pool->{"attempt"} and $pool->{"attempt"} == $attempt
$pool->{"attempt"} $pool->{"attempt"} == $attempt
Truth table100%3/3
A and B
A= $pool->{"attempt"}B= $pool->{"attempt"} == $attempt
ABresult
0X0
100
111
699 73 $attempt->{completed} = 1;
700 73 delete $pool->{attempt};
701 73 $pool->{connecting} = 0;
702 73 my %result = @_;
703 73 my $engine;
704 73 my $ok = eval { $engine = $self->_connected($pool, $op, $version, \%result); 1 };
705 73 ▶ if (!$ok) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $ok) { } 3 70 73
elsif (not $op->is_terminal || $op->{'transaction'}) { } 70 0 70
706 3 my $error = "$@";
707 3 ▶ if (!$self->_fallback_alternative($pool, $op, $error)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_fallback_alternative($pool, $op, $error)) 1 2 3
708 1 $self->_fail_pending($pool, $op, $error);
709 }
710 ▶ } elsif (!$op->is_terminal && !$op->{transaction}) {
Condition33%1/3
$op->is_terminal || $op->{'transaction'}
l!l&&r!l&&!r
0070
MC/DC0%0/2
$op->is_terminal || $op->{'transaction'}
$op->is_terminal $op->{'transaction'}
Truth table33%1/3
A || B
A= $op->is_terminalB= $op->{'transaction'}
ABresult
1X1
011
000
711 # Connection establishment is complete. Waiting for peer stream
712 # credit is queued work, not another connection in progress.
713 70 $op->{state} = 'queued';
714 }
715 73 $self->_pump($pool);
716 73 return $engine;
717 81 };
718 81 ▶ my @alpn = $version eq 'tcp'
Branch: 2 branches
BranchTrueFalseTotal
$version eq 'tcp' ? : 47 34 81
$version eq 'h3' ? : 16 18 34
719 ? $self->alpn_protocols : ($version eq 'h3' ? ('h3') : ($version));
720 81 my $cancel;
721 81 my $ok = eval {
722 81 ▶ if ($quic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quic) { } 16 65 81
723 16 my $info = $pool->{info};
724 16 ▶ if ($alt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alt) 5 11 16
725 # The HTTP origin is unchanged. Only the UDP target differs.
726 $info = { %$info,
727 alternative_host => $info->{host},
728 alternative_port => $alt->{port},
729 5 };
730 }
731 16 $cancel = $factory->($info, $ready);
732 } else {
733 65 $cancel = $factory->($pool->{info}, \@alpn, $ready);
734 }
735 81 1;
736 };
737 81 ▶ if (ref($cancel) eq 'CODE' && !$attempt->{completed}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cancel eq "CODE" and not $attempt->{"completed"}) 9 72 81
Condition66%2/3
ref $cancel eq "CODE" and not $attempt->{"completed"}
!ll&&!rl&&r
7209
MC/DC50%1/2
ref $cancel eq "CODE" and not $attempt->{"completed"}
ref $cancel eq "CODE" not $attempt->{"completed"}
Truth table66%2/3
A and not(B)
A= ref $cancel eq "CODE"B= not $attempt->{"completed"}
ABresult
0X0
100
111
738 9 ▶ if ($attempt->{cancelled}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attempt->{'cancelled'}) { } 0 9 9
739 0 ▶ eval { $cancel->(); 1 } or warn "connection cancellation failed: $@";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { &$cancel(); 1 } } or warn "connection cancellation failed: $@" 0 0 0
740 } else {
741 9 $attempt->{cancel} = $cancel;
742 }
743 }
744 81 ▶ $ready->(error => "$@") unless $ok || $called || $attempt->{cancelled};
Branch: 1 branch
BranchTrueFalseTotal
unless $ok or $called or $attempt->{"cancelled"} 0 81 81
Condition33%2/6
$ok or $called or $attempt->{"cancelled"}
l!l&&r!l&&!r
8100
$ok or $called
l!l&&r!l&&!r
8100
MC/DC0%0/3
$ok or $called or $attempt->{"cancelled"}
$ok $called $attempt->{"cancelled"}
Truth table25%1/4
A or B or C
A= $okB= $calledC= $attempt->{"cancelled"}
ABCresult
1XX1
01X1
0011
0000
745 }
746  
747 # A pending request may abandon its own factory without holding the origin
748 # hostage. The framework may return a cancellation callback from the factory.
749 14 ▶sub _abandon_connect {
Subroutine _abandon_connect: called CC=5 SCAR=16.2
750 14 my ($self, $pool, $op) = @_;
751 14 ▶ my $attempt = $pool->{attempt} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $attempt = $pool->{"attempt"} or return 7 7 14
752 7 ▶ return unless $attempt->{op} == $op;
Branch: 1 branch
BranchTrueFalseTotal
unless $attempt->{"op"} == $op 0 7 7
753 7 delete $pool->{attempt};
754 7 $pool->{connecting} = 0;
755 7 $attempt->{cancelled} = 1;
756 7 ▶ if (my $cancel = delete $attempt->{cancel}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cancel = delete $attempt->{"cancel"}) 5 2 7
757 5 ▶ eval { $cancel->(); 1 } or warn "connection cancellation failed: $@";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { &$cancel(); 1 } } or warn "connection cancellation failed: $@" 5 0 5
758 }
759 7 return;
760 }
761  
762 6 ▶sub _request_timeout {
Subroutine _request_timeout: called CC=3 SCAR=11.0
763 6 my ($self, $op, $seconds) = @_;
764 6 ▶ return if $op->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $op->is_terminal 2 4 6
765 4 my $error = "request timed out after $seconds seconds";
766 4 ▶ if (my $tx = $op->{transaction}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tx = $op->{"transaction"}) 1 3 4
767 # Engine cancellation preserves protocol-specific stream isolation.
768 # The operation separately reports expiration as a timeout error.
769 1 $op->{timeout_error} = $error;
770 1 $tx->cancel;
771 1 return;
772 }
773 3 $self->_fail_pending($op->{origin}, $op, $error);
774 3 $self->_schedule($op->{origin});
775 3 return;
776 }
777  
778 73 ▶sub _connected {
Subroutine _connected: called CC=32 SCAR=42.9
779 73 my ($self, $pool, $op, $version, $result) = @_;
780 73 ▶ die "$result->{error}" if defined($result->{error}) && length($result->{error});
Branch: 1 branch
BranchTrueFalseTotal
if defined $result->{"error"} and length $result->{"error"} 2 71 73
Condition66%2/3
defined $result->{"error"} and length $result->{"error"}
!ll&&!rl&&r
7102
MC/DC50%1/2
defined $result->{"error"} and length $result->{"error"}
defined $result->{"error"} length $result->{"error"}
Truth table66%2/3
A and B
A= defined $result->{"error"}B= length $result->{"error"}
ABresult
0X0
100
111
781 71 my ($protocol, $host, %arg);
782 71 ▶ if ($version eq 'h3') {
Branch: 1 branch
BranchTrueFalseTotal
if ($version eq 'h3') { } 14 57 71
783 14 $protocol = 'h3';
784 14 $host = $result->{connection};
785 14 ▶ die "connect_quic: expected a ready QUIC connection\n"
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($host) and $host->can("ready") and $host->can("closed") and $host->ready and not $host->closed 0 14 14
Condition33%4/12
builtin::blessed($host) and $host->can("ready") and $host->can("closed") and $host->ready and not $host->closed
!ll&&!rl&&r
0014
builtin::blessed($host) and $host->can("ready") and $host->can("closed") and $host->ready
!ll&&!rl&&r
0014
builtin::blessed($host) and $host->can("ready") and $host->can("closed")
!ll&&!rl&&r
0014
builtin::blessed($host) and $host->can("ready")
!ll&&!rl&&r
0014
MC/DC0%0/5
builtin::blessed($host) and $host->can("ready") and $host->can("closed") and $host->ready and not $host->closed
builtin::blessed($host) $host->can("ready") $host->can("closed") $host->ready not $host->closed
Truth table16%1/6
A and B and C and D and not(E)
A= builtin::blessed($host)B= $host->can("ready")C= $host->can("closed")D= $host->readyE= not $host->closed
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
786 unless blessed($host) && $host->can('ready') && $host->can('closed')
787 && $host->ready && !$host->closed;
788 die "connect_quic: alternative must authenticate the original HTTPS origin\n"
789 if $op->{alt_svc}
790 && !(defined($result->{verified_origin})
791 && !ref($result->{verified_origin})
792 14 ▶ && $result->{verified_origin} eq '1');
Branch: 1 branch
BranchTrueFalseTotal
if $op->{"alt_svc"} and not defined $result->{"verified_origin"} && !ref($result->{"verified_origin"}) && $result->{"verified_origin"} eq 1 1 13 14
Condition77%7/9
$op->{"alt_svc"} and not defined $result->{"verified_origin"} && !ref($result->{"verified_origin"}) && $result->{"verified_origin"} eq 1
!ll&&!rl&&r
1121
defined $result->{'verified_origin'} && !ref($result->{'verified_origin'}) && $result->{'verified_origin'} eq '1'
!ll&&!rl&&r
102
defined $result->{"verified_origin"} and not ref $result->{"verified_origin"}
!ll&&!rl&&r
102
MC/DC50%2/4
$op->{"alt_svc"} and not defined $result->{"verified_origin"} && !ref($result->{"verified_origin"}) && $result->{"verified_origin"} eq 1
$op->{"alt_svc"} defined $result->{"verified_origin"} not ref $result->{"verified_origin"} $result->{'verified_origin'} eq '1'
Truth table60%3/5
A and not(B and not(C) && D)
A= $op->{"alt_svc"}B= defined $result->{"verified_origin"}C= not ref $result->{"verified_origin"}D= $result->{'verified_origin'} eq '1'
ABCDresult
0XXX0
11110
10XX1
110X1
11101
793 13 %arg = (quic => $host);
794 } else {
795 $protocol = defined($result->{alpn}) && length($result->{alpn})
796 57 ▶ ? $result->{alpn} : 'http/1.1';
Branch: 1 branch
BranchTrueFalseTotal
defined $result->{'alpn'} && length $result->{'alpn'} ? : 40 17 57
Condition66%2/3
defined $result->{"alpn"} and length $result->{"alpn"}
!ll&&!rl&&r
17040
MC/DC50%1/2
defined $result->{"alpn"} and length $result->{"alpn"}
defined $result->{"alpn"} length $result->{"alpn"}
Truth table66%2/3
A and B
A= defined $result->{"alpn"}B= length $result->{"alpn"}
ABresult
0X0
100
111
797 die "connect_stream: negotiated unsupported or disabled protocol\n"
798 unless ($protocol eq 'h2' || $protocol eq 'http/1.1')
799 57 ▶ && $self->{policy}->enabled($protocol)
Branch: 1 branch
BranchTrueFalseTotal
unless $protocol eq "h2" || $protocol eq "http/1.1" and $self->{"policy"}->enabled($protocol) and _compatible($version, $protocol) 0 57 57
Condition44%4/9
$protocol eq "h2" || $protocol eq "http/1.1" and $self->{"policy"}->enabled($protocol) and _compatible($version, $protocol)
!ll&&!rl&&r
0057
$protocol eq "h2" || $protocol eq "http/1.1" and $self->{"policy"}->enabled($protocol)
!ll&&!rl&&r
0057
$protocol eq "h2" or $protocol eq "http/1.1"
l!l&&r!l&&!r
21360
MC/DC0%0/4
$protocol eq "h2" || $protocol eq "http/1.1" and $self->{"policy"}->enabled($protocol) and _compatible($version, $protocol)
$protocol eq "h2" $protocol eq "http/1.1" $self->{"policy"}->enabled($protocol) _compatible($version, $protocol)
Truth table28%2/7
A or B and C and D
A= $protocol eq "h2"B= $protocol eq "http/1.1"C= $self->{"policy"}->enabled($protocol)D= _compatible($version, $protocol)
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
800 && _compatible($version, $protocol);
801 57 $host = $result->{transport};
802 57 ▶ die "connect_stream: transport must implement unblock_send, unblock_finish and unblock_abort\n"
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($host) and $host->can("unblock_send") and $host->can("unblock_finish") and $host->can("unblock_abort") 0 57 57
Condition33%3/9
builtin::blessed($host) and $host->can("unblock_send") and $host->can("unblock_finish") and $host->can("unblock_abort")
!ll&&!rl&&r
0057
builtin::blessed($host) and $host->can("unblock_send") and $host->can("unblock_finish")
!ll&&!rl&&r
0057
builtin::blessed($host) and $host->can("unblock_send")
!ll&&!rl&&r
0057
MC/DC0%0/4
builtin::blessed($host) and $host->can("unblock_send") and $host->can("unblock_finish") and $host->can("unblock_abort")
builtin::blessed($host) $host->can("unblock_send") $host->can("unblock_finish") $host->can("unblock_abort")
Truth table20%1/5
A and B and C and D
A= builtin::blessed($host)B= $host->can("unblock_send")C= $host->can("unblock_finish")D= $host->can("unblock_abort")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
803 unless blessed($host)
804 && $host->can('unblock_send')
805 && $host->can('unblock_finish')
806 && $host->can('unblock_abort');
807 57 %arg = (transport => $host);
808 }
809 70 my $options = $self->{policy}->options($protocol);
810 # These advertise Server capabilities; Client constructors reject them.
811 70 ▶ delete $options->{enable_connect_protocol} if $protocol eq 'h2';
Branch: 1 branch
BranchTrueFalseTotal
if $protocol eq "h2" 21 49 70
812 70 ▶ delete $options->{enable_extended_connect} if $protocol eq 'h3';
Branch: 1 branch
BranchTrueFalseTotal
if $protocol eq "h3" 13 57 70
813 my $conn = {
814 host => $host, protocol => $protocol, active => 0,
815 credit_blocked => 0,
816 verified_origin =>
817 (defined($result->{verified_origin})
818 && !ref($result->{verified_origin})
819 70 ▶ && $result->{verified_origin} eq '1') ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
defined $result->{'verified_origin'} && !ref($result->{'verified_origin'}) && $result->{'verified_origin'} eq '1' ? : 8 62 70
Condition66%4/6
defined $result->{"verified_origin"} and not ref $result->{"verified_origin"} and $result->{"verified_origin"} eq 1
!ll&&!rl&&r
6208
defined $result->{"verified_origin"} and not ref $result->{"verified_origin"}
!ll&&!rl&&r
6208
MC/DC33%1/3
defined $result->{"verified_origin"} and not ref $result->{"verified_origin"} and $result->{"verified_origin"} eq 1
defined $result->{"verified_origin"} not ref $result->{"verified_origin"} $result->{"verified_origin"} eq 1
Truth table50%2/4
A and not(B) and C
A= defined $result->{"verified_origin"}B= not ref $result->{"verified_origin"}C= $result->{"verified_origin"} eq 1
ABCresult
0XX0
10X0
1100
1111
820 };
821 70 my $weak_self = $self;
822 70 my $weak_pool = $pool;
823 70 my $weak_conn = $conn;
824 70 weaken($weak_self);
825 70 weaken($weak_pool);
826 70 weaken($weak_conn);
827 70 ▶ if ($protocol eq 'h2') {
Branch: 2 branches
BranchTrueFalseTotal
if ($protocol eq 'h2') { } 21 49 70
elsif ($protocol eq 'h3') { } 13 36 49
828 # A peer may raise its advertised stream limit later.
829 1 ▶ $options->{on_settings} = sub {
Subroutine __ANON__: called CC=4 SCAR=17.1
830 1 ▶ return unless $weak_self && $weak_pool && $weak_conn;
Branch: 1 branch
BranchTrueFalseTotal
unless $weak_self and $weak_pool and $weak_conn 0 1 1
Condition33%2/6
$weak_self and $weak_pool and $weak_conn
!ll&&!rl&&r
001
$weak_self and $weak_pool
!ll&&!rl&&r
001
MC/DC0%0/3
$weak_self and $weak_pool and $weak_conn
$weak_self $weak_pool $weak_conn
Truth table25%1/4
A and B and C
A= $weak_selfB= $weak_poolC= $weak_conn
ABCresult
0XX0
10X0
1100
1111
831 1 $weak_conn->{h2_settings_seen} = 1;
832 1 $weak_self->_schedule($weak_pool);
833 21 };
834 } elsif ($protocol eq 'h3') {
835 # The H3 engine exclusively owns Net::QUIC's availability callback.
836 # A failed-to-open bidi stream causes this one-shot notification.
837 4 ▶ $options->{on_request_available} = sub {
Subroutine __ANON__: called CC=4 SCAR=17.1
838 4 ▶ return unless $weak_self && $weak_pool && $weak_conn;
Branch: 1 branch
BranchTrueFalseTotal
unless $weak_self and $weak_pool and $weak_conn 0 4 4
Condition33%2/6
$weak_self and $weak_pool and $weak_conn
!ll&&!rl&&r
004
$weak_self and $weak_pool
!ll&&!rl&&r
004
MC/DC0%0/3
$weak_self and $weak_pool and $weak_conn
$weak_self $weak_pool $weak_conn
Truth table25%1/4
A and B and C
A= $weak_selfB= $weak_poolC= $weak_conn
ABCresult
0XX0
10X0
1100
1111
839 4 $weak_conn->{credit_blocked} = 0;
840 4 $weak_self->_schedule($weak_pool);
841 13 };
842 13 ▶ if ($self->{policy}->websocket_enabled('h3')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"policy"}->websocket_enabled("h3")) 0 13 13
843 # This hook fires after the CURRENT H3 peer SETTINGS frame,
844 # including when it contains no extension settings. Never
845 # submit CONNECT inline from the native receive callback.
846 0 ▶ $options->{on_extension_settings} = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
847 0 ▶ return unless $weak_self && $weak_pool && $weak_conn;
Branch: 1 branch
BranchTrueFalseTotal
unless $weak_self and $weak_pool and $weak_conn 0 0 0
Condition0%0/6
$weak_self and $weak_pool and $weak_conn
!ll&&!rl&&r
000
$weak_self and $weak_pool
!ll&&!rl&&r
000
MC/DC0%0/3
$weak_self and $weak_pool and $weak_conn
$weak_self $weak_pool $weak_conn
Truth table0%0/4
A and B and C
A= $weak_selfB= $weak_poolC= $weak_conn
ABCresult
0XX0
10X0
1100
1111
848 0 $weak_self->_schedule($weak_pool);
849 0 };
850 }
851 }
852 70 my $engine = Unblock::HTTP::_EngineFactory->create(
853 'Client', $protocol, %$options, %arg,
854 );
855 70 ▶ $engine->start if $protocol eq 'h3';
Branch: 1 branch
BranchTrueFalseTotal
if $protocol eq "h3" 13 57 70
856 70 $conn->{engine} = $engine;
857 70 push @{ $pool->{connections} }, $conn;
858 70 return $engine;
859 }
860  
861 # Alternative connection failure before dispatch is safe to recover from:
862 # the engine never saw this request. Once dispatched, no retry is automatic.
863 3 ▶sub _fallback_alternative {
Subroutine _fallback_alternative: called CC=9 SCAR=23.7
864 3 my ($self, $pool, $op, $error) = @_;
865 return 0 unless $op->{alt_svc} && !$op->{transaction}
866 && !$op->is_terminal
867 3 ▶ && ($self->{policy}->enabled('http/1.1') || $self->{policy}->enabled('h2'));
Branch: 1 branch
BranchTrueFalseTotal
unless $op->{"alt_svc"} and not $op->{"transaction"} and not $op->is_terminal and $self->{"policy"}->enabled("http/1.1") || $self->{"policy"}->enabled("h2") 1 2 3
Condition58%7/12
$op->{"alt_svc"} and not $op->{"transaction"} and not $op->is_terminal and $self->{"policy"}->enabled("http/1.1") || $self->{"policy"}->enabled("h2")
!ll&&!rl&&r
102
$op->{"alt_svc"} and not $op->{"transaction"} and not $op->is_terminal
!ll&&!rl&&r
102
$op->{"alt_svc"} and not $op->{"transaction"}
!ll&&!rl&&r
102
$self->{"policy"}->enabled("http/1.1") or $self->{"policy"}->enabled("h2")
l!l&&r!l&&!r
200
MC/DC20%1/5
$op->{"alt_svc"} and not $op->{"transaction"} and not $op->is_terminal and $self->{"policy"}->enabled("http/1.1") || $self->{"policy"}->enabled("h2")
$op->{"alt_svc"} not $op->{"transaction"} not $op->is_terminal $self->{"policy"}->enabled("http/1.1") $self->{"policy"}->enabled("h2")
Truth table33%2/6
A and not(B) and not(C) and D or E
A= $op->{"alt_svc"}B= not $op->{"transaction"}C= not $op->is_terminalD= $self->{"policy"}->enabled("http/1.1")E= $self->{"policy"}->enabled("h2")
ABCDEresult
0XXXX0
10XXX0
110XX0
111000
1111X1
111011
868 2 $self->{alt_svc}->invalidate($op->{origin}{info}{key});
869 2 for my $pending (@{ $pool->{pending} }) {
870 2 ▶ next unless $pending->{alt_svc} && !$pending->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $pending->{"alt_svc"} and not $pending->is_terminal 0 2 2
Condition33%1/3
$pending->{"alt_svc"} and not $pending->is_terminal
!ll&&!rl&&r
002
MC/DC0%0/2
$pending->{"alt_svc"} and not $pending->is_terminal
$pending->{"alt_svc"} not $pending->is_terminal
Truth table33%1/3
A and not(B)
A= $pending->{"alt_svc"}B= not $pending->is_terminal
ABresult
0X0
100
111
871 2 delete $pending->{alt_svc};
872 2 $pending->{version} = 'tcp';
873 2 $pending->{state} = 'queued';
874 }
875 2 return 1;
876 }
877  
878 13 ▶sub _learn_alt_svc {
Subroutine _learn_alt_svc: called CC=5 SCAR=16.5
879 13 my ($self, $pool, $conn, $response) = @_;
880 13 ▶ return if $conn->{stale};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"stale"} 0 13 13
881 return unless $conn->{verified_origin}
882 && $pool->{info}{scheme} eq 'https'
883 13 ▶ && $self->{policy}->enabled('h3');
Branch: 1 branch
BranchTrueFalseTotal
unless $conn->{"verified_origin"} and $pool->{"info"}{"scheme"} eq "https" and $self->{"policy"}->enabled("h3") 3 10 13
Condition66%4/6
$conn->{"verified_origin"} and $pool->{"info"}{"scheme"} eq "https" and $self->{"policy"}->enabled("h3")
!ll&&!rl&&r
3010
$conn->{"verified_origin"} and $pool->{"info"}{"scheme"} eq "https"
!ll&&!rl&&r
3010
MC/DC33%1/3
$conn->{"verified_origin"} and $pool->{"info"}{"scheme"} eq "https" and $self->{"policy"}->enabled("h3")
$conn->{"verified_origin"} $pool->{"info"}{"scheme"} eq "https" $self->{"policy"}->enabled("h3")
Truth table50%2/4
A and B and C
A= $conn->{"verified_origin"}B= $pool->{"info"}{"scheme"} eq "https"C= $self->{"policy"}->enabled("h3")
ABCresult
0XX0
10X0
1100
1111
884 10 $self->{alt_svc}->observe($pool->{info}{key}, $response);
885 10 return;
886 }
887  
888 495 ▶sub _dispatch {
Subroutine _dispatch: called CC=36 SCAR=53.5
889 495 my ($self, $pool, $conn, $op) = @_;
890 495 ▶ $self->_cancel_idle($conn) if $conn->{idle_cancel};
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"idle_cancel"} 0 495 495
891 495 $conn->{active}++;
892 495 $op->{state} = 'active';
893 # The Client owns in-flight operations even if the caller discards its
894 # handle. Transaction callbacks must not own the operation or pool:
895 # once terminal, that would retain the Transaction through a cycle.
896 495 my $op_id = refaddr($op);
897 495 $self->{active_operations}{$op_id} = $op;
898 495 my ($weak_self, $weak_pool, $weak_conn, $weak_op) =
899 ($self, $pool, $conn, $op);
900 495 weaken($weak_self);
901 495 weaken($weak_pool);
902 495 weaken($weak_conn);
903 495 weaken($weak_op);
904 495 my $callbacks = $op->{callbacks};
905 495 my $ws_spec = $op->{websocket_connect};
906 495 my %engine_callback;
907 495 ▶ $engine_callback{on_data} = $callbacks->{on_data} if $callbacks->{on_data};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_data"} 2 493 495
908 $engine_callback{on_informational} = $callbacks->{on_informational}
909 495 ▶ if $callbacks->{on_informational};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_informational"} 0 495 495
910 $engine_callback{on_drain} = $callbacks->{on_drain}
911 495 ▶ if $callbacks->{on_drain};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_drain"} 0 495 495
912  
913 # Alt-Svc discovery only affects later TCP-first requests. A Client
914 # configured for H3 alone can never consult the alternative cache;
915 # avoid allocating and running an unused per-response observer there.
916 495 ▶ if ($pool->{info}{scheme} eq 'https'
Branch: 2 branches
BranchTrueFalseTotal
if ($pool->{'info'}{'scheme'} eq 'https' and $self->{'policy'}->enabled('h3') and $self->{'policy'}->enabled('h2') || $self->{'policy'}->enabled('http/1.1')) { } 16 479 495
elsif ($callbacks->{'on_response'} and $callbacks->{'on_data'}) { } 2 951 953
Condition100%9/9
$pool->{"info"}{"scheme"} eq "https" and $self->{"policy"}->enabled("h3") and $self->{"policy"}->enabled("h2") || $self->{"policy"}->enabled("http/1.1")
!ll&&!rl&&r
33214716
$pool->{"info"}{"scheme"} eq "https" and $self->{"policy"}->enabled("h3")
!ll&&!rl&&r
36296163
$self->{"policy"}->enabled("h2") or $self->{"policy"}->enabled("http/1.1")
l!l&&r!l&&!r
142147
MC/DC100%4/4
$pool->{"info"}{"scheme"} eq "https" and $self->{"policy"}->enabled("h3") and $self->{"policy"}->enabled("h2") || $self->{"policy"}->enabled("http/1.1")
$pool->{"info"}{"scheme"} eq "https" $self->{"policy"}->enabled("h3") $self->{"policy"}->enabled("h2") $self->{"policy"}->enabled("http/1.1")
Truth table100%5/5
A and B and C or D
A= $pool->{"info"}{"scheme"} eq "https"B= $self->{"policy"}->enabled("h3")C= $self->{"policy"}->enabled("h2")D= $self->{"policy"}->enabled("http/1.1")
ABCDresult
0XXX0
10XX0
11000
111X1
11011
917 && $self->{policy}->enabled('h3')
918 && ($self->{policy}->enabled('h2')
919 || $self->{policy}->enabled('http/1.1'))) {
920 # Once per response headers, not on the body hot path.
921 13 ▶ $engine_callback{on_response} = sub {
Subroutine __ANON__: called CC=6 SCAR=23.5
922 13 my ($tx, $response) = @_;
923 13 ▶ $weak_self->_learn_alt_svc($weak_pool, $weak_conn, $response)
Branch: 1 branch
BranchTrueFalseTotal
if $weak_self and $weak_pool and $weak_conn 13 0 13
Condition33%2/6
$weak_self and $weak_pool and $weak_conn
!ll&&!rl&&r
0013
$weak_self and $weak_pool
!ll&&!rl&&r
0013
MC/DC0%0/3
$weak_self and $weak_pool and $weak_conn
$weak_self $weak_pool $weak_conn
Truth table25%1/4
A and B and C
A= $weak_selfB= $weak_poolC= $weak_conn
ABCresult
0XX0
10X0
1100
1111
924 if $weak_self && $weak_pool && $weak_conn;
925 $callbacks->{on_response}->($tx, $response)
926 13 ▶ if $callbacks->{on_data} && $callbacks->{on_response};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_data"} and $callbacks->{"on_response"} 0 13 13
Condition33%1/3
$callbacks->{"on_data"} and $callbacks->{"on_response"}
!ll&&!rl&&r
1300
MC/DC0%0/2
$callbacks->{"on_data"} and $callbacks->{"on_response"}
$callbacks->{"on_data"} $callbacks->{"on_response"}
Truth table33%1/3
A and B
A= $callbacks->{"on_data"}B= $callbacks->{"on_response"}
ABresult
0X0
100
111
927 16 };
928 ▶ } elsif ($callbacks->{on_response} && $callbacks->{on_data}) {
Condition100%3/3
$callbacks->{"on_response"} and $callbacks->{"on_data"}
!ll&&!rl&&r
47432
MC/DC100%2/2
$callbacks->{"on_response"} and $callbacks->{"on_data"}
$callbacks->{"on_response"} $callbacks->{"on_data"}
Truth table100%3/3
A and B
A= $callbacks->{"on_response"}B= $callbacks->{"on_data"}
ABresult
0X0
100
111
929 2 $engine_callback{on_response} = $callbacks->{on_response};
930 }
931 495 ▶ if ($callbacks->{on_response} || ($callbacks->{on_end} && $callbacks->{on_data})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callbacks->{"on_response"} or $callbacks->{"on_end"} and $callbacks->{"on_data"}) 6 489 495
Condition50%3/6
$callbacks->{"on_response"} or $callbacks->{"on_end"} and $callbacks->{"on_data"}
l!l&&r!l&&!r
60489
$callbacks->{"on_end"} and $callbacks->{"on_data"}
!ll&&!rl&&r
48900
MC/DC33%1/3
$callbacks->{"on_response"} or $callbacks->{"on_end"} and $callbacks->{"on_data"}
$callbacks->{"on_response"} $callbacks->{"on_end"} $callbacks->{"on_data"}
Truth table50%2/4
A or B and C
A= $callbacks->{"on_response"}B= $callbacks->{"on_end"}C= $callbacks->{"on_data"}
ABCresult
1XX1
0111
00X0
0100
932 6 ▶ $engine_callback{on_complete} = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
933 6 my ($tx) = @_;
934 6 ▶ if ($callbacks->{on_data}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callbacks->{'on_data'}) { } 2 4 6
935 2 ▶ $callbacks->{on_end}->($tx) if $callbacks->{on_end};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_end"} 1 1 2
936 } else {
937 $callbacks->{on_response}->($tx, $tx->response)
938 4 ▶ if $callbacks->{on_response};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_response"} 4 0 4
939 }
940 6 };
941 }
942 495 ▶ if ($callbacks->{on_error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callbacks->{"on_error"}) 8 487 495
943 8 $engine_callback{on_error} = $callbacks->{on_error};
944 }
945 495 ▶ if ($ws_spec && ($conn->{protocol} eq 'h2'
Branch: 2 branches
BranchTrueFalseTotal
if ($ws_spec and $conn->{'protocol'} eq 'h2' || $conn->{'protocol'} eq 'h3') { } 0 495 495
elsif ($ws_spec) { } 0 495 495
Condition16%1/6
$ws_spec and $conn->{"protocol"} eq "h2" || $conn->{"protocol"} eq "h3"
!ll&&!rl&&r
49500
$conn->{"protocol"} eq "h2" or $conn->{"protocol"} eq "h3"
l!l&&r!l&&!r
000
MC/DC0%0/3
$ws_spec and $conn->{"protocol"} eq "h2" || $conn->{"protocol"} eq "h3"
$ws_spec $conn->{"protocol"} eq "h2" $conn->{"protocol"} eq "h3"
Truth table25%1/4
A and B or C
A= $ws_specB= $conn->{"protocol"} eq "h2"C= $conn->{"protocol"} eq "h3"
ABCresult
0XX0
1000
11X1
1011
946 || $conn->{protocol} eq 'h3')) {
947 # Unlike HTTP1, a WebSocket occupies one multiplexed H2/H3 stream.
948 # Its normal transaction lifetime remains active until END_STREAM.
949 # No host socket takeover or HTTP pool detachment is performed.
950 0 ▶ $engine_callback{on_response} = sub {
Subroutine __ANON__: not called CC=10 SCAR=47.0
951 0 my ($tx, $response) = @_;
952 # A rejected H3 handshake must not throw out of Net::QUIC's
953 # receive dispatch. Defer a reset of this stream only.
954 0 my $valid = eval {
955 0 $ws_spec->{handshake}->validate_client_response($response);
956 0 1;
957 };
958 0 ▶ if (!$valid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($valid) 0 0 0
959 0 ▶ die $@ if $conn->{protocol} ne 'h3';
Branch: 1 branch
BranchTrueFalseTotal
if $conn->{"protocol"} ne "h3" 0 0 0
960 0 ▶ my $active_op = $weak_op or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_op = $weak_op or return 0 0 0
961 $active_op->{websocket_handshake_error} =
962 0 ▶ "$@" || 'HTTP3 WebSocket handshake failed';
Condition0%0/2
"$@" || 'HTTP3 WebSocket handshake failed'
l!l
00
MC/DC0%0/1
"$@" || 'HTTP3 WebSocket handshake failed'
"$@"
Truth table0%0/2
A
A= "$@"
Aresult
11
00
963 0 ▶ my $active_self = $weak_self or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_self = $weak_self or return 0 0 0
964 0 ▶ $active_self->{factory}{defer}->(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
965 0 ▶ $tx->cancel unless $tx->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $tx->is_terminal 0 0 0
966 0 });
967 0 return;
968 }
969 0 require Unblock::HTTP::_WebSocketH2Body;
970 0 require Unblock::WebSocket::Client;
971 0 ▶ my $active_op = $weak_op or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_op = $weak_op or return 0 0 0
972 0 ▶ my $active_self = $weak_self or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_self = $weak_self or return 0 0 0
973 my $bridge = Unblock::HTTP::_WebSocketH2Body->new(
974 transaction => $tx, defer => $active_self->{factory}{defer},
975 0 );
976 my $ws = Unblock::WebSocket::Client->new(
977 0 %{ $ws_spec->{handshake}->connection_options },
978 0 ▶ %{ $ws_spec->{options} },
Branch: 1 branch
BranchTrueFalseTotal
$callbacks->{'on_error'} ? : 0 0 0
979 transport => $bridge,
980 ($callbacks->{on_error}
981 0 ? (on_error => $callbacks->{on_error}) : ()),
982 );
983 0 $bridge->websocket($ws);
984 0 $active_op->{websocket} = $ws;
985 0 $active_op->{websocket_bridge} = $bridge;
986 $ws_spec->{on_open}->($ws, $tx)
987 0 ▶ if $ws_spec->{on_open};
Branch: 1 branch
BranchTrueFalseTotal
if $ws_spec->{"on_open"} 0 0 0
988 0 };
989 0 ▶ $engine_callback{on_data} = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
990 0 ▶ my $active_op = $weak_op or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_op = $weak_op or return 0 0 0
991 # An H3 rejection may carry an ordinary HTTP error body.
992 # Discard it after validation has failed; it is not framed
993 # WebSocket DATA and must not unwind the QUIC receive call.
994 0 ▶ return if $active_op->{websocket_handshake_error};
Branch: 1 branch
BranchTrueFalseTotal
if $active_op->{"websocket_handshake_error"} 0 0 0
995 my $ws = $active_op->{websocket}
996 0 ▶ or die 'multiplexed WebSocket DATA arrived before validated response';
Branch: 1 branch
BranchTrueFalseTotal
my $ws = $active_op->{"websocket"} or die "multiplexed WebSocket DATA arrived before validated response" 0 0 0
997 0 $ws->input($_[1]);
998 0 };
999 0 ▶ $engine_callback{on_drain} = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1000 0 ▶ my $active_op = $weak_op or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_op = $weak_op or return 0 0 0
1001 0 ▶ my $bridge = $active_op->{websocket_bridge} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $bridge = $active_op->{"websocket_bridge"} or return 0 0 0
1002 0 $bridge->resume;
1003 0 };
1004 0 ▶ $engine_callback{on_complete} = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
1005 0 ▶ my $active_op = $weak_op or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_op = $weak_op or return 0 0 0
1006 0 ▶ my $ws = $active_op->{websocket} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $ws = $active_op->{"websocket"} or return 0 0 0
1007 0 ▶ $ws->input_eof if !$ws->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if not $ws->is_closed 0 0 0
1008 0 };
1009 }
1010 elsif ($ws_spec) {
1011 # Validation must happen before HTTP1 yields its byte-stream.
1012 # Invalid 101 replies and ordinary HTTP rejection responses are
1013 # failed handshakes, not successful established WebSockets.
1014 0 ▶ $engine_callback{on_response} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1015 0 my ($tx, $response) = @_;
1016 0 $ws_spec->{handshake}->validate_client_response($response);
1017 0 };
1018 0 ▶ $engine_callback{on_switch} = sub {
Subroutine __ANON__: not called CC=11 SCAR=48.8
1019 0 my ($tx, $response) = @_;
1020 0 ▶ my $active_self = $weak_self or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_self = $weak_self or return 0 0 0
1021 0 ▶ my $active_pool = $weak_pool or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_pool = $weak_pool or return 0 0 0
1022 0 ▶ my $active_conn = $weak_conn or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_conn = $weak_conn or return 0 0 0
1023 0 ▶ my $active_op = $weak_op or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_op = $weak_op or return 0 0 0
1024 local $active_pool->{callback_depth} =
1025 0 ▶ ($active_pool->{callback_depth} || 0) + 1;
Condition0%0/2
$active_pool->{'callback_depth'} || 0
l!l
00
MC/DC0%0/1
$active_pool->{'callback_depth'} || 0
$active_pool->{'callback_depth'}
Truth table0%0/2
A
A= $active_pool->{'callback_depth'}
Aresult
11
00
1026 0 my $host = $active_conn->{host};
1027 0 ▶ croak 'connect_websocket(): transport must implement unblock_upgrade()'
Branch: 1 branch
BranchTrueFalseTotal
unless $host->can("unblock_upgrade") 0 0 0
1028 unless $host->can('unblock_upgrade');
1029  
1030 0 require Unblock::WebSocket::Client;
1031 my $ws = Unblock::WebSocket::Client->new(
1032 0 %{ $ws_spec->{handshake}->connection_options },
1033 0 ▶ %{ $ws_spec->{options} },
Branch: 1 branch
BranchTrueFalseTotal
$callbacks->{'on_error'} ? : 0 0 0
1034 transport => $host,
1035 ($callbacks->{on_error}
1036 0 ? (on_error => $callbacks->{on_error}) : ()),
1037 );
1038 # The framework changes the input owner synchronously, while
1039 # leaving its ordered write queue and the socket unchanged.
1040 0 $host->unblock_upgrade($ws);
1041 0 $active_op->{websocket} = $ws;
1042 # Keep the detached pool bookkeeping alive only until HTTP1
1043 # invokes on_finish immediately after this on_switch callback.
1044 # The ordinary callback closure intentionally holds weak refs.
1045 0 $active_op->{upgrade_retirement} = [$active_pool, $active_conn];
1046 0 $active_conn->{released} = 1; # transferred, never close by pool
1047 $active_self->_cancel_idle($active_conn)
1048 0 ▶ if $active_conn->{idle_cancel};
Branch: 1 branch
BranchTrueFalseTotal
if $active_conn->{"idle_cancel"} 0 0 0
1049 $active_pool->{connections} = [
1050 0 grep { $_ != $active_conn } @{ $active_pool->{connections} }
1051 ];
1052 $ws_spec->{on_open}->($ws, $tx)
1053 0 ▶ if $ws_spec->{on_open};
Branch: 1 branch
BranchTrueFalseTotal
if $ws_spec->{"on_open"} 0 0 0
1054 0 my $tail = $active_conn->{engine}->take_remainder;
1055 0 ▶ $ws->input($tail) if length $tail;
Branch: 1 branch
BranchTrueFalseTotal
if length $tail 0 0 0
1056 0 };
1057 }
1058 490 ▶ $engine_callback{on_finish} = sub {
Subroutine __ANON__: called CC=34 SCAR=41.6
1059 490 my ($tx) = @_;
1060 490 ▶ my $active_op = $weak_op or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_op = $weak_op or return 490 0 490
1061 490 ▶ return if $active_op->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $active_op->is_terminal 0 490 490
1062 490 my $upgrade_retirement = delete $active_op->{upgrade_retirement};
1063 490 ▶ my ($active_self, $active_pool, $active_conn) =
Condition16%2/12
$weak_pool || $upgrade_retirement && $upgrade_retirement->[0]
l!l&&r!l&&!r
49000
$upgrade_retirement and $upgrade_retirement->[0]
!ll&&!rl&&r
000
$weak_conn || $upgrade_retirement && $upgrade_retirement->[1]
l!l&&r!l&&!r
49000
$upgrade_retirement and $upgrade_retirement->[1]
!ll&&!rl&&r
000
MC/DC0%0/3
$weak_pool || $upgrade_retirement && $upgrade_retirement->[0]
$weak_pool $upgrade_retirement $upgrade_retirement->[0]
MC/DC0%0/3
$weak_conn || $upgrade_retirement && $upgrade_retirement->[1]
$weak_conn $upgrade_retirement $upgrade_retirement->[1]
Truth table25%1/4
A || B and C
A= $weak_poolB= $upgrade_retirementC= $upgrade_retirement->[0]
ABCresult
1XX1
0111
00X0
0100
Truth table25%1/4
A || B and C
A= $weak_connB= $upgrade_retirementC= $upgrade_retirement->[1]
ABCresult
1XX1
0111
00X0
0100
1064 ($weak_self,
1065 $weak_pool || ($upgrade_retirement && $upgrade_retirement->[0]),
1066 $weak_conn || ($upgrade_retirement && $upgrade_retirement->[1]));
1067 490 ▶ return unless $active_self && $active_pool && $active_conn;
Branch: 1 branch
BranchTrueFalseTotal
unless $active_self and $active_pool and $active_conn 0 490 490
Condition33%2/6
$active_self and $active_pool and $active_conn
!ll&&!rl&&r
00490
$active_self and $active_pool
!ll&&!rl&&r
00490
MC/DC0%0/3
$active_self and $active_pool and $active_conn
$active_self $active_pool $active_conn
Truth table25%1/4
A and B and C
A= $active_selfB= $active_poolC= $active_conn
ABCresult
0XX0
10X0
1100
1111
1068 local $active_pool->{callback_depth} =
1069 490 ▶ ($active_pool->{callback_depth} || 0) + 1;
Condition50%1/2
$active_pool->{'callback_depth'} || 0
l!l
0490
MC/DC0%0/1
$active_pool->{'callback_depth'} || 0
$active_pool->{'callback_depth'}
Truth table50%1/2
A
A= $active_pool->{'callback_depth'}
Aresult
11
00
1070 490 ▶ $active_op->{transaction} ||= $tx;
Condition33%1/3
$active_op->{"transaction"} ||= $tx
l!l&&r!l&&!r
49000
MC/DC0%0/2
$active_op->{"transaction"} ||= $tx
$active_op->{"transaction"} $tx
Truth table33%1/3
A ||= B
A= $active_op->{"transaction"}B= $tx
ABresult
1X1
011
000
1071 490 ▶ if (my $bridge = delete $active_op->{websocket_bridge}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $bridge = delete $active_op->{"websocket_bridge"}) 0 490 490
1072 0 $bridge->detach;
1073 }
1074 $active_op->{state} = ($active_op->{timeout_error}
1075 490 ▶ || $active_op->{websocket_handshake_error}) ? 'error'
Branch: 3 branches
BranchTrueFalseTotal
$active_op->{'timeout_error'} || $active_op->{'websocket_handshake_error'} ? : 1 489 490
$tx->is_cancelled ? : 0 489 489
$tx->is_error ? : 1 488 489
Condition66%2/3
$active_op->{"timeout_error"} or $active_op->{"websocket_handshake_error"}
l!l&&r!l&&!r
10489
MC/DC50%1/2
$active_op->{"timeout_error"} or $active_op->{"websocket_handshake_error"}
$active_op->{"timeout_error"} $active_op->{"websocket_handshake_error"}
Truth table66%2/3
A or B
A= $active_op->{"timeout_error"}B= $active_op->{"websocket_handshake_error"}
ABresult
1X1
011
000
1076 : $tx->is_cancelled ? 'cancelled'
1077 : $tx->is_error ? 'error' : 'complete';
1078 $active_op->{error} = $active_op->{timeout_error}
1079 || $active_op->{websocket_handshake_error}
1080 490 ▶ || ($tx->is_error ? $tx->error : undef);
Branch: 1 branch
BranchTrueFalseTotal
$tx->is_error ? : 1 488 489
Condition83%5/6
$active_op->{'timeout_error'} || $active_op->{'websocket_handshake_error'} || ($tx->is_error ? $tx->error : undef)
l!l&&r!l&&!r
11488
$active_op->{"timeout_error"} or $active_op->{"websocket_handshake_error"}
l!l&&r!l&&!r
10489
MC/DC66%2/3
$active_op->{'timeout_error'} || $active_op->{'websocket_handshake_error'} || ($tx->is_error ? $tx->error : undef)
$active_op->{"timeout_error"} $active_op->{"websocket_handshake_error"} ($tx->is_error ? $tx->error : undef)
Truth table75%3/4
A or B || C
A= $active_op->{"timeout_error"}B= $active_op->{"websocket_handshake_error"}C= ($tx->is_error ? $tx->error : undef)
ABCresult
1XX1
01X1
0011
0000
1081 490 $active_op->_cancel_timer;
1082 490 $active_conn->{active}--;
1083 490 ▶ if (($active_op->{timeout_error}
Branch: 1 branch
BranchTrueFalseTotal
if ($active_op->{"timeout_error"} || $active_op->{"websocket_handshake_error"} and $callbacks->{"on_error"}) 1 489 490
Condition66%4/6
$active_op->{"timeout_error"} || $active_op->{"websocket_handshake_error"} and $callbacks->{"on_error"}
!ll&&!rl&&r
48901
$active_op->{"timeout_error"} or $active_op->{"websocket_handshake_error"}
l!l&&r!l&&!r
10489
MC/DC33%1/3
$active_op->{"timeout_error"} || $active_op->{"websocket_handshake_error"} and $callbacks->{"on_error"}
$active_op->{"timeout_error"} $active_op->{"websocket_handshake_error"} $callbacks->{"on_error"}
Truth table40%2/5
A or B and C
A= $active_op->{"timeout_error"}B= $active_op->{"websocket_handshake_error"}C= $callbacks->{"on_error"}
ABCresult
00X0
1X00
0100
1X11
0111
1084 || $active_op->{websocket_handshake_error})
1085 && $callbacks->{on_error}) {
1086 1 ▶ eval { $callbacks->{on_error}->($tx, $active_op->{error}); 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $callbacks->{"on_error"}->($tx, $active_op->{"error"}); 1 } } or warn $@ 1 0 1
1087 or warn $@;
1088 }
1089 490 my $ok = eval {
1090 490 ▶ $callbacks->{on_finish}->($tx) if $callbacks->{on_finish};
Branch: 1 branch
BranchTrueFalseTotal
if $callbacks->{"on_finish"} 12 478 490
1091 490 1;
1092 };
1093 490 ▶ warn $@ unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 490 490
1094 # Keep the strong active ownership through application callbacks.
1095 # A caller-retained handle still owns the real engine Transaction.
1096 490 delete $active_self->{active_operations}{$op_id};
1097 # A quiet, reusable connection needs no additional loop turn.
1098 # Preserve deferred H1 reentrancy, pending queues, idle timers
1099 # and immediate cleanup of closed/draining/stale connections.
1100 490 ▶ if ($active_self->{shutdown}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($active_self->{"shutdown"}) 3 487 490
1101 $active_self->_drop_connection(
1102 $active_pool, $active_conn, 'shutdown',
1103 3 ▶ ) if !$active_conn->{active} && !$active_conn->{released};
Branch: 1 branch
BranchTrueFalseTotal
unless $active_conn->{"active"} or $active_conn->{"released"} 2 1 3
Condition66%2/3
$active_conn->{"active"} or $active_conn->{"released"}
l!l&&r!l&&!r
102
MC/DC50%1/2
$active_conn->{"active"} or $active_conn->{"released"}
$active_conn->{"active"} $active_conn->{"released"}
Truth table66%2/3
A or B
A= $active_conn->{"active"}B= $active_conn->{"released"}
ABresult
1X1
011
000
1104 3 return;
1105 }
1106 $active_self->_schedule($active_pool)
1107 487 if @{ $active_pool->{pending} }
1108 || defined($active_self->{idle_timeout})
1109 || $active_conn->{stale}
1110 487 ▶ || _closed($active_conn) || _retired($active_conn);
Branch: 1 branch
BranchTrueFalseTotal
if @{$active_pool->{"pending"};} or defined $active_self->{"idle_timeout"} or $active_conn->{"stale"} or _closed($active_conn) or _retired($active_conn) 24 463 487
Condition75%9/12
@{$active_pool->{"pending"};} or defined $active_self->{"idle_timeout"} or $active_conn->{"stale"} or _closed($active_conn) or _retired($active_conn)
l!l&&r!l&&!r
240463
@{$active_pool->{"pending"};} or defined $active_self->{"idle_timeout"} or $active_conn->{"stale"} or _closed($active_conn)
l!l&&r!l&&!r
240463
@{$active_pool->{"pending"};} or defined $active_self->{"idle_timeout"} or $active_conn->{"stale"}
l!l&&r!l&&!r
240463
@{$active_pool->{"pending"};} or defined $active_self->{"idle_timeout"}
l!l&&r!l&&!r
1410463
MC/DC40%2/5
@{$active_pool->{"pending"};} or defined $active_self->{"idle_timeout"} or $active_conn->{"stale"} or _closed($active_conn) or _retired($active_conn)
@{$active_pool->{"pending"};} defined $active_self->{"idle_timeout"} $active_conn->{"stale"} _closed($active_conn) _retired($active_conn)
Truth table50%3/6
A or B or C or D or E
A= @{$active_pool->{"pending"};}B= defined $active_self->{"idle_timeout"}C= $active_conn->{"stale"}D= _closed($active_conn)E= _retired($active_conn)
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1111 495 };
1112 495 my $no_credit = 0;
1113 495 my $ok = eval {
1114 die "connect_websocket(): requires HTTP1, HTTP2 or HTTP3 transport\n"
1115 if $ws_spec && $conn->{protocol} ne 'http/1.1'
1116 495 ▶ && $conn->{protocol} ne 'h2' && $conn->{protocol} ne 'h3';
Branch: 1 branch
BranchTrueFalseTotal
if $ws_spec and $conn->{"protocol"} ne "http/1.1" and $conn->{"protocol"} ne "h2" and $conn->{"protocol"} ne "h3" 0 495 495
Condition33%3/9
$ws_spec and $conn->{"protocol"} ne "http/1.1" and $conn->{"protocol"} ne "h2" and $conn->{"protocol"} ne "h3"
!ll&&!rl&&r
49500
$ws_spec and $conn->{"protocol"} ne "http/1.1" and $conn->{"protocol"} ne "h2"
!ll&&!rl&&r
49500
$ws_spec and $conn->{"protocol"} ne "http/1.1"
!ll&&!rl&&r
49500
MC/DC0%0/4
$ws_spec and $conn->{"protocol"} ne "http/1.1" and $conn->{"protocol"} ne "h2" and $conn->{"protocol"} ne "h3"
$ws_spec $conn->{"protocol"} ne "http/1.1" $conn->{"protocol"} ne "h2" $conn->{"protocol"} ne "h3"
Truth table20%1/5
A and B and C and D
A= $ws_specB= $conn->{"protocol"} ne "http/1.1"C= $conn->{"protocol"} ne "h2"D= $conn->{"protocol"} ne "h3"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1117 die "connect_websocket(): HTTP1 requires unblock_upgrade()\n"
1118 if $ws_spec && $conn->{protocol} eq 'http/1.1'
1119 495 ▶ && !$conn->{host}->can('unblock_upgrade');
Branch: 1 branch
BranchTrueFalseTotal
if $ws_spec and $conn->{"protocol"} eq "http/1.1" and not $conn->{"host"}->can("unblock_upgrade") 0 495 495
Condition33%2/6
$ws_spec and $conn->{"protocol"} eq "http/1.1" and not $conn->{"host"}->can("unblock_upgrade")
!ll&&!rl&&r
49500
$ws_spec and $conn->{"protocol"} eq "http/1.1"
!ll&&!rl&&r
49500
MC/DC0%0/3
$ws_spec and $conn->{"protocol"} eq "http/1.1" and not $conn->{"host"}->can("unblock_upgrade")
$ws_spec $conn->{"protocol"} eq "http/1.1" not $conn->{"host"}->can("unblock_upgrade")
Truth table25%1/4
A and B and not(C)
A= $ws_specB= $conn->{"protocol"} eq "http/1.1"C= not $conn->{"host"}->can("unblock_upgrade")
ABCresult
0XX0
10X0
1100
1111
1120 $op->{transaction} = $conn->{engine}->request(
1121 $op->{request},
1122 stream_body => $op->{stream_body},
1123 495 %engine_callback,
1124 );
1125 # HTTP/3 returns undef before opening a QUIC bidi stream.
1126 # Defer the SAME unsent operation until the engine signals credit.
1127 $no_credit = 1 if !defined($op->{transaction})
1128 495 ▶ && !$op->is_terminal && $conn->{protocol} eq 'h3';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $op->{"transaction"} || $op->is_terminal and $conn->{"protocol"} eq "h3" 5 490 495
Condition66%4/6
not defined $op->{"transaction"} || $op->is_terminal and $conn->{"protocol"} eq "h3"
!ll&&!rl&&r
49005
defined $op->{'transaction'} || $op->is_terminal
l!l&&r!l&&!r
49005
MC/DC33%1/3
not defined $op->{"transaction"} || $op->is_terminal and $conn->{"protocol"} eq "h3"
defined $op->{'transaction'} $op->is_terminal $conn->{"protocol"} eq "h3"
Truth table50%2/4
not(A || B) and C
A= defined $op->{'transaction'}B= $op->is_terminalC= $conn->{"protocol"} eq "h3"
ABCresult
1XX0
01X0
0000
0011
1129 die "$conn->{protocol} request was not admitted by its engine\n"
1130 495 ▶ unless $no_credit || defined($op->{transaction}) || $op->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $no_credit or defined $op->{"transaction"} or $op->is_terminal 0 495 495
Condition50%3/6
$no_credit or defined $op->{"transaction"} or $op->is_terminal
l!l&&r!l&&!r
49500
$no_credit or defined $op->{"transaction"}
l!l&&r!l&&!r
54900
MC/DC0%0/3
$no_credit or defined $op->{"transaction"} or $op->is_terminal
$no_credit defined $op->{"transaction"} $op->is_terminal
Truth table50%2/4
A or B or C
A= $no_creditB= defined $op->{"transaction"}C= $op->is_terminal
ABCresult
1XX1
01X1
0011
0000
1131 495 1;
1132 };
1133 495 ▶ if ($ok && $no_credit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok and $no_credit) 5 490 495
Condition66%2/3
$ok and $no_credit
!ll&&!rl&&r
04905
MC/DC50%1/2
$ok and $no_credit
$ok $no_credit
Truth table66%2/3
A and B
A= $okB= $no_credit
ABresult
0X0
100
111
1134 5 delete $self->{active_operations}{$op_id};
1135 5 $conn->{active}--;
1136 5 $conn->{credit_blocked} = 1;
1137 5 $op->{state} = 'queued';
1138 5 unshift @{ $pool->{pending} }, $op;
1139 5 $self->{pending_count}++;
1140 5 return 0;
1141 }
1142 490 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 490 490
1143 0 delete $self->{active_operations}{$op_id};
1144 0 ▶ if (!$op->is_terminal) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($op->is_terminal) 0 0 0
1145 0 $conn->{active}--;
1146 0 $self->_fail_active($op, "$@");
1147 }
1148 0 $self->_schedule($pool);
1149 }
1150 490 return 1;
1151 }
1152  
1153 44 ▶sub _schedule {
Subroutine _schedule: called CC=4 SCAR=14.1
1154 44 my ($self, $pool) = @_;
1155 44 ▶ return if $self->{shutdown};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"shutdown"} 2 42 44
1156 42 ▶ return if $pool->{scheduled}++;
Branch: 1 branch
BranchTrueFalseTotal
if $pool->{"scheduled"}++ 4 38 42
1157 38 my $ok = eval {
1158 35 ▶ $self->{factory}{defer}->(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1159 35 $pool->{scheduled} = 0;
1160 35 $self->_pump($pool);
1161 38 });
1162 38 1;
1163 };
1164 38 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ok) 0 38 38
1165 0 $pool->{scheduled} = 0;
1166 0 warn "Client defer callback failed: $@";
1167 }
1168 }
1169  
1170 0 ▶sub _fail_active {
Subroutine _fail_active: not called CC=2 SCAR=17.9
1171 0 my ($self, $op, $error) = @_;
1172 0 ▶ return if $op->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $op->is_terminal 0 0 0
1173 0 $op->{state} = 'error';
1174 0 $op->{error} = $error;
1175 0 $op->_cancel_timer;
1176 0 $self->_pending_callbacks($op, 1);
1177 }
1178  
1179 4 ▶sub _fail_pending {
Subroutine _fail_pending: called CC=4 SCAR=14.0
1180 4 my ($self, $pool, $op, $error) = @_;
1181 4 $self->_abandon_connect($pool, $op);
1182 4 ▶ for (my $i = 0; $i < @{ $pool->{pending} }; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$pool->{"pending"};}) 4 0 4
1183 4 ▶ next unless $pool->{pending}[$i] == $op;
Branch: 1 branch
BranchTrueFalseTotal
unless $pool->{"pending"}[$i] == $op 0 4 4
1184 4 splice @{ $pool->{pending} }, $i, 1;
1185 4 $self->{pending_count}--;
1186 4 last;
1187 }
1188 4 ▶ return if $op->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $op->is_terminal 0 4 4
1189 4 $op->{state} = 'error';
1190 4 $op->{error} = $error;
1191 4 $op->_cancel_timer;
1192 4 $self->_pending_callbacks($op, 1);
1193 }
1194  
1195 12 ▶sub _pending_callbacks {
Subroutine _pending_callbacks: called CC=6 SCAR=18.1
1196 12 my ($self, $op, $failed) = @_;
1197 12 my $callbacks = $op->{callbacks};
1198 12 ▶ if ($failed && $callbacks->{on_error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($failed and $callbacks->{"on_error"}) 4 8 12
Condition66%2/3
$failed and $callbacks->{"on_error"}
!ll&&!rl&&r
804
MC/DC50%1/2
$failed and $callbacks->{"on_error"}
$failed $callbacks->{"on_error"}
Truth table66%2/3
A and B
A= $failedB= $callbacks->{"on_error"}
ABresult
0X0
100
111
1199 4 ▶ eval { $callbacks->{on_error}->($op, $op->{error}); 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $callbacks->{"on_error"}->($op, $op->{"error"}); 1 } } or warn $@ 4 0 4
1200 or warn $@;
1201 }
1202 12 ▶ if ($callbacks->{on_finish}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callbacks->{"on_finish"}) 8 4 12
1203 8 ▶ eval { $callbacks->{on_finish}->($op); 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $callbacks->{"on_finish"}->($op); 1 } } or warn $@ 8 0 8
1204 or warn $@;
1205 }
1206 }
1207  
1208 8 ▶sub _cancel_queued {
Subroutine _cancel_queued: called CC=3 SCAR=11.0
1209 8 my ($self, $op) = @_;
1210 8 my $pool = $op->{origin};
1211 8 $self->_abandon_connect($pool, $op);
1212 8 ▶ for (my $i = 0; $i < @{ $pool->{pending} }; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$pool->{"pending"};}) 8 0 8
1213 8 ▶ next unless $pool->{pending}[$i] == $op;
Branch: 1 branch
BranchTrueFalseTotal
unless $pool->{"pending"}[$i] == $op 0 8 8
1214 8 splice @{ $pool->{pending} }, $i, 1;
1215 8 $self->{pending_count}--;
1216 8 last;
1217 }
1218 8 $self->_pending_callbacks($op, 0);
1219 8 $self->_schedule($pool);
1220 }
1221  
1222 10 1;
1223  
1224 __END__
↑ Summary HTTP/Server.pm »