blib/lib/Unblock/HTTP1/Server.pm

filter: Statementstmt 95.7% 403 / 421 Branchbran 77.7% 241 / 310 Conditioncond 60.0% 93 / 155 MC/DCmcdc 36.6% 33 / 90 Subroutinesub 97.0% 33 / 34 Podpod 100% 4 / 4 totaltotal 79.5% 807 / 1014 CC 214 SCAR 34.1
CC
214
Cov
83%
_drive
82.0
_retire_if_done
22.1
_transaction_write
20.6
CRAP 30.2
« blib/lib/Unblock/HTTP1/Client.pm ↑ Summary blib/lib/Unblock/HTTP1/_Engine.pm »
1 package Unblock::HTTP1::Server;
2  
3 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 27 ▶use parent 'Unblock::HTTP1::_Engine';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 27 ▶use Uniform::HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 27 ▶use Uniform::HTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 27 ▶use Unblock::HTTP1::_Native ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 27 ▶use Unblock::HTTP1::_Wire ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 27 ▶use Unblock::HTTP1::Transaction;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 27 our $VERSION = '0.13';
15  
16 92 ▶sub new {
Subroutine new: called CC=5 SCAR=16.2
Pod documented
17 92 my ($class, %option) = @_;
18 92 my %callbacks;
19 92 for my $name (qw(on_request on_body on_request_end on_error on_switch)) {
20 460 ▶ next unless exists $option{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $option{$name} 301 159 460
21 159 my $cb = delete $option{$name};
22 159 ▶ croak "new(): $name must be a coderef" unless ref($cb) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cb eq "CODE" 0 159 159
23 159 $callbacks{$name} = $cb;
24 }
25 92 ▶ croak 'new(): on_request callback is required' unless $callbacks{on_request};
Branch: 1 branch
BranchTrueFalseTotal
unless $callbacks{"on_request"} 0 92 92
26 92 my $self = bless {
27 callbacks => \%callbacks,
28 active => undef,
29 rx => undef,
30 }, $class;
31 92 $self->_init_engine(%option);
32 91 return $self;
33 }
34  
35 1 ▶sub transaction { $_[0]{active} }
Subroutine transaction: called CC=1 SCAR=0.0
Pod documented
36  
37 12 ▶sub drain {
Subroutine drain: called CC=7 SCAR=19.6
Pod documented
38 12 my ($self) = @_;
39 12 ▶ return $self if $self->{closed} || $self->{switched} || $self->{draining};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} or $self->{"switched"} or $self->{"draining"} 6 6 12
Condition83%5/6
$self->{"closed"} or $self->{"switched"} or $self->{"draining"}
l!l&&r!l&&!r
426
$self->{"closed"} or $self->{"switched"}
l!l&&r!l&&!r
408
MC/DC66%2/3
$self->{"closed"} or $self->{"switched"} or $self->{"draining"}
$self->{"closed"} $self->{"switched"} $self->{"draining"}
Truth table75%3/4
A or B or C
A= $self->{"closed"}B= $self->{"switched"}C= $self->{"draining"}
ABCresult
1XX1
01X1
0011
0000
40 6 $self->{draining} = 1;
41 6 ▶ if (!$self->{active}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->{'active'}) { } 2 4 6
elsif ($self->{'active'}{'remote_done'}) { } 0 4 4
42 2 $self->{closed} = 1;
43 2 $self->_input_clear;
44 } elsif ($self->{active}{remote_done}) {
45 0 $self->_input_clear;
46 }
47 6 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 5 1 6
48 6 return $self;
49 }
50  
51 4 ▶sub want_read {
Subroutine want_read: called CC=4 SCAR=14.1
Pod documented
52 4 my ($self) = @_;
53 return 0 if $self->{draining}
54 4 ▶ && (!$self->{active} || $self->{active}{remote_done});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"draining"} and !$self->{"active"} || $self->{"active"}{"remote_done"} 2 2 4
Condition66%4/6
$self->{"draining"} and !$self->{"active"} || $self->{"active"}{"remote_done"}
!ll&&!rl&&r
022
not $self->{"active"} or $self->{"active"}{"remote_done"}
l!l&&r!l&&!r
022
MC/DC33%1/3
$self->{"draining"} and !$self->{"active"} || $self->{"active"}{"remote_done"}
$self->{"draining"} not $self->{"active"} $self->{"active"}{"remote_done"}
Truth table50%2/4
A and not(B) or C
A= $self->{"draining"}B= not $self->{"active"}C= $self->{"active"}{"remote_done"}
ABCresult
0XX0
1000
11X1
1011
55 2 return $self->SUPER::want_read;
56 }
57  
58 8 ▶sub _input_native_head {
Subroutine _input_native_head: called CC=10 SCAR=24.5
59 8 my ($self, $head, $request) = @_;
60 croak '_input_native_head(): cannot be called recursively from an engine callback'
61 8 ▶ if $self->{driving};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"driving"} 0 8 8
62 8 ▶ return (4, 0) if $self->{switched};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"switched"} 0 8 8
63 8 ▶ return (3, 0) if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 8 8
64 croak '_input_native_head(): cannot mix native head input with buffered portable input'
65 8 ▶ if length $self->{input};
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"input"} 0 8 8
66 croak '_input_native_head(): request body is already active'
67 8 ▶ if $self->{active} || $self->{rx};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"active"} or $self->{"rx"} 0 8 8
Condition33%1/3
$self->{"active"} or $self->{"rx"}
l!l&&r!l&&!r
008
MC/DC0%0/2
$self->{"active"} or $self->{"rx"}
$self->{"active"} $self->{"rx"}
Truth table33%1/3
A or B
A= $self->{"active"}B= $self->{"rx"}
ABresult
1X1
011
000
68  
69 8 my ($status, $ready);
70 {
71 8 local $self->{borrowed_head} = $head;
72 8 local $self->{borrowed_message} = $request;
73 8 local $self->{native_head_preconsumed} = 1;
74 8 local $self->{driving} = 1;
75 8 $self->_drive;
76 8 ▶ $status = $self->{closed} ? 3 : $self->{switched} ? 4 : 0;
Branch: 2 branches
BranchTrueFalseTotal
$self->{'closed'} ? : 0 8 8
$self->{'switched'} ? : 0 8 8
77 8 $ready = $self->_borrowed_native_head_ready;
78 }
79 8 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 1 7 8
80 8 return ($status, $ready);
81 }
82  
83 307 ▶sub _drive {
Subroutine _drive: called CC=65 SCAR=44.1
84 307 my ($self) = @_;
85 307 ▶ while (!$self->{closed} && !$self->{switched}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"closed"} or $self->{"switched"}) 381 20 401
Condition100%3/3
$self->{"closed"} or $self->{"switched"}
l!l&&r!l&&!r
137381
MC/DC100%2/2
$self->{"closed"} or $self->{"switched"}
$self->{"closed"} $self->{"switched"}
Truth table100%3/3
A or B
A= $self->{"closed"}B= $self->{"switched"}
ABresult
1X1
011
000
86 381 my $tx = $self->{active};
87 381 my $rx = $self->{rx};
88  
89 381 ▶ if (!$tx) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tx) 317 64 381
90 317 ▶ if ($self->{draining}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"draining"}) 0 317 317
91 0 $self->{closed} = 1;
92 0 $self->_input_clear;
93 0 return;
94 }
95 317 ▶ return unless $self->{borrowed_head} || $self->_input_length;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"borrowed_head"} or $self->_input_length 47 270 317
Condition100%3/3
$self->{"borrowed_head"} or $self->_input_length
l!l&&r!l&&!r
1725347
MC/DC100%2/2
$self->{"borrowed_head"} or $self->_input_length
$self->{"borrowed_head"} $self->_input_length
Truth table100%3/3
A or B
A= $self->{"borrowed_head"}B= $self->_input_length
ABresult
1X1
011
000
96 270 my $head = delete $self->{borrowed_head};
97 270 my $request = delete $self->{borrowed_message};
98 270 ▶ if (!$head) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($head) 253 17 270
99 253 my ($input, $offset) = $self->_input_window;
100 $head = Unblock::HTTP1::_Native->parse_request_head(
101 253 $input, 0, $self->{max_headers}, $offset,
102 );
103 }
104 270 ▶ if (!$head) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($head) 170 100 270
105 170 ▶ if ($self->_input_length > $self->{max_head_size}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_input_length > $self->{"max_head_size"}) 0 170 170
106 0 $self->_protocol_error(431, 'request head exceeds configured limit');
107 }
108 170 return;
109 }
110 100 ▶ if (!$head->{ok}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($head->{"ok"}) 2 98 100
111 2 ▶ $self->_protocol_error($head->{status} || 400, $head->{error});
Condition50%1/2
$head->{'status'} || 400
l!l
20
MC/DC0%0/1
$head->{'status'} || 400
$head->{'status'}
Truth table50%1/2
A
A= $head->{'status'}
Aresult
11
00
112 2 return;
113 }
114 98 ▶ if ($head->{consumed} > $self->{max_head_size}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($head->{"consumed"} > $self->{"max_head_size"}) 1 97 98
115 1 $self->_protocol_error(431, 'request head exceeds configured limit');
116 1 return;
117 }
118 $self->_input_discard($head->{consumed})
119 97 ▶ unless $self->{native_head_preconsumed};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"native_head_preconsumed"} 89 8 97
120  
121 97 ▶ if ($head->{expect_continue} < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($head->{"expect_continue"} < 0) 1 96 97
122 1 $self->_protocol_error(417, 'unsupported Expect field');
123 1 return;
124 }
125  
126 96 ▶ if (!$request) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($request) 79 17 96
127 my %target_metadata = Unblock::HTTP1::_Wire::_received_request_metadata(
128 $head->{method}, $head->{target},
129 79 );
130 79 $request = Unblock::HTTP1::_Wire::_request_from_validated_head(
131 $head, %target_metadata,
132 );
133 }
134  
135 96 $tx = Unblock::HTTP1::Transaction->_new(
136 $self, $request,
137 callbacks => {},
138 local_done => 0,
139 remote_done => 0,
140 );
141 96 ▶ $tx->{request_keep_alive} = $head->{keep_alive} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$head->{'keep_alive'} ? : 86 10 96
142 96 $tx->{request_body_mode} = $head->{body_mode};
143 96 $self->{active} = $tx;
144  
145 96 ▶ my $bodyless = $head->{body_mode} eq 'none' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$head->{'body_mode'} eq 'none' ? : 61 35 96
146 my $fixed_ready = !$bodyless
147 && $head->{body_mode} eq 'content-length'
148 && defined($head->{content_length})
149 96 ▶ && $self->_input_length >= $head->{content_length};
Condition88%8/9
!$bodyless && $head->{'body_mode'} eq 'content-length' && defined $head->{'content_length'} && $self->_input_length >= $head->{'content_length'}
!ll&&!rl&&r
71916
not $bodyless and $head->{"body_mode"} eq "content-length" and defined $head->{"content_length"}
!ll&&!rl&&r
71025
not $bodyless and $head->{"body_mode"} eq "content-length"
!ll&&!rl&&r
611025
MC/DC75%3/4
!$bodyless && $head->{'body_mode'} eq 'content-length' && defined $head->{'content_length'} && $self->_input_length >= $head->{'content_length'}
not $bodyless $head->{"body_mode"} eq "content-length" defined $head->{"content_length"} $self->_input_length >= $head->{'content_length'}
Truth table80%4/5
not(A) and B and C && D
A= not $bodylessB= $head->{"body_mode"} eq "content-length"C= defined $head->{"content_length"}D= $self->_input_length >= $head->{'content_length'}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
150  
151 96 ▶ if (!$bodyless && !$fixed_ready) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bodyless or $fixed_ready) 19 77 96
Condition100%3/3
$bodyless or $fixed_ready
l!l&&r!l&&!r
611619
MC/DC100%2/2
$bodyless or $fixed_ready
$bodyless $fixed_ready
Truth table100%3/3
A or B
A= $bodylessB= $fixed_ready
ABresult
1X1
011
000
152 $self->{rx} = $rx = {
153 mode => $head->{body_mode},
154 remaining => $head->{content_length},
155 19 request => $request,
156 };
157 19 ▶ if ($rx->{mode} eq 'chunked') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rx->{"mode"} eq "chunked") 10 9 19
158 10 $rx->{decoder} = Unblock::HTTP1::_Native::Chunked->new($self->{max_chunk_extension_size});
159 }
160 }
161  
162 96 ▶ if ($head->{expect_continue} > 0
Branch: 1 branch
BranchTrueFalseTotal
if ($head->{"expect_continue"} > 0 and $head->{"body_mode"} eq "chunked" || $head->{"body_mode"} eq "content-length" && $head->{"content_length"}) 1 95 96
Condition44%4/9
$head->{"expect_continue"} > 0 and $head->{"body_mode"} eq "chunked" || $head->{"body_mode"} eq "content-length" && $head->{"content_length"}
!ll&&!rl&&r
9501
$head->{"body_mode"} eq "chunked" or $head->{"body_mode"} eq "content-length" and $head->{"content_length"}
l!l&&r!l&&!r
010
$head->{"body_mode"} eq "content-length" and $head->{"content_length"}
!ll&&!rl&&r
001
MC/DC25%1/4
$head->{"expect_continue"} > 0 and $head->{"body_mode"} eq "chunked" || $head->{"body_mode"} eq "content-length" && $head->{"content_length"}
$head->{"expect_continue"} > 0 $head->{"body_mode"} eq "chunked" $head->{"body_mode"} eq "content-length" $head->{"content_length"}
Truth table40%2/5
A and B or C and D
A= $head->{"expect_continue"} > 0B= $head->{"body_mode"} eq "chunked"C= $head->{"body_mode"} eq "content-length"D= $head->{"content_length"}
ABCDresult
0XXX0
100X0
10100
11XX1
10111
163 && ($head->{body_mode} eq 'chunked'
164 || ($head->{body_mode} eq 'content-length'
165 && $head->{content_length}))) {
166 1 $self->_queue_output("HTTP/1.1 100 Continue\r\n\r\n");
167 }
168  
169 96 my $cb = $self->_invoke_server('on_request', $tx, $request);
170 96 ▶ return $self->_application_error($cb) unless $cb eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $cb eq 1 5 91 96
171 91 ▶ return if $self->{switched} || $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"switched"} or $self->{"closed"} 2 89 91
Condition66%2/3
$self->{"switched"} or $self->{"closed"}
l!l&&r!l&&!r
0289
MC/DC50%1/2
$self->{"switched"} or $self->{"closed"}
$self->{"switched"} $self->{"closed"}
Truth table66%2/3
A or B
A= $self->{"switched"}B= $self->{"closed"}
ABresult
1X1
011
000
172  
173 89 ▶ if ($bodyless) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bodyless) 56 33 89
174 56 $self->_complete_request($tx, $request);
175 56 next;
176 }
177  
178 33 ▶ if ($fixed_ready) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fixed_ready) 14 19 33
179 14 my $length = $head->{content_length};
180 14 ▶ if ($length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length) 9 5 14
181 9 my $bytes = $self->_input_take($length);
182 9 my $body_cb = $tx->_receive_data($request, $bytes);
183 9 ▶ return $self->_application_error($body_cb)
Branch: 1 branch
BranchTrueFalseTotal
unless $body_cb eq 1 0 9 9
184 unless $body_cb eq '1';
185 9 ▶ return if $self->{switched} || $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"switched"} or $self->{"closed"} 1 8 9
Condition66%2/3
$self->{"switched"} or $self->{"closed"}
l!l&&r!l&&!r
018
MC/DC50%1/2
$self->{"switched"} or $self->{"closed"}
$self->{"switched"} $self->{"closed"}
Truth table66%2/3
A or B
A= $self->{"switched"}B= $self->{"closed"}
ABresult
1X1
011
000
186 }
187 13 $self->_complete_request($tx, $request);
188 13 next;
189 }
190 }
191  
192 83 ▶ $tx = $self->{active} or next;
Branch: 1 branch
BranchTrueFalseTotal
$tx = $self->{"active"} or next 83 0 83
193 83 $rx = $self->{rx};
194 83 ▶ if (!$rx) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rx) 10 73 83
195 10 ▶ $self->_input_clear if $self->{draining};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"draining"} 2 8 10
196 10 return;
197 }
198  
199 73 ▶ if ($rx->{mode} eq 'content-length') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rx->{"mode"} eq "content-length") 19 54 73
200 19 ▶ return unless $self->_input_length;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_input_length 2 17 19
201 17 my $available = $self->_input_length;
202 my $take = $available < $rx->{remaining}
203 17 ▶ ? $available : $rx->{remaining};
Branch: 1 branch
BranchTrueFalseTotal
$available < $rx->{'remaining'} ? : 9 8 17
204 17 my $bytes = $self->_input_take($take);
205 17 $rx->{remaining} -= $take;
206 17 my $cb = $tx->_receive_data($rx->{request}, $bytes);
207 17 ▶ return $self->_application_error($cb) unless $cb eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $cb eq 1 1 16 17
208 16 ▶ return if $tx->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $tx->is_terminal 0 16 16
209 16 ▶ if ($rx->{remaining} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rx->{"remaining"} == 0) 7 9 16
210 7 $self->_finish_request;
211 7 next;
212 }
213 9 return;
214 }
215  
216 54 ▶ if ($rx->{mode} eq 'chunked') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rx->{"mode"} eq "chunked") 31 23 54
217 31 ▶ return unless $self->_input_length;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_input_length 2 29 31
218 29 my ($input, $offset) = $self->_input_window;
219 29 my $available = $self->_input_length;
220 29 my ($done, $decoded, $leftover);
221 29 my $ok = eval {
222 ($done, $decoded, $leftover) =
223 29 $rx->{decoder}->feed($input, 1, $offset);
224 28 1;
225 };
226 29 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 1 28 29
227 1 $self->_protocol_error(400, "$@");
228 1 return;
229 }
230 28 $self->_input_discard($available - length($leftover));
231 28 ▶ if (defined($decoded) && length($decoded)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $decoded and length $decoded) 15 13 28
Condition66%2/3
defined $decoded and length $decoded
!ll&&!rl&&r
01315
MC/DC50%1/2
defined $decoded and length $decoded
defined $decoded length $decoded
Truth table66%2/3
A and B
A= defined $decodedB= length $decoded
ABresult
0X0
100
111
232 15 my $cb = $tx->_receive_data($rx->{request}, $decoded);
233 15 ▶ return $self->_application_error($cb) unless $cb eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $cb eq 1 0 15 15
234 }
235 28 ▶ return if $tx->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $tx->is_terminal 0 28 28
236 28 ▶ return unless $done;
Branch: 1 branch
BranchTrueFalseTotal
unless $done 19 9 28
237 9 $rx->{mode} = 'trailers';
238 9 delete $rx->{decoder};
239 9 next;
240 }
241  
242 23 ▶ if ($rx->{mode} eq 'trailers') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rx->{"mode"} eq "trailers") 23 0 23
243 23 my ($input, $offset) = $self->_input_window;
244 my $trailers = Unblock::HTTP1::_Native->parse_trailers(
245 23 $input, 0, $self->{max_headers}, $offset,
246 );
247 23 ▶ if (!$trailers) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($trailers) 14 9 23
248 14 ▶ if ($self->_input_length > $self->{max_head_size}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_input_length > $self->{"max_head_size"}) 0 14 14
249 0 $self->_protocol_error(431, 'trailer section exceeds configured limit');
250 }
251 14 return;
252 }
253 9 ▶ if (!$trailers->{ok}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($trailers->{"ok"}) 0 9 9
254 0 $self->_protocol_error(400, $trailers->{error});
255 0 return;
256 }
257 9 ▶ if ($trailers->{consumed} > $self->{max_head_size}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trailers->{"consumed"} > $self->{"max_head_size"}) 0 9 9
258 0 $self->_protocol_error(431, 'trailer section exceeds configured limit');
259 0 return;
260 }
261 9 for my $field (@{ $trailers->{headers} }) {
262 6 my $name = lc $field->[0];
263 6 ▶ if ($name eq 'content-length' || $name eq 'transfer-encoding'
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "content-length" or $name eq "transfer-encoding" or $name eq "host" or $name eq "connection" or $name eq "trailer") 0 6 6
Condition33%4/12
$name eq "content-length" or $name eq "transfer-encoding" or $name eq "host" or $name eq "connection" or $name eq "trailer"
l!l&&r!l&&!r
006
$name eq "content-length" or $name eq "transfer-encoding" or $name eq "host" or $name eq "connection"
l!l&&r!l&&!r
006
$name eq "content-length" or $name eq "transfer-encoding" or $name eq "host"
l!l&&r!l&&!r
006
$name eq "content-length" or $name eq "transfer-encoding"
l!l&&r!l&&!r
006
MC/DC0%0/5
$name eq "content-length" or $name eq "transfer-encoding" or $name eq "host" or $name eq "connection" or $name eq "trailer"
$name eq "content-length" $name eq "transfer-encoding" $name eq "host" $name eq "connection" $name eq "trailer"
Truth table16%1/6
A or B or C or D or E
A= $name eq "content-length"B= $name eq "transfer-encoding"C= $name eq "host"D= $name eq "connection"E= $name eq "trailer"
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
264 || $name eq 'host' || $name eq 'connection' || $name eq 'trailer') {
265 0 $self->_protocol_error(400, 'forbidden framing field in HTTP/1 trailers');
266 0 return;
267 }
268 6 $rx->{request}->add_trailer(@$field);
269 }
270 9 $self->_input_discard($trailers->{consumed});
271 9 $self->_finish_request;
272 9 next;
273 }
274  
275 0 return $self->_protocol_error(400, 'invalid HTTP/1 server receive state');
276 }
277 20 return;
278 }
279  
280 16 ▶sub _finish_request {
Subroutine _finish_request: called CC=3 SCAR=11.4
281 16 my ($self) = @_;
282 16 ▶ my $tx = $self->{active} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $tx = $self->{"active"} or return 16 0 16
283 16 ▶ my $rx = delete $self->{rx} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $rx = delete $self->{"rx"} or return 16 0 16
284 16 return $self->_complete_request($tx, $rx->{request});
285 }
286  
287 85 ▶sub _complete_request {
Subroutine _complete_request: called CC=4 SCAR=13.9
288 85 my ($self, $tx, $request) = @_;
289 85 ▶ return if $tx->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $tx->is_terminal 0 85 85
290 85 ▶ if ($tx->{request_body_mode} eq 'none') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx->{'request_body_mode'} eq 'none') { } 56 29 85
291 # Both trusted head builders (portable FastPath and native ABI)
292 # already deliver a complete, frozen, empty-body Uniform Request.
293 # There can be no receive chunks to materialize in this case.
294 56 $tx->{receive_done} = 1;
295 } else {
296 29 $tx->_finish_receive($request);
297 29 $request->mark_complete->freeze;
298 }
299 85 $tx->_mark_remote_done;
300 85 my $cb;
301 {
302 85 local $self->{completing_request} = 1;
303 85 $cb = $self->_invoke_server('on_request_end', $tx, $request);
304 }
305 85 ▶ return $self->_application_error($cb) unless $cb eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $cb eq 1 0 85 85
306 85 $self->_retire_if_done;
307 85 return;
308 }
309  
310 94 ▶sub _transaction_respond {
Subroutine _transaction_respond: called CC=17 SCAR=28.8
311 94 my ($self, $tx, $response, %option) = @_;
312 croak 'respond(): Transaction is not active on this HTTP/1 connection'
313 94 ▶ unless $self->{active} && $self->{active} == $tx;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"active"} and $self->{"active"} == $tx 0 94 94
Condition33%1/3
$self->{"active"} and $self->{"active"} == $tx
!ll&&!rl&&r
0094
MC/DC0%0/2
$self->{"active"} and $self->{"active"} == $tx
$self->{"active"} $self->{"active"} == $tx
Truth table33%1/3
A and B
A= $self->{"active"}B= $self->{"active"} == $tx
ABresult
0X0
100
111
314 94 ▶ croak 'respond(): Transaction already has a Response' if $tx->response;
Branch: 1 branch
BranchTrueFalseTotal
if $tx->response 0 94 94
315 94 my $status = Unblock::HTTP1::_Wire::_status_code($response->status);
316 94 ▶ croak 'respond(): informational status must use send_informational()'
Branch: 1 branch
BranchTrueFalseTotal
if $status < 200 and $status != 101 1 93 94
Condition100%3/3
$status < 200 and $status != 101
!ll&&!rl&&r
8491
MC/DC100%2/2
$status < 200 and $status != 101
$status < 200 $status != 101
Truth table100%3/3
A and B
A= $status < 200B= $status != 101
ABresult
0X0
100
111
317 if $status < 200 && $status != 101;
318  
319 93 ▶ my $stream_body = delete($option{stream_body}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $option{'stream_body'} ? : 7 86 93
320 93 my $on_drain = delete $option{on_drain};
321 93 ▶ croak 'respond(): on_drain must be a coderef'
Branch: 1 branch
BranchTrueFalseTotal
if defined $on_drain and ref $on_drain ne "CODE" 0 93 93
Condition66%2/3
defined $on_drain and ref $on_drain ne "CODE"
!ll&&!rl&&r
9120
MC/DC0%0/2
defined $on_drain and ref $on_drain ne "CODE"
defined $on_drain ref $on_drain ne "CODE"
Truth table66%2/3
A and B
A= defined $on_drainB= ref $on_drain ne "CODE"
ABresult
0X0
100
111
322 if defined($on_drain) && ref($on_drain) ne 'CODE';
323 93 ▶ croak 'respond(): on_drain requires stream_body' if $on_drain && !$stream_body;
Branch: 1 branch
BranchTrueFalseTotal
if $on_drain and not $stream_body 0 93 93
Condition66%2/3
$on_drain and not $stream_body
!ll&&!rl&&r
9120
MC/DC0%0/2
$on_drain and not $stream_body
$on_drain not $stream_body
Truth table66%2/3
A and not(B)
A= $on_drainB= not $stream_body
ABresult
0X0
100
111
324 93 ▶ croak 'respond(): unknown options: ' . join(', ', sort keys %option) if %option;
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 93 93
325  
326 93 my $plan = Unblock::HTTP1::_Wire::response_plan(
327 $tx->request, $response,
328 stream_body => $stream_body,
329 );
330 89 $tx->_set_response($response);
331 89 $tx->{send_plan} = $plan;
332 89 $tx->{stream_body} = $stream_body;
333 89 ▶ $tx->{callbacks}{on_drain} = $on_drain if $on_drain;
Branch: 1 branch
BranchTrueFalseTotal
if $on_drain 2 87 89
334 # The queue now owns these bytes. A retained Transaction must not keep
335 # a second serialized copy of its canonical response body alive.
336 89 $self->_queue_output(delete $plan->{wire});
337  
338 89 ▶ if ($plan->{switch}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plan->{"switch"}) 8 81 89
339 8 $tx->_mark_local_done;
340 8 $tx->{switch_pending} = 1;
341 8 $self->_retire_if_done;
342 8 return $tx;
343 }
344  
345 81 ▶ if ($plan->{body_finalized}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plan->{"body_finalized"}) 74 7 81
346 74 $tx->_mark_local_done;
347 74 ▶ $tx->{keep_alive} = $plan->{keep_alive} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$plan->{'keep_alive'} ? : 64 10 74
348 74 $self->_retire_if_done;
349 }
350 81 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 23 58 81
351 81 return $tx;
352 }
353  
354 4 ▶sub _transaction_informational {
Subroutine _transaction_informational: called CC=8 SCAR=24.0
355 4 my ($self, $tx, $response) = @_;
356 croak 'send_informational(): Transaction is not active on this HTTP/1 connection'
357 4 ▶ unless $self->{active} && $self->{active} == $tx;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"active"} and $self->{"active"} == $tx 0 4 4
Condition33%1/3
$self->{"active"} and $self->{"active"} == $tx
!ll&&!rl&&r
004
MC/DC0%0/2
$self->{"active"} and $self->{"active"} == $tx
$self->{"active"} $self->{"active"} == $tx
Truth table33%1/3
A and B
A= $self->{"active"}B= $self->{"active"} == $tx
ABresult
0X0
100
111
358 4 my $status = $response->status;
359 4 ▶ croak 'send_informational(): status must be 100 through 199 except 101'
Branch: 1 branch
BranchTrueFalseTotal
unless $status >= 100 and $status < 200 and $status != 101 0 4 4
Condition33%2/6
$status >= 100 and $status < 200 and $status != 101
!ll&&!rl&&r
004
$status >= 100 and $status < 200
!ll&&!rl&&r
004
MC/DC0%0/3
$status >= 100 and $status < 200 and $status != 101
$status >= 100 $status < 200 $status != 101
Truth table25%1/4
A and B and C
A= $status >= 100B= $status < 200C= $status != 101
ABCresult
0XX0
10X0
1100
1111
360 unless $status >= 100 && $status < 200 && $status != 101;
361 4 ▶ croak 'send_informational(): HTTP/1.0 clients cannot receive 1xx responses'
Branch: 1 branch
BranchTrueFalseTotal
if ($tx->request->version || "1.1") eq "1.0" 1 3 4
Condition50%1/2
$tx->request->version || '1.1'
l!l
40
MC/DC0%0/1
$tx->request->version || '1.1'
$tx->request->version
Truth table50%1/2
A
A= $tx->request->version
Aresult
11
00
362 if ($tx->request->version || '1.1') eq '1.0';
363 3 my $plan = Unblock::HTTP1::_Wire::response_plan($tx->request, $response);
364 3 $self->_queue_output($plan->{wire});
365 3 return $tx;
366 }
367  
368 15 ▶sub _transaction_write {
Subroutine _transaction_write: called CC=19 SCAR=30.3
369 15 my ($self, $tx, $bytes, $final) = @_;
370 croak 'write(): Transaction is not active on this HTTP/1 connection'
371 15 ▶ unless $self->{active} && $self->{active} == $tx;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"active"} and $self->{"active"} == $tx 0 15 15
Condition33%1/3
$self->{"active"} and $self->{"active"} == $tx
!ll&&!rl&&r
0015
MC/DC0%0/2
$self->{"active"} and $self->{"active"} == $tx
$self->{"active"} $self->{"active"} == $tx
Truth table33%1/3
A and B
A= $self->{"active"}B= $self->{"active"} == $tx
ABresult
0X0
100
111
372 15 ▶ my $plan = $tx->{send_plan} or croak 'write(): respond() has not started a response';
Branch: 1 branch
BranchTrueFalseTotal
my $plan = $tx->{"send_plan"} or croak("write(): respond() has not started a response") 15 0 15
373 15 ▶ croak 'write(): response does not have a streaming body' unless $tx->{stream_body};
Branch: 1 branch
BranchTrueFalseTotal
unless $tx->{"stream_body"} 0 15 15
374 15 ▶ croak 'write(): streaming response body is already complete' if $tx->{local_done};
Branch: 1 branch
BranchTrueFalseTotal
if $tx->{"local_done"} 0 15 15
375 15 $bytes = Unblock::HTTP1::_Wire::_bytes('response body chunk', $bytes);
376  
377 15 ▶ if ($plan->{mode} eq 'chunked') {
Branch: 3 branches
BranchTrueFalseTotal
if ($plan->{'mode'} eq 'chunked') { } 11 4 15
elsif ($plan->{'mode'} eq 'content-length') { } 2 2 4
elsif ($plan->{'mode'} eq 'close') { } 2 0 2
378 11 $self->_queue_output(Unblock::HTTP1::_Wire::chunk($bytes));
379 11 ▶ if ($final) {
Branch: 1 branch
BranchTrueFalseTotal
if ($final) 5 6 11
380 5 my $trailers = Unblock::HTTP1::_Wire::_fields($tx->response, 'trailer');
381 5 $self->_queue_output(Unblock::HTTP1::_Wire::final_chunk($trailers));
382 5 $tx->_mark_local_done;
383 }
384 } elsif ($plan->{mode} eq 'content-length') {
385 2 my $remaining = $plan->{remaining};
386 2 ▶ croak 'write(): body exceeds declared Content-Length' if length($bytes) > $remaining;
Branch: 1 branch
BranchTrueFalseTotal
if length $bytes > $remaining 0 2 2
387 2 $self->_queue_output($bytes);
388 2 $remaining -= length($bytes);
389 2 $plan->{remaining} = $remaining;
390 2 ▶ croak 'end(): body ended before declared Content-Length' if $final && $remaining;
Branch: 1 branch
BranchTrueFalseTotal
if $final and $remaining 0 2 2
Condition66%2/3
$final and $remaining
!ll&&!rl&&r
110
MC/DC0%0/2
$final and $remaining
$final $remaining
Truth table66%2/3
A and B
A= $finalB= $remaining
ABresult
0X0
100
111
391 2 ▶ $tx->_mark_local_done if $remaining == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $remaining == 0 1 1 2
392 } elsif ($plan->{mode} eq 'close') {
393 2 $self->_queue_output($bytes);
394 2 ▶ $tx->_mark_local_done if $final;
Branch: 1 branch
BranchTrueFalseTotal
if $final 1 1 2
395 } else {
396 0 croak 'write(): invalid streaming response framing mode';
397 }
398  
399 15 ▶ if ($tx->{local_done}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx->{"local_done"}) 7 8 15
400 7 ▶ $tx->{keep_alive} = $plan->{keep_alive} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$plan->{'keep_alive'} ? : 6 1 7
401 7 $self->_retire_if_done;
402 }
403 15 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 6 9 15
404 15 my $ok = $self->_stream_ok;
405 15 ▶ $tx->{blocked} = 1 unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 6 9 15
406 15 return $ok;
407 }
408  
409 # Keep HTTP/1 pipelined response construction batched while preserving
410 # exactly-once terminal callbacks. A local response is not successfully
411 # complete until its complete output was accepted by the attached host.
412 97 ▶sub _transport_sync {
Subroutine _transport_sync: called CC=3 SCAR=11.0
413 97 my ($self) = @_;
414 97 ▶ return if $self->{driving} || $self->{transport_syncing};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"driving"} or $self->{"transport_syncing"} 25 72 97
Condition66%2/3
$self->{"driving"} or $self->{"transport_syncing"}
l!l&&r!l&&!r
25072
MC/DC50%1/2
$self->{"driving"} or $self->{"transport_syncing"}
$self->{"driving"} $self->{"transport_syncing"}
Truth table66%2/3
A or B
A= $self->{"driving"}B= $self->{"transport_syncing"}
ABresult
1X1
011
000
415 72 $self->SUPER::_transport_sync;
416 72 $self->_finish_accepted_output;
417 72 return;
418 }
419  
420 8 ▶sub _transport_finish {
Subroutine _transport_finish: called CC=2 SCAR=7.0
421 8 my ($self, $host) = @_;
422 # A host may synchronously close on finish (e.g. peer already at EOF).
423 # Commit accepted response completion before that terminal notification.
424 8 $self->_finish_accepted_output;
425 8 ▶ $self->SUPER::_transport_finish($host) unless $self->{transport_aborted};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"transport_aborted"} 8 0 8
426 8 return;
427 }
428  
429 80 ▶sub _finish_accepted_output {
Subroutine _finish_accepted_output: called CC=6 SCAR=17.9
430 80 my ($self) = @_;
431 80 ▶ return if $self->{transport_aborted} || length($self->{output});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_aborted"} or length $self->{"output"} 25 55 80
Condition100%3/3
$self->{"transport_aborted"} or length $self->{"output"}
l!l&&r!l&&!r
71855
MC/DC100%2/2
$self->{"transport_aborted"} or length $self->{"output"}
$self->{"transport_aborted"} length $self->{"output"}
Truth table100%3/3
A or B
A= $self->{"transport_aborted"}B= length $self->{"output"}
ABresult
1X1
011
000
432 55 ▶ my $pending = delete $self->{pending_host_finishes} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $pending = delete $self->{"pending_host_finishes"} or return 13 42 55
433 13 for my $tx (@$pending) {
434 16 ▶ $tx->_mark_complete unless $tx->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $tx->is_terminal 16 0 16
435 16 $tx->_notify_finish;
436 }
437 13 return;
438 }
439  
440 174 ▶sub _retire_if_done {
Subroutine _retire_if_done: called CC=22 SCAR=31.0
441 174 my ($self) = @_;
442 174 ▶ my $tx = $self->{active} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $tx = $self->{"active"} or return 173 1 174
443 173 ▶ return if $self->{completing_request};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"completing_request"} 35 138 173
444 138 ▶ return unless $tx->{local_done} && $tx->{remote_done};
Branch: 1 branch
BranchTrueFalseTotal
unless $tx->{"local_done"} and $tx->{"remote_done"} 55 83 138
Condition100%3/3
$tx->{"local_done"} and $tx->{"remote_done"}
!ll&&!rl&&r
104583
MC/DC100%2/2
$tx->{"local_done"} and $tx->{"remote_done"}
$tx->{"local_done"} $tx->{"remote_done"}
Truth table100%3/3
A and B
A= $tx->{"local_done"}B= $tx->{"remote_done"}
ABresult
0X0
100
111
445 83 ▶ if ($tx->{switch_pending}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx->{"switch_pending"}) 8 75 83
446 8 ▶ $tx->_mark_complete unless $tx->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $tx->is_terminal 8 0 8
447 8 my $response = $tx->response;
448 8 $self->_mark_switched;
449 8 $self->{active} = undef;
450 8 ▶ if ($self->{transport_attached}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"transport_attached"}) 3 5 8
451 3 $self->{switch_notice} = [ $tx, $response ];
452 3 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 3 0 3
453 3 return;
454 }
455 5 return $self->_deliver_switch_notice($tx, $response);
456 }
457 # The HTTP/1 parser can finish several pipelined requests during one
458 # input call. Retire them from parsing now, but hold their terminal
459 # observers until the whole coalesced output is accepted by the host.
460 75 ▶ my $await_host = $self->{transport_attached} && length($self->{output});
Condition100%3/3
$self->{'transport_attached'} && length $self->{'output'}
!ll&&!rl&&r
52320
MC/DC100%2/2
$self->{'transport_attached'} && length $self->{'output'}
$self->{'transport_attached'} length $self->{'output'}
Truth table100%3/3
A && B
A= $self->{'transport_attached'}B= length $self->{'output'}
ABresult
0X0
100
111
461 75 ▶ if ($await_host) {
Branch: 1 branch
BranchTrueFalseTotal
if ($await_host) { } 20 55 75
462 20 ▶ push @{ $self->{pending_host_finishes} //= [] }, $tx;
Condition100%2/2
$self->{"pending_host_finishes"} //= []
l!l
317
MC/DC100%1/1
$self->{"pending_host_finishes"} //= []
$self->{"pending_host_finishes"}
Truth table100%2/2
A
A= $self->{"pending_host_finishes"}
Aresult
11
00
463 } else {
464 55 ▶ $tx->_mark_complete unless $tx->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $tx->is_terminal 55 0 55
465 }
466 75 my $keep = $tx->{keep_alive};
467 75 ▶ $keep = $tx->{request_keep_alive} unless defined $keep;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $keep 0 75 75
468 75 $self->{active} = undef;
469 75 ▶ if (!$keep || $self->{eof} || $self->{draining}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $keep or $self->{"eof"} or $self->{"draining"}) 16 59 75
Condition100%6/6
not $keep or $self->{"eof"} or $self->{"draining"}
l!l&&r!l&&!r
12459
not $keep or $self->{"eof"}
l!l&&r!l&&!r
11163
MC/DC100%3/3
not $keep or $self->{"eof"} or $self->{"draining"}
not $keep $self->{"eof"} $self->{"draining"}
Truth table100%4/4
not(A) or B or C
A= not $keepB= $self->{"eof"}C= $self->{"draining"}
ABCresult
1XX1
01X1
0011
0000
470 16 $self->{closed} = 1;
471 16 $self->_input_clear;
472 }
473 75 ▶ $tx->_notify_finish unless $await_host;
Branch: 1 branch
BranchTrueFalseTotal
unless $await_host 55 20 75
474 75 ▶ if ($self->{closed}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"closed"}) 16 59 75
475 16 ▶ $self->_transport_sync if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 6 10 16
476 16 return;
477 }
478 59 ▶ return if $self->{driving};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"driving"} 55 4 59
479 4 local $self->{driving} = 1;
480 4 ▶ $self->_drive if $self->_input_length;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_input_length 0 4 4
481 4 return;
482 }
483  
484 8 ▶sub _deliver_switch_notice {
Subroutine _deliver_switch_notice: called CC=3 SCAR=11.1
485 8 my ($self, $tx, $response) = @_;
486 8 my $cb = $self->_invoke_server('on_switch', $tx, $response);
487 8 $tx->_notify_finish;
488 8 ▶ if ($cb ne '1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cb ne 1) 1 7 8
489 1 ▶ if ($self->{transport_attached}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'transport_attached'}) { } 1 0 1
490 1 $self->_transport_abort($cb);
491 } else {
492 0 $self->_application_error($cb);
493 }
494 }
495 8 return;
496 }
497  
498 4 ▶sub _transaction_cancel {
Subroutine _transaction_cancel: called CC=5 SCAR=16.4
499 4 my ($self, $tx) = @_;
500 4 ▶ return if $tx->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $tx->is_terminal 0 4 4
501 4 $tx->_mark_cancelled;
502 4 ▶ $self->{active} = undef if $self->{active} && $self->{active} == $tx;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"active"} and $self->{"active"} == $tx 4 0 4
Condition33%1/3
$self->{"active"} and $self->{"active"} == $tx
!ll&&!rl&&r
004
MC/DC0%0/2
$self->{"active"} and $self->{"active"} == $tx
$self->{"active"} $self->{"active"} == $tx
Truth table33%1/3
A and B
A= $self->{"active"}B= $self->{"active"} == $tx
ABresult
0X0
100
111
503 4 $self->{rx} = undef;
504 4 $self->{closed} = 1;
505 4 $self->_input_clear;
506 {
507 4 local $self->{cancelling} = 1;
508 $self->_transport_abort('HTTP/1 transaction cancelled')
509 4 ▶ if $self->{transport_attached};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"transport_attached"} 1 3 4
510 }
511 4 $tx->_notify_finish;
512 4 return;
513 }
514  
515 49 ▶sub _maybe_drain {
Subroutine _maybe_drain: called CC=4 SCAR=13.9
516 49 my ($self) = @_;
517 49 ▶ my $tx = $self->{active} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $tx = $self->{"active"} or return 4 45 49
518 4 ▶ return unless $tx->{blocked};
Branch: 1 branch
BranchTrueFalseTotal
unless $tx->{"blocked"} 2 2 4
519 2 $tx->{blocked} = 0;
520 2 my $cb = $tx->_invoke('on_drain');
521 2 ▶ $self->_application_error($cb) unless $cb eq '1';
Branch: 1 branch
BranchTrueFalseTotal
unless $cb eq 1 0 2 2
522 2 return;
523 }
524  
525 226 ▶sub _invoke_server {
Subroutine _invoke_server: called CC=6 SCAR=17.9
526 226 my ($self, $name, @args) = @_;
527 226 ▶ my $cb = $self->{callbacks}{$name} or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $cb = $self->{"callbacks"}{$name} or return 1 165 61 226
528 165 my $tx = $args[0];
529 165 ▶ $tx->{callback_depth}++ if $tx;
Branch: 1 branch
BranchTrueFalseTotal
if $tx 162 3 165
530 165 my $ok = eval { $cb->(@args); 1 };
531 165 my $error = "$@";
532 165 ▶ if ($tx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx) 162 3 165
533 162 $tx->{callback_depth}--;
534 162 ▶ $tx->_notify_finish if $tx->{finish_pending};
Branch: 1 branch
BranchTrueFalseTotal
if $tx->{"finish_pending"} 3 159 162
535 }
536 165 ▶ return $ok ? 1 : $error;
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 158 7 165
537 }
538  
539 6 ▶sub _application_error {
Subroutine _application_error: called CC=9 SCAR=24.6
540 6 my ($self, $error) = @_;
541 6 ▶ $error = 'HTTP/1 server callback failed' unless defined($error) && length($error);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $error and length $error 0 6 6
Condition33%1/3
defined $error and length $error
!ll&&!rl&&r
006
MC/DC0%0/2
defined $error and length $error
defined $error length $error
Truth table33%1/3
A and B
A= defined $errorB= length $error
ABresult
0X0
100
111
542 6 my $tx = $self->{active};
543 6 ▶ if ($tx && !$tx->response && !$self->{switched}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tx and not $tx->response and not $self->{"switched"}) 6 0 6
Condition33%2/6
$tx and not $tx->response and not $self->{"switched"}
!ll&&!rl&&r
006
$tx and not $tx->response
!ll&&!rl&&r
006
MC/DC0%0/3
$tx and not $tx->response and not $self->{"switched"}
$tx not $tx->response not $self->{"switched"}
Truth table25%1/4
A and not(B) and not(C)
A= $txB= not $tx->responseC= not $self->{"switched"}
ABCresult
0XX0
10X0
1100
1111
544 6 local $self->{completing_request} = 1;
545 6 eval {
546 6 my $response = Uniform::HTTP::Response->new(status => 500, body => '');
547 6 $self->_transaction_respond($tx, $response);
548 6 1;
549 };
550 }
551 6 $self->{closed} = 1;
552 6 ▶ $tx->_fail($error) if $tx && !$tx->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $tx and not $tx->is_terminal 6 0 6
Condition33%1/3
$tx and not $tx->is_terminal
!ll&&!rl&&r
006
MC/DC0%0/2
$tx and not $tx->is_terminal
$tx not $tx->is_terminal
Truth table33%1/3
A and not(B)
A= $txB= not $tx->is_terminal
ABresult
0X0
100
111
553 6 $self->_invoke_server('on_error', $tx, $error);
554 6 $self->{active} = undef;
555 6 $self->{rx} = undef;
556 6 $self->_input_clear;
557 6 ▶ $tx->_notify_finish if $tx;
Branch: 1 branch
BranchTrueFalseTotal
if $tx 6 0 6
558 6 return;
559 }
560  
561 6 ▶sub _protocol_error {
Subroutine _protocol_error: called CC=12 SCAR=27.4
562 6 my ($self, $status, $detail) = @_;
563 6 ▶ return if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 6 6
564 6 ▶ my $reason = $status == 400 ? 'Bad Request'
Branch: 5 branches
BranchTrueFalseTotal
$status == 400 ? : 3 3 6
$status == 417 ? : 1 2 3
$status == 431 ? : 2 0 2
$status == 501 ? : 0 0 0
$status == 505 ? : 0 0 0
565 : $status == 417 ? 'Expectation Failed'
566 : $status == 431 ? 'Request Header Fields Too Large'
567 : $status == 501 ? 'Not Implemented'
568 : $status == 505 ? 'HTTP Version Not Supported'
569 : 'Bad Request';
570 6 my $wire = 'HTTP/1.1 ' . $status . ' ' . $reason . "\r\n"
571 . "Content-Length: 0\r\nConnection: close\r\n\r\n";
572 6 $self->_queue_output($wire);
573 6 $self->{closed} = 1;
574 6 ▶ if (my $tx = $self->{active}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tx = $self->{"active"}) 2 4 6
575 2 ▶ $tx->_fail($detail || $reason) unless $tx->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $tx->is_terminal 2 0 2
Condition33%1/3
$detail || $reason
l!l&&r!l&&!r
200
MC/DC0%0/2
$detail || $reason
$detail $reason
Truth table33%1/3
A || B
A= $detailB= $reason
ABresult
1X1
011
000
576 }
577 6 ▶ $self->_invoke_server('on_error', $self->{active}, $detail || $reason);
Condition33%1/3
$detail || $reason
l!l&&r!l&&!r
600
MC/DC0%0/2
$detail || $reason
$detail $reason
Truth table33%1/3
A || B
A= $detailB= $reason
ABresult
1X1
011
000
578 6 my $tx = delete $self->{active};
579 6 $self->{rx} = undef;
580 6 $self->_input_clear;
581 6 ▶ $tx->_notify_finish if $tx;
Branch: 1 branch
BranchTrueFalseTotal
if $tx 2 4 6
582 6 return;
583 }
584  
585 0 ▶sub _borrowed_should_buffer_tail {
Subroutine _borrowed_should_buffer_tail: not called CC=3 SCAR=24.8
586 0 my ($self) = @_;
587 0 ▶ return $self->{active} && !$self->{rx} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'active'} && !$self->{'rx'} ? : 0 0 0
Condition0%0/3
$self->{"active"} and not $self->{"rx"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"active"} and not $self->{"rx"}
$self->{"active"} not $self->{"rx"}
Truth table0%0/3
A and not(B)
A= $self->{"active"}B= not $self->{"rx"}
ABresult
0X0
100
111
588 }
589  
590 20 ▶sub _borrowed_native_head_ready {
Subroutine _borrowed_native_head_ready: called CC=6 SCAR=18.2
591 20 my ($self) = @_;
592 20 ▶ return 0 if $self->{closed} || $self->{switched};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} or $self->{"switched"} 2 18 20
Condition66%2/3
$self->{"closed"} or $self->{"switched"}
l!l&&r!l&&!r
0218
MC/DC50%1/2
$self->{"closed"} or $self->{"switched"}
$self->{"closed"} $self->{"switched"}
Truth table66%2/3
A or B
A= $self->{"closed"}B= $self->{"switched"}
ABresult
1X1
011
000
593 18 ▶ return 0 if $self->{active} || $self->{rx};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"active"} or $self->{"rx"} 4 14 18
Condition66%2/3
$self->{"active"} or $self->{"rx"}
l!l&&r!l&&!r
4014
MC/DC50%1/2
$self->{"active"} or $self->{"rx"}
$self->{"active"} $self->{"rx"}
Truth table66%2/3
A or B
A= $self->{"active"}B= $self->{"rx"}
ABresult
1X1
011
000
594 14 ▶ return 0 if length $self->{input};
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"input"} 0 14 14
595 14 return 1;
596 }
597  
598 2 ▶sub _on_eof {
Subroutine _on_eof: called CC=6 SCAR=19.2
599 2 my ($self) = @_;
600 2 ▶ return if $self->{switched};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"switched"} 0 2 2
601 2 ▶ if ($self->{active} && $self->{active}{remote_done}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"active"} and $self->{"active"}{"remote_done"}) 1 1 2
Condition66%2/3
$self->{"active"} and $self->{"active"}{"remote_done"}
!ll&&!rl&&r
011
MC/DC50%1/2
$self->{"active"} and $self->{"active"}{"remote_done"}
$self->{"active"} $self->{"active"}{"remote_done"}
Truth table66%2/3
A and B
A= $self->{"active"}B= $self->{"active"}{"remote_done"}
ABresult
0X0
100
111
602 # A fully received request may still have a delayed application
603 # response. Read EOF prevents reuse but does not cancel that reply.
604 1 $self->{active}{request_keep_alive} = 0;
605 1 return;
606 }
607 1 ▶ if ($self->{active} || length($self->{input})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'active'} or length $self->{'input'}) { } 1 0 1
Condition33%1/3
$self->{"active"} or length $self->{"input"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->{"active"} or length $self->{"input"}
$self->{"active"} length $self->{"input"}
Truth table33%1/3
A or B
A= $self->{"active"}B= length $self->{"input"}
ABresult
1X1
011
000
608 1 $self->_protocol_error(400, 'unexpected EOF in HTTP/1 request');
609 } else {
610 0 $self->{closed} = 1;
611 }
612 1 return;
613 }
614  
615 7 ▶sub _fail_all {
Subroutine _fail_all: called CC=8 SCAR=21.2
616 7 my ($self, $error) = @_;
617 7 my $tx = delete $self->{active};
618 7 ▶ $tx->_fail($error) if $tx && !$tx->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $tx and not $tx->is_terminal 0 7 7
Condition33%1/3
$tx and not $tx->is_terminal
!ll&&!rl&&r
700
MC/DC0%0/2
$tx and not $tx->is_terminal
$tx not $tx->is_terminal
Truth table33%1/3
A and not(B)
A= $txB= not $tx->is_terminal
ABresult
0X0
100
111
619 7 $self->{rx} = undef;
620 7 $self->_input_clear;
621 7 ▶ my $pending = delete $self->{pending_host_finishes} || [];
Condition100%2/2
delete $self->{'pending_host_finishes'} || []
l!l
43
MC/DC100%1/1
delete $self->{'pending_host_finishes'} || []
delete $self->{'pending_host_finishes'}
Truth table100%2/2
A
A= delete $self->{'pending_host_finishes'}
Aresult
11
00
622 7 $_->_fail($error) for grep { !$_->is_terminal } @$pending;
623 7 ▶ $self->_invoke_server('on_error', $tx, $error) unless $self->{cancelling};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"cancelling"} 6 1 7
624 7 ▶ $tx->_notify_finish if $tx;
Branch: 1 branch
BranchTrueFalseTotal
if $tx 0 7 7
625 7 $_->_notify_finish for @$pending;
626 7 return;
627 }
628  
629 27 1;
630  
631 __END__
« blib/lib/Unblock/HTTP1/Client.pm ↑ Summary blib/lib/Unblock/HTTP1/_Engine.pm »