blib/lib/Unblock/HTTP1/Server.pm

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