blib/lib/Unblock/HTTP1/_Wire.pm

filter: Statementstmt 88.7% 752 / 847 Branchbran 68.9% 513 / 744 Conditioncond 57.8% 286 / 494 MC/DCmcdc 27.9% 72 / 258 Subroutinesub 96.3% 52 / 54 Podpod 0.0% 0 / 5 totaltotal 69.7% 1675 / 2402 CC 568 SCAR 49.9
CC
568
Cov
74%
response_plan
506.1
request_plan
141.5
_simple_response_plan_portable
90.7
CRAP 146.2
↑ Summary blib/lib/Unblock/HTTP1/Client.pm »
1 package Unblock::HTTP1::_Wire;
2  
3 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 35 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 35 ▶use Config ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 35 ▶use utf8 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 35 ▶use Uniform::HTTP::FastPath ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 35 ▶my $MAX_CONTENT_LENGTH = $Config::Config{uvsize} >= 8
Branch: 1 branch
BranchTrueFalseTotal
$Config::Config{'uvsize'} >= 8 ? : 35 0 35
11 ? '18446744073709551615'
12 : '4294967295';
13  
14 71 ▶sub _request_from_validated_head {
Subroutine _request_from_validated_head: called CC=3 SCAR=11.0
15 71 my ($head, %metadata) = @_;
16  
17 71 my $flags =
18 Uniform::HTTP::FastPath::FLAG_HEADERS_LOSSLESS()
19 | Uniform::HTTP::FastPath::FLAG_TRAILERS_LOSSLESS()
20 | Uniform::HTTP::FastPath::FLAG_TARGET_EXACT();
21  
22 71 ▶ if ($head->{body_mode} eq 'none') {
Branch: 1 branch
BranchTrueFalseTotal
if ($head->{'body_mode'} eq 'none') { } 46 25 71
23 46 $flags |= Uniform::HTTP::FastPath::FLAG_COMPLETE()
24 | Uniform::HTTP::FastPath::FLAG_HAS_BUFFERED_BODY();
25 } else {
26 25 $flags |=
27 Uniform::HTTP::FastPath::FLAG_MUTABLE()
28 | Uniform::HTTP::FastPath::FLAG_BODY_MUTABLE()
29 | Uniform::HTTP::FastPath::FLAG_TRAILERS_MUTABLE();
30 }
31  
32 return Uniform::HTTP::FastPath::request_from_validated([
33 Uniform::HTTP::FastPath::ABI_VERSION(),
34 Uniform::HTTP::FastPath::KIND_REQUEST(),
35 $flags,
36 $head->{version},
37 $head->{method},
38 $head->{target},
39 $metadata{scheme},
40 $metadata{authority},
41 $metadata{protocol},
42 undef,
43 undef,
44 $head->{headers},
45 [],
46 71 ▶ $head->{body_mode} eq 'none' ? '' : undef,
Branch: 1 branch
BranchTrueFalseTotal
$head->{'body_mode'} eq 'none' ? : 46 25 71
47 ]);
48 }
49  
50 56 ▶sub _response_from_validated_head {
Subroutine _response_from_validated_head: called CC=2 SCAR=6.9
51 56 my ($head, $informational) = @_;
52  
53 56 my $flags =
54 Uniform::HTTP::FastPath::FLAG_HEADERS_LOSSLESS()
55 | Uniform::HTTP::FastPath::FLAG_TRAILERS_LOSSLESS();
56  
57 56 ▶ if ($informational) {
Branch: 1 branch
BranchTrueFalseTotal
if ($informational) { } 4 52 56
58 4 $flags |= Uniform::HTTP::FastPath::FLAG_COMPLETE();
59 } else {
60 52 $flags |=
61 Uniform::HTTP::FastPath::FLAG_MUTABLE()
62 | Uniform::HTTP::FastPath::FLAG_BODY_MUTABLE()
63 | Uniform::HTTP::FastPath::FLAG_TRAILERS_MUTABLE();
64 }
65  
66 return Uniform::HTTP::FastPath::response_from_validated([
67 Uniform::HTTP::FastPath::ABI_VERSION(),
68 Uniform::HTTP::FastPath::KIND_RESPONSE(),
69 $flags,
70 $head->{version},
71 undef,
72 undef,
73 undef,
74 undef,
75 undef,
76 $head->{status},
77 $head->{reason},
78 $head->{headers},
79 56 [],
80 undef,
81 ]);
82 }
83  
84 257 ▶sub _fast_request_view {
Subroutine _fast_request_view: called CC=2 SCAR=6.9
85 257 my ($request) = @_;
86 257 ▶ return unless ref($request) eq 'Uniform::HTTP::Request';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $request eq "Uniform::HTTP::Request" 7 250 257
87 250 return Uniform::HTTP::FastPath::view($request);
88 }
89  
90 103 ▶sub _fast_response_view {
Subroutine _fast_response_view: called CC=2 SCAR=6.9
91 103 my ($response) = @_;
92 103 ▶ return unless ref($response) eq 'Uniform::HTTP::Response';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $response eq "Uniform::HTTP::Response" 6 97 103
93 97 return Uniform::HTTP::FastPath::view($response);
94 }
95  
96 35 my %REASON = (
97 100 => 'Continue', 101 => 'Switching Protocols', 103 => 'Early Hints',
98 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 204 => 'No Content',
99 205 => 'Reset Content', 206 => 'Partial Content',
100 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found',
101 303 => 'See Other', 304 => 'Not Modified', 307 => 'Temporary Redirect',
102 308 => 'Permanent Redirect', 400 => 'Bad Request', 401 => 'Unauthorized',
103 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed',
104 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone',
105 411 => 'Length Required', 413 => 'Content Too Large', 414 => 'URI Too Long',
106 415 => 'Unsupported Media Type', 417 => 'Expectation Failed',
107 421 => 'Misdirected Request', 422 => 'Unprocessable Content',
108 426 => 'Upgrade Required', 428 => 'Precondition Required',
109 429 => 'Too Many Requests', 431 => 'Request Header Fields Too Large',
110 451 => 'Unavailable For Legal Reasons', 500 => 'Internal Server Error',
111 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable',
112 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported',
113 );
114  
115 549 ▶sub _bytes {
Subroutine _bytes: called CC=4 SCAR=15.2
116 549 my ($label, $value) = @_;
117 549 ▶ croak "$label must be a defined scalar byte string"
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or ref $value 0 549 549
Condition33%1/3
not defined $value or ref $value
l!l&&r!l&&!r
00549
MC/DC0%0/2
not defined $value or ref $value
not defined $value ref $value
Truth table33%1/3
not(A) or B
A= not defined $valueB= ref $value
ABresult
1X1
011
000
118 if !defined($value) || ref($value);
119 549 my $copy = "$value";
120 549 ▶ croak "$label must be a byte string" unless utf8::downgrade($copy, 1);
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::downgrade($copy, 1) 0 549 549
121 549 return $copy;
122 }
123  
124 190 ▶sub _method {
Subroutine _method: called CC=2 SCAR=6.9
125 190 my ($value) = @_;
126 190 $value = _bytes('request method', $value);
127 190 ▶ croak 'request method must be an HTTP token'
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /\A[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]+\z/ 1 189 190
128 unless $value =~ /\A[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]+\z/;
129 189 return $value;
130 }
131  
132 9 ▶sub _field_name {
Subroutine _field_name: called CC=2 SCAR=6.9
133 9 my ($section, $value) = @_;
134 9 $value = _bytes("$section name", $value);
135 9 ▶ croak "invalid $section field name"
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /\A[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]+\z/ 2 7 9
136 unless $value =~ /\A[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]+\z/;
137 7 return $value;
138 }
139  
140 5 ▶sub _field_value {
Subroutine _field_value: called CC=2 SCAR=6.9
141 5 my ($section, $value) = @_;
142 5 $value = _bytes("$section value", $value);
143 5 ▶ croak "invalid $section field value"
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /[\x00-\x08\x0a-\x1f\x7f]/ 2 3 5
144 if $value =~ /[\x00-\x08\x0a-\x1f\x7f]/;
145 3 return $value;
146 }
147  
148 88 ▶sub _status_code {
Subroutine _status_code: called CC=6 SCAR=21.4
149 88 my ($value) = @_;
150 88 ▶ croak 'response status must be a three-digit integer from 100 through 599'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or ref $value or not "$value" =~ /\A[0-9]{3}\z/ or $value < 100 or $value > 599 1 87 88
Condition41%5/12
not defined $value or ref $value or not "$value" =~ /\A[0-9]{3}\z/ or $value < 100 or $value > 599
l!l&&r!l&&!r
0187
not defined $value or ref $value or not "$value" =~ /\A[0-9]{3}\z/ or $value < 100
l!l&&r!l&&!r
0088
not defined $value or ref $value or not "$value" =~ /\A[0-9]{3}\z/
l!l&&r!l&&!r
0088
not defined $value or ref $value
l!l&&r!l&&!r
0088
MC/DC20%1/5
not defined $value or ref $value or not "$value" =~ /\A[0-9]{3}\z/ or $value < 100 or $value > 599
not defined $value ref $value not "$value" =~ /\A[0-9]{3}\z/ $value < 100 $value > 599
Truth table33%2/6
not(A) or B or not(C) or D or E
A= not defined $valueB= ref $valueC= not "$value" =~ /\A[0-9]{3}\z/D= $value < 100E= $value > 599
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
151 if !defined($value) || ref($value)
152 || "$value" !~ /\A[0-9]{3}\z/
153 || $value < 100 || $value > 599;
154 87 return 0 + $value;
155 }
156  
157 1 ▶sub _reason_phrase {
Subroutine _reason_phrase: called CC=2 SCAR=7.6
158 1 my ($value) = @_;
159 1 $value = _bytes('response reason', $value);
160 1 ▶ croak 'invalid HTTP/1 response reason phrase'
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /[\x00-\x08\x0a-\x1f\x7f]/ 1 0 1
161 if $value =~ /[\x00-\x08\x0a-\x1f\x7f]/;
162 0 return $value;
163 }
164  
165 2124 ▶sub _lc {
Subroutine _lc: called CC=1 SCAR=0.0
166 2124 my ($value) = @_;
167 2124 $value =~ tr/A-Z/a-z/;
168 2124 return $value;
169 }
170  
171 204 ▶sub _fields {
Subroutine _fields: called CC=8 SCAR=21.4
172 204 my ($message, $section, $view) = @_;
173  
174 204 ▶ if ($view) {
Branch: 1 branch
BranchTrueFalseTotal
if ($view) 199 5 204
175 199 ▶ my $slot = $section eq 'trailer'
Branch: 1 branch
BranchTrueFalseTotal
$section eq 'trailer' ? : 67 132 199
176 ? Uniform::HTTP::FastPath::SLOT_TRAILERS()
177 : Uniform::HTTP::FastPath::SLOT_HEADERS();
178 199 return $view->[$slot];
179 }
180  
181 5 ▶ my $count_method = $section eq 'trailer' ? 'trailer_count' : 'header_count';
Branch: 1 branch
BranchTrueFalseTotal
$section eq 'trailer' ? : 5 0 5
182 5 ▶ my $name_method = $section eq 'trailer' ? 'trailer_name' : 'header_name';
Branch: 1 branch
BranchTrueFalseTotal
$section eq 'trailer' ? : 5 0 5
183 5 ▶ my $value_method = $section eq 'trailer' ? 'trailer_value' : 'header_value';
Branch: 1 branch
BranchTrueFalseTotal
$section eq 'trailer' ? : 5 0 5
184 5 my $count = $message->$count_method();
185 5 ▶ croak "$section fields are unavailable" unless defined $count;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $count 0 5 5
186 5 my @fields;
187 5 for my $i (0 .. $count - 1) {
188 0 push @fields, [
189 _field_name($section, $message->$name_method($i)),
190 _field_value($section, $message->$value_method($i)),
191 ];
192 }
193 5 return \@fields;
194 }
195  
196 748 ▶sub _values {
Subroutine _values: called CC=1 SCAR=0.0
197 748 my ($fields, $wanted) = @_;
198 748 my $key = _lc($wanted);
199 748 return [ map { $_->[1] } grep { _lc($_->[0]) eq $key } @$fields ];
200 }
201  
202 191 ▶sub _connection_tokens {
Subroutine _connection_tokens: called CC=5 SCAR=16.1
203 191 my ($fields) = @_;
204 191 my %seen;
205 191 for my $value (@{ _values($fields, 'Connection') }) {
206 74 for my $member (split /,/, $value, -1) {
207 86 $member =~ s/\A[ \t]+//;
208 86 $member =~ s/[ \t]+\z//;
209 86 ▶ next unless length $member;
Branch: 1 branch
BranchTrueFalseTotal
unless length $member 0 86 86
210 86 ▶ croak 'invalid Connection option'
Branch: 1 branch
BranchTrueFalseTotal
unless $member =~ /\A[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]+\z/ 3 83 86
211 unless $member =~ /\A[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]+\z/;
212 83 $seen{ _lc($member) } = 1;
213 }
214 }
215 188 return \%seen;
216 }
217  
218 138 ▶sub _content_length {
Subroutine _content_length: called CC=10 SCAR=23.5
219 138 my ($fields) = @_;
220 138 my @numbers;
221 138 for my $value (@{ _values($fields, 'Content-Length') }) {
222 40 for my $member (split /,/, $value, -1) {
223 41 $member =~ s/\A[ \t]+//;
224 41 $member =~ s/[ \t]+\z//;
225 41 ▶ croak 'invalid Content-Length' unless $member =~ /\A[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $member =~ /\A[0-9]+\z/ 0 41 41
226  
227 # Compare decimal values, not their textual spelling. RFC 9112
228 # permits repeated or comma-combined values when every member has
229 # the same numeric value.
230 41 $member =~ s/\A0+(?=[0-9])//;
231  
232 41 ▶ croak 'Content-Length exceeds supported framing range'
Branch: 1 branch
BranchTrueFalseTotal
if length $member > length $MAX_CONTENT_LENGTH or length $member == length $MAX_CONTENT_LENGTH and $member gt $MAX_CONTENT_LENGTH 2 39 41
Condition50%3/6
length $member > length $MAX_CONTENT_LENGTH or length $member == length $MAX_CONTENT_LENGTH and $member gt $MAX_CONTENT_LENGTH
l!l&&r!l&&!r
2039
length $member == length $MAX_CONTENT_LENGTH and $member gt $MAX_CONTENT_LENGTH
!ll&&!rl&&r
3900
MC/DC33%1/3
length $member > length $MAX_CONTENT_LENGTH or length $member == length $MAX_CONTENT_LENGTH and $member gt $MAX_CONTENT_LENGTH
length $member > length $MAX_CONTENT_LENGTH length $member == length $MAX_CONTENT_LENGTH $member gt $MAX_CONTENT_LENGTH
Truth table50%2/4
A or B and C
A= length $member > length $MAX_CONTENT_LENGTHB= length $member == length $MAX_CONTENT_LENGTHC= $member gt $MAX_CONTENT_LENGTH
ABCresult
1XX1
0111
00X0
0100
233 if length($member) > length($MAX_CONTENT_LENGTH)
234 || (length($member) == length($MAX_CONTENT_LENGTH)
235 && $member gt $MAX_CONTENT_LENGTH);
236  
237 39 push @numbers, $member;
238 }
239 }
240 136 ▶ return undef unless @numbers;
Branch: 1 branch
BranchTrueFalseTotal
unless @numbers 99 37 136
241 37 my $first = $numbers[0];
242 37 for my $number (@numbers) {
243 39 ▶ croak 'conflicting Content-Length fields' if $number ne $first;
Branch: 1 branch
BranchTrueFalseTotal
if $number ne $first 0 39 39
244 }
245 37 return 0 + $first;
246 }
247  
248 23 ▶sub _transfer_encoding {
Subroutine _transfer_encoding: called CC=9 SCAR=38.8
249 23 my ($fields) = @_;
250 23 my @codings;
251 23 for my $value (@{ _values($fields, 'Transfer-Encoding') }) {
252 0 for my $member (split /,/, $value, -1) {
253 0 $member =~ s/\A[ \t]+//;
254 0 $member =~ s/[ \t]+\z//;
255 0 ▶ croak 'invalid Transfer-Encoding' unless length $member;
Branch: 1 branch
BranchTrueFalseTotal
unless length $member 0 0 0
256 0 my ($token, $tail) = $member =~ /\A([^; \t]+)(.*)\z/;
257 0 ▶ croak 'invalid Transfer-Encoding' unless defined $token;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $token 0 0 0
258 0 push @codings, [ _lc($token), $tail ];
259 }
260 }
261 23 ▶ return [] unless @codings;
Branch: 1 branch
BranchTrueFalseTotal
unless @codings 23 0 23
262 0 ▶ croak 'unsupported HTTP/1 transfer coding'
Branch: 1 branch
BranchTrueFalseTotal
if @codings != 1 or $codings[0][0] ne "chunked" or length $codings[0][1] 0 0 0
Condition0%0/6
@codings != 1 or $codings[0][0] ne "chunked" or length $codings[0][1]
l!l&&r!l&&!r
000
@codings != 1 or $codings[0][0] ne "chunked"
l!l&&r!l&&!r
000
MC/DC0%0/3
@codings != 1 or $codings[0][0] ne "chunked" or length $codings[0][1]
@codings != 1 $codings[0][0] ne "chunked" length $codings[0][1]
Truth table0%0/4
A or B or C
A= @codings != 1B= $codings[0][0] ne "chunked"C= length $codings[0][1]
ABCresult
1XX1
01X1
0011
0000
263 if @codings != 1 || $codings[0][0] ne 'chunked' || length($codings[0][1]);
264 0 return ['chunked'];
265 }
266  
267  
268 50 ▶sub _transfer_coding_token_end {
Subroutine _transfer_coding_token_end: called CC=4 SCAR=13.9
269 50 my ($value, $pos) = @_;
270 50 my $len = length $value;
271 50 my $start = $pos;
272 50 ▶ while ($pos < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < $len) 261 29 290
273 261 my $ch = substr($value, $pos, 1);
274 261 ▶ last unless $ch =~ /[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $ch =~ /[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]/ 21 240 261
275 240 ++$pos;
276 }
277 50 ▶ return $pos > $start ? $pos : undef;
Branch: 1 branch
BranchTrueFalseTotal
$pos > $start ? : 50 0 50
278 }
279  
280 31 ▶sub _parse_transfer_coding_member {
Subroutine _parse_transfer_coding_member: called CC=29 SCAR=37.8
281 31 my ($member) = @_;
282 31 $member = _trim($member);
283 31 ▶ croak 'invalid Transfer-Encoding' unless length $member;
Branch: 1 branch
BranchTrueFalseTotal
unless length $member 0 31 31
284  
285 31 my $len = length $member;
286 31 my $pos = 0;
287 31 my $end = _transfer_coding_token_end($member, $pos);
288 31 ▶ croak 'invalid Transfer-Encoding' unless defined $end;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $end 0 31 31
289 31 my $coding = _lc(substr($member, $pos, $end - $pos));
290 31 $pos = $end;
291 31 my $parameters = 0;
292  
293 31 while (1) {
294 41 ▶ ++$pos while $pos < $len && substr($member, $pos, 1) =~ /[ \t]/;
Branch: 1 branch
BranchTrueFalseTotal
$pos < $len and substr($member, $pos, 1) =~ /[ \t]/ and do { ++$pos } 0 41 41
Condition66%2/3
$pos < $len and substr($member, $pos, 1) =~ /[ \t]/
!ll&&!rl&&r
30110
MC/DC0%0/2
$pos < $len and substr($member, $pos, 1) =~ /[ \t]/
$pos < $len substr($member, $pos, 1) =~ /[ \t]/
Truth table66%2/3
A and B
A= $pos < $lenB= substr($member, $pos, 1) =~ /[ \t]/
ABresult
0X0
100
111
295 41 ▶ last if $pos == $len;
Branch: 1 branch
BranchTrueFalseTotal
if $pos == $len 30 11 41
296  
297 11 ▶ croak 'invalid Transfer-Encoding'
Branch: 1 branch
BranchTrueFalseTotal
unless substr($member, $pos, 1) eq ";" 0 11 11
298 unless substr($member, $pos, 1) eq ';';
299 11 ++$pos;
300 11 ▶ ++$pos while $pos < $len && substr($member, $pos, 1) =~ /[ \t]/;
Branch: 1 branch
BranchTrueFalseTotal
$pos < $len and substr($member, $pos, 1) =~ /[ \t]/ and do { ++$pos } 3 11 14
Condition66%2/3
$pos < $len and substr($member, $pos, 1) =~ /[ \t]/
!ll&&!rl&&r
0113
MC/DC50%1/2
$pos < $len and substr($member, $pos, 1) =~ /[ \t]/
$pos < $len substr($member, $pos, 1) =~ /[ \t]/
Truth table66%2/3
A and B
A= $pos < $lenB= substr($member, $pos, 1) =~ /[ \t]/
ABresult
0X0
100
111
301  
302 11 $end = _transfer_coding_token_end($member, $pos);
303 11 ▶ croak 'invalid Transfer-Encoding parameter' unless defined $end;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $end 0 11 11
304 11 $pos = $end;
305 11 ▶ ++$pos while $pos < $len && substr($member, $pos, 1) =~ /[ \t]/;
Branch: 1 branch
BranchTrueFalseTotal
$pos < $len and substr($member, $pos, 1) =~ /[ \t]/ and do { ++$pos } 0 11 11
Condition66%2/3
$pos < $len and substr($member, $pos, 1) =~ /[ \t]/
!ll&&!rl&&r
1100
MC/DC0%0/2
$pos < $len and substr($member, $pos, 1) =~ /[ \t]/
$pos < $len substr($member, $pos, 1) =~ /[ \t]/
Truth table66%2/3
A and B
A= $pos < $lenB= substr($member, $pos, 1) =~ /[ \t]/
ABresult
0X0
100
111
306  
307 11 ▶ croak 'invalid Transfer-Encoding parameter'
Branch: 1 branch
BranchTrueFalseTotal
unless $pos < $len and substr($member, $pos, 1) eq "=" 1 10 11
Condition66%2/3
$pos < $len and substr($member, $pos, 1) eq "="
!ll&&!rl&&r
1010
MC/DC50%1/2
$pos < $len and substr($member, $pos, 1) eq "="
$pos < $len substr($member, $pos, 1) eq "="
Truth table66%2/3
A and B
A= $pos < $lenB= substr($member, $pos, 1) eq "="
ABresult
0X0
100
111
308 unless $pos < $len && substr($member, $pos, 1) eq '=';
309 10 ++$pos;
310 10 ▶ ++$pos while $pos < $len && substr($member, $pos, 1) =~ /[ \t]/;
Branch: 1 branch
BranchTrueFalseTotal
$pos < $len and substr($member, $pos, 1) =~ /[ \t]/ and do { ++$pos } 0 10 10
Condition33%1/3
$pos < $len and substr($member, $pos, 1) =~ /[ \t]/
!ll&&!rl&&r
0100
MC/DC0%0/2
$pos < $len and substr($member, $pos, 1) =~ /[ \t]/
$pos < $len substr($member, $pos, 1) =~ /[ \t]/
Truth table33%1/3
A and B
A= $pos < $lenB= substr($member, $pos, 1) =~ /[ \t]/
ABresult
0X0
100
111
311 10 ▶ croak 'invalid Transfer-Encoding parameter' if $pos == $len;
Branch: 1 branch
BranchTrueFalseTotal
if $pos == $len 0 10 10
312  
313 10 ▶ if (substr($member, $pos, 1) eq '"') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($member, $pos, 1) eq '"') { } 2 8 10
314 2 ++$pos;
315 2 my $closed = 0;
316 2 ▶ while ($pos < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < $len) 8 0 8
317 8 my $ch = substr($member, $pos, 1);
318 8 ▶ if ($ch eq '"') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "\"") 2 6 8
319 2 ++$pos;
320 2 $closed = 1;
321 2 last;
322 }
323 6 ▶ if ($ch eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "\\") 0 6 6
324 0 ++$pos;
325 0 ▶ croak 'invalid Transfer-Encoding quoted parameter'
Branch: 1 branch
BranchTrueFalseTotal
if $pos == $len 0 0 0
326 if $pos == $len;
327 0 ++$pos;
328 0 next;
329 }
330 6 my $ord = ord($ch);
331 6 ▶ croak 'invalid Transfer-Encoding quoted parameter'
Branch: 1 branch
BranchTrueFalseTotal
if $ord < 32 and $ch ne "\t" or $ord == 127 0 6 6
Condition33%2/6
$ord < 32 and $ch ne "\t" or $ord == 127
l!l&&r!l&&!r
006
$ord < 32 and $ch ne "\t"
!ll&&!rl&&r
600
MC/DC0%0/3
$ord < 32 and $ch ne "\t" or $ord == 127
$ord < 32 $ch ne "\t" $ord == 127
Truth table20%1/5
A and B or C
A= $ord < 32B= $ch ne "\t"C= $ord == 127
ABCresult
11X1
0X11
1011
0X00
1000
332 if ($ord < 0x20 && $ch ne "\t") || $ord == 0x7f;
333 6 ++$pos;
334 }
335 2 ▶ croak 'unterminated Transfer-Encoding quoted parameter'
Branch: 1 branch
BranchTrueFalseTotal
unless $closed 0 2 2
336 unless $closed;
337 } else {
338 8 $end = _transfer_coding_token_end($member, $pos);
339 8 ▶ croak 'invalid Transfer-Encoding parameter value'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $end 0 8 8
340 unless defined $end;
341 8 $pos = $end;
342 }
343 10 ++$parameters;
344 }
345  
346 30 ▶ croak 'chunked transfer coding does not accept parameters'
Branch: 1 branch
BranchTrueFalseTotal
if $coding eq "chunked" and $parameters 1 29 30
Condition100%3/3
$coding eq "chunked" and $parameters
!ll&&!rl&&r
16131
MC/DC100%2/2
$coding eq "chunked" and $parameters
$coding eq "chunked" $parameters
Truth table100%3/3
A and B
A= $coding eq "chunked"B= $parameters
ABresult
0X0
100
111
347 if $coding eq 'chunked' && $parameters;
348 29 return $coding;
349 }
350  
351 37 ▶sub _split_quoted_delimiter {
Subroutine _split_quoted_delimiter: called CC=10 SCAR=24.3
352 37 my ($value, $delimiter, $label) = @_;
353 37 my @member;
354 37 my $start = 0;
355 37 my $quoted = 0;
356 37 my $escaped = 0;
357 37 my $len = length $value;
358  
359 37 for my $pos (0 .. $len - 1) {
360 400 my $ch = substr($value, $pos, 1);
361 400 ▶ if ($escaped) {
Branch: 1 branch
BranchTrueFalseTotal
if ($escaped) 0 400 400
362 0 $escaped = 0;
363 0 next;
364 }
365 400 ▶ if ($quoted && $ch eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if ($quoted and $ch eq "\\") 0 400 400
Condition66%2/3
$quoted and $ch eq "\\"
!ll&&!rl&&r
388120
MC/DC0%0/2
$quoted and $ch eq "\\"
$quoted $ch eq "\\"
Truth table66%2/3
A and B
A= $quotedB= $ch eq "\\"
ABresult
0X0
100
111
366 0 $escaped = 1;
367 0 next;
368 }
369 400 ▶ if ($ch eq '"') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "\"") 6 394 400
370 6 $quoted = !$quoted;
371 6 next;
372 }
373 394 ▶ next unless $ch eq $delimiter && !$quoted;
Branch: 1 branch
BranchTrueFalseTotal
unless $ch eq $delimiter and not $quoted 382 12 394
Condition100%3/3
$ch eq $delimiter and not $quoted
!ll&&!rl&&r
381112
MC/DC100%2/2
$ch eq $delimiter and not $quoted
$ch eq $delimiter not $quoted
Truth table100%3/3
A and not(B)
A= $ch eq $delimiterB= not $quoted
ABresult
0X0
100
111
374 12 push @member, substr($value, $start, $pos - $start);
375 12 $start = $pos + 1;
376 }
377  
378 37 ▶ croak "unterminated $label quoted parameter"
Branch: 1 branch
BranchTrueFalseTotal
if $quoted or $escaped 0 37 37
Condition33%1/3
$quoted or $escaped
l!l&&r!l&&!r
0037
MC/DC0%0/2
$quoted or $escaped
$quoted $escaped
Truth table33%1/3
A or B
A= $quotedB= $escaped
ABresult
1X1
011
000
379 if $quoted || $escaped;
380 37 push @member, substr($value, $start);
381 37 return @member;
382 }
383  
384 92 ▶sub _response_transfer_encoding {
Subroutine _response_transfer_encoding: called CC=3 SCAR=11.0
385 92 my ($fields) = @_;
386 92 my @coding;
387  
388 92 for my $value (@{ _values($fields, 'Transfer-Encoding') }) {
389 16 my @member = _split_quoted_delimiter(
390 $value, ',', 'Transfer-Encoding',
391 );
392 16 push @coding, map { scalar _parse_transfer_coding_member($_) } @member;
393 }
394  
395 90 my $chunked = grep { $_ eq 'chunked' } @coding;
396 90 ▶ croak 'chunked transfer coding must not be applied more than once'
Branch: 1 branch
BranchTrueFalseTotal
if $chunked > 1 1 89 90
397 if $chunked > 1;
398  
399 89 return \@coding;
400 }
401  
402  
403 4 ▶sub _qvalue_thousandths {
Subroutine _qvalue_thousandths: called CC=5 SCAR=16.2
404 4 my ($value) = @_;
405 4 $value = _trim($value);
406  
407 4 ▶ if ($value =~ /\A0(?:\.([0-9]{0,3}))?\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /\A0(?:\.([0-9]{0,3}))?\z/) 3 1 4
408 3 ▶ my $fraction = defined($1) ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 2 1 3
409 3 ▶ return 0 if $fraction eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $fraction eq "" 1 2 3
410 2 return 0 + ($fraction . ('0' x (3 - length($fraction))));
411 }
412 1 ▶ if ($value =~ /\A1(?:\.(0{0,3}))?\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /\A1(?:\.(0{0,3}))?\z/) 0 1 1
413 0 return 1000;
414 }
415 1 croak 'invalid TE qvalue';
416 }
417  
418 33 ▶sub _request_te_preferences {
Subroutine _request_te_preferences: called CC=17 SCAR=28.8
419 33 my ($fields) = @_;
420 33 my $values = _values($fields, 'TE');
421 33 my %quality;
422 33 my $trailers = 0;
423  
424 33 for my $value (@$values) {
425 12 ▶ next if _trim($value) eq '';
Branch: 1 branch
BranchTrueFalseTotal
if _trim($value) eq "" 0 12 12
426  
427 12 for my $member (_split_quoted_delimiter($value, ',', 'TE')) {
428 13 $member = _trim($member);
429 13 ▶ croak 'invalid TE field value' unless length $member;
Branch: 1 branch
BranchTrueFalseTotal
unless length $member 0 13 13
430  
431 13 ▶ if (_lc($member) eq 'trailers') {
Branch: 1 branch
BranchTrueFalseTotal
if (_lc($member) eq "trailers") 2 11 13
432 2 $trailers = 1;
433 2 next;
434 }
435  
436 11 my $coding = scalar _parse_transfer_coding_member($member);
437 11 ▶ croak 'TE must not list the chunked transfer coding'
Branch: 1 branch
BranchTrueFalseTotal
if $coding eq "chunked" 1 10 11
438 if $coding eq 'chunked';
439 10 ▶ croak 'trailers TE keyword must not have parameters'
Branch: 1 branch
BranchTrueFalseTotal
if $coding eq "trailers" 1 9 10
440 if $coding eq 'trailers';
441  
442 9 my @part = _split_quoted_delimiter($member, ';', 'TE');
443 9 shift @part;
444 9 my $rank = 1000;
445 9 my $seen_q = 0;
446  
447 9 for my $index (0 .. $#part) {
448 6 my $parameter = _trim($part[$index]);
449 6 my ($name, $value) = $parameter =~
450 /\A([!#\$%&'*+\-.^_\x60|~0-9A-Za-z]+)[ \t]*=[ \t]*(.+)\z/s;
451 6 ▶ croak 'invalid TE parameter' unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 6 6
452  
453 6 ▶ next unless _lc($name) eq 'q';
Branch: 1 branch
BranchTrueFalseTotal
unless _lc($name) eq "q" 0 6 6
454 6 ▶ croak 'TE qvalue must be the final parameter'
Branch: 1 branch
BranchTrueFalseTotal
if $index != $#part 1 5 6
455 if $index != $#part;
456 5 ▶ croak 'TE must not contain more than one qvalue'
Branch: 1 branch
BranchTrueFalseTotal
if $seen_q++ 0 5 5
457 if $seen_q++;
458 5 ▶ croak 'TE qvalue must not be quoted'
Branch: 1 branch
BranchTrueFalseTotal
if substr($value, 0, 1) eq "\"" 1 4 5
459 if substr($value, 0, 1) eq '"';
460 4 $rank = _qvalue_thousandths($value);
461 }
462  
463 $quality{$coding} = $rank
464 6 ▶ if !exists($quality{$coding}) || $rank > $quality{$coding};
Branch: 1 branch
BranchTrueFalseTotal
if not exists $quality{$coding} or $rank > $quality{$coding} 6 0 6
Condition33%1/3
not exists $quality{$coding} or $rank > $quality{$coding}
l!l&&r!l&&!r
600
MC/DC0%0/2
not exists $quality{$coding} or $rank > $quality{$coding}
not exists $quality{$coding} $rank > $quality{$coding}
Truth table33%1/3
not(A) or B
A= not exists $quality{$coding}B= $rank > $quality{$coding}
ABresult
1X1
011
000
465 }
466 }
467  
468 return {
469 28 ▶ present => @$values ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
@$values ? : 7 21 28
470 trailers => $trailers,
471 quality => \%quality,
472 };
473 }
474  
475 99 ▶sub _trim {
Subroutine _trim: called CC=1 SCAR=0.0
476 99 my ($value) = @_;
477 99 $value =~ s/\A[ \t]+//;
478 99 $value =~ s/[ \t]+\z//;
479 99 return $value;
480 }
481  
482 100 ▶sub _validate_host_value {
Subroutine _validate_host_value: called CC=6 SCAR=20.5
483 100 my ($value) = @_;
484 100 $value = _bytes('Host field', $value);
485 100 ▶ return 1 if $value eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "" 0 100 100
486  
487 100 ▶ croak 'invalid Host field'
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ m[[\x00-\x20\x7f/?#@]] 1 99 100
488 if $value =~ /[\x00-\x20\x7f\/?#@]/;
489  
490 99 ▶ if (substr($value, 0, 1) eq '[') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($value, 0, 1) eq "[") 0 99 99
491 0 ▶ croak 'invalid Host field'
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /\A\[[^\]]+\](?::[0-9]*)?\z/ 0 0 0
492 unless $value =~ /\A\[[^\]]+\](?::[0-9]*)?\z/;
493 0 return 1;
494 }
495  
496 99 ▶ croak 'invalid Host field'
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /\A[^:]+(?::[0-9]*)?\z/ 0 99 99
497 unless $value =~ /\A[^:]+(?::[0-9]*)?\z/;
498 99 return 1;
499 }
500  
501 15 ▶sub _authority_form {
Subroutine _authority_form: called CC=6 SCAR=18.8
502 15 my ($target) = @_;
503 15 $target = _bytes('CONNECT target', $target);
504  
505 15 my ($host, $port);
506 15 ▶ if ($target =~ /\A(\[[^\]\s]+\]):([0-9]+)\z/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($target =~ /\A(\[[^\]\s]+\]):([0-9]+)\z/) { } 0 15 15
elsif ($target =~ m[\A([^:\s/?#@]+):([0-9]+)\z]) { } 14 1 15
507 0 ($host, $port) = ($1, $2);
508 } elsif ($target =~ /\A([^:\s\/?#@]+):([0-9]+)\z/) {
509 14 ($host, $port) = ($1, $2);
510 } else {
511 1 croak 'CONNECT target must be an authority-form host:port';
512 }
513  
514 14 ▶ croak 'CONNECT target port must be between 1 and 65535'
Branch: 1 branch
BranchTrueFalseTotal
if $port < 1 or $port > 65535 0 14 14
Condition33%1/3
$port < 1 or $port > 65535
l!l&&r!l&&!r
0014
MC/DC0%0/2
$port < 1 or $port > 65535
$port < 1 $port > 65535
Truth table33%1/3
A or B
A= $port < 1B= $port > 65535
ABresult
1X1
011
000
515 if $port < 1 || $port > 65_535;
516 14 ▶ return wantarray ? ($host, 0 + $port) : "$host:$port";
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 7 7 14
517 }
518  
519 7 ▶sub _connect_host {
Subroutine _connect_host: called CC=9 SCAR=25.1
520 7 my ($value) = @_;
521 7 $value = _trim(_bytes('CONNECT Host', $value));
522  
523 7 my ($host, $port);
524 7 ▶ if ($value =~ /\A(\[[^\]\s]+\])(?::([0-9]*))?\z/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($value =~ /\A(\[[^\]\s]+\])(?::([0-9]*))?\z/) { } 0 7 7
elsif ($value =~ m[\A([^:\s/?#@]+)(?::([0-9]*))?\z]) { } 7 0 7
525 0 ($host, $port) = ($1, $2);
526 } elsif ($value =~ /\A([^:\s\/?#@]+)(?::([0-9]*))?\z/) {
527 7 ($host, $port) = ($1, $2);
528 } else {
529 0 croak 'CONNECT Host must contain a valid host with an optional port';
530 }
531  
532 7 ▶ $port = undef if defined($port) && $port eq '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $port and $port eq "" 0 7 7
Condition66%2/3
defined $port and $port eq ""
!ll&&!rl&&r
160
MC/DC0%0/2
defined $port and $port eq ""
defined $port $port eq ""
Truth table66%2/3
A and B
A= defined $portB= $port eq ""
ABresult
0X0
100
111
533 7 ▶ croak 'CONNECT Host port must be between 1 and 65535'
Branch: 1 branch
BranchTrueFalseTotal
if defined $port and $port < 1 || $port > 65535 0 7 7
Condition50%3/6
defined $port and $port < 1 || $port > 65535
!ll&&!rl&&r
160
$port < 1 or $port > 65535
l!l&&r!l&&!r
006
MC/DC0%0/3
defined $port and $port < 1 || $port > 65535
defined $port $port < 1 $port > 65535
Truth table50%2/4
A and B or C
A= defined $portB= $port < 1C= $port > 65535
ABCresult
0XX0
1000
11X1
1011
534 if defined($port) && ($port < 1 || $port > 65_535);
535 7 ▶ return ($host, defined($port) ? 0 + $port : undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $port ? : 6 1 7
536 }
537  
538 115 ▶sub _validate_request_target {
Subroutine _validate_request_target: called CC=8 SCAR=20.8
539 115 my ($method, $target) = @_;
540 115 $method = _method($method);
541 115 $target = _bytes('request target', $target);
542  
543 115 ▶ croak 'HTTP/1 request target must not contain whitespace or control bytes'
Branch: 1 branch
BranchTrueFalseTotal
if $target =~ /[\x00-\x20\x7f]/ 1 114 115
544 if $target =~ /[\x00-\x20\x7f]/;
545 114 ▶ croak 'HTTP/1 request target must not contain a fragment'
Branch: 1 branch
BranchTrueFalseTotal
if index($target, "#") != -1 1 113 114
546 if index($target, '#') >= 0;
547  
548 113 ▶ if ($target eq '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($target eq "*") 2 111 113
549 2 ▶ croak 'HTTP/1 asterisk request target is only valid for OPTIONS'
Branch: 1 branch
BranchTrueFalseTotal
unless $method eq "OPTIONS" 1 1 2
550 unless $method eq 'OPTIONS';
551 1 return $target;
552 }
553  
554 111 ▶ if ($method eq 'CONNECT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "CONNECT") 8 103 111
555 8 _authority_form($target);
556 7 return $target;
557 }
558  
559 103 ▶ return $target if substr($target, 0, 1) eq '/';
Branch: 1 branch
BranchTrueFalseTotal
if substr($target, 0, 1) eq "/" 92 11 103
560  
561 # absolute-form begins with a URI scheme. URI interpretation and proxy
562 # routing remain above this protocol engine; only the wire form is checked.
563 11 ▶ return $target
Branch: 1 branch
BranchTrueFalseTotal
if $target =~ /\A[A-Za-z][A-Za-z0-9+.-]*:[^#]*\z/ 10 1 11
564 if $target =~ /\A[A-Za-z][A-Za-z0-9+.-]*:[^#]*\z/;
565  
566 1 croak 'HTTP/1 request target must use origin-form, absolute-form, '
567 . 'CONNECT authority-form, or OPTIONS asterisk-form';
568 }
569  
570 110 ▶sub _absolute_form_host {
Subroutine _absolute_form_host: called CC=12 SCAR=26.0
571 110 my ($method, $target) = @_;
572 110 ▶ return (0, undef) if $method eq 'CONNECT';
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "CONNECT" 7 103 110
573 103 ▶ return (0, undef)
Branch: 1 branch
BranchTrueFalseTotal
unless $target =~ /\A([A-Za-z][A-Za-z0-9+.-]*):(.*)\z/s 93 10 103
574 unless $target =~ /\A([A-Za-z][A-Za-z0-9+.-]*):(.*)\z/s;
575  
576 10 my $scheme = _lc($1);
577 10 my $rest = $2;
578  
579 10 ▶ if (($scheme eq 'http' || $scheme eq 'https')
Branch: 1 branch
BranchTrueFalseTotal
if ($scheme eq "http" || $scheme eq "https" and substr($rest, 0, 2) ne "//") 1 9 10
Condition50%3/6
$scheme eq "http" || $scheme eq "https" and substr($rest, 0, 2) ne "//"
!ll&&!rl&&r
091
$scheme eq "http" or $scheme eq "https"
l!l&&r!l&&!r
1000
MC/DC33%1/3
$scheme eq "http" || $scheme eq "https" and substr($rest, 0, 2) ne "//"
$scheme eq "http" $scheme eq "https" substr($rest, 0, 2) ne "//"
Truth table40%2/5
A or B and C
A= $scheme eq "http"B= $scheme eq "https"C= substr($rest, 0, 2) ne "//"
ABCresult
00X0
1X00
0100
1X11
0111
580 && substr($rest, 0, 2) ne '//') {
581 1 croak 'http(s) absolute-form request target requires an authority';
582 }
583  
584 # Other absolute URI schemes can legitimately omit authority. In that
585 # case HTTP/1.1 still carries an empty Host field.
586 9 ▶ return (1, '') unless substr($rest, 0, 2) eq '//';
Branch: 1 branch
BranchTrueFalseTotal
unless substr($rest, 0, 2) eq "//" 0 9 9
587  
588 9 my $authority = substr($rest, 2);
589 9 $authority =~ s{[/?].*\z}{}s;
590  
591 9 ▶ if ($scheme eq 'http' || $scheme eq 'https') {
Branch: 1 branch
BranchTrueFalseTotal
if ($scheme eq "http" or $scheme eq "https") 9 0 9
Condition33%1/3
$scheme eq "http" or $scheme eq "https"
l!l&&r!l&&!r
900
MC/DC0%0/2
$scheme eq "http" or $scheme eq "https"
$scheme eq "http" $scheme eq "https"
Truth table33%1/3
A or B
A= $scheme eq "http"B= $scheme eq "https"
ABresult
1X1
011
000
592 9 ▶ croak 'http(s) absolute-form request target requires a non-empty authority'
Branch: 1 branch
BranchTrueFalseTotal
if $authority eq "" 0 9 9
593 if $authority eq '';
594 9 ▶ croak 'http(s) absolute-form request target requires a non-empty host'
Branch: 1 branch
BranchTrueFalseTotal
if substr($authority, 0, 1) eq ":" 0 9 9
595 if substr($authority, 0, 1) eq ':';
596 9 ▶ croak 'http(s) absolute-form request target must not contain userinfo'
Branch: 1 branch
BranchTrueFalseTotal
if index($authority, "\@") != -1 1 8 9
597 if index($authority, '@') >= 0;
598 }
599  
600 # Generic URI schemes can carry userinfo. Host excludes it.
601 8 $authority =~ s/\A.*@//s;
602 8 return (1, $authority);
603 }
604  
605 69 ▶sub _received_request_metadata {
Subroutine _received_request_metadata: called CC=7 SCAR=29.6
606 69 my ($method, $target) = @_;
607 69 $method = _method($method);
608 69 $target = _bytes('request target', $target);
609  
610 69 ▶ if ($method eq 'CONNECT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "CONNECT") 2 67 69
611 2 return (authority => $target);
612 }
613  
614 67 ▶ return () if substr($target, 0, 1) eq '/' || $target eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if substr($target, 0, 1) eq "/" or $target eq "*" 67 0 67
Condition33%1/3
substr($target, 0, 1) eq "/" or $target eq "*"
l!l&&r!l&&!r
6700
MC/DC0%0/2
substr($target, 0, 1) eq "/" or $target eq "*"
substr($target, 0, 1) eq "/" $target eq "*"
Truth table33%1/3
A or B
A= substr($target, 0, 1) eq "/"B= $target eq "*"
ABresult
1X1
011
000
615  
616 0 ▶ return () unless $target =~ /\A([A-Za-z][A-Za-z0-9+.-]*):(.*)\z/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $target =~ /\A([A-Za-z][A-Za-z0-9+.-]*):(.*)\z/s 0 0 0
617 0 my ($scheme, $rest) = ($1, $2);
618 0 my @metadata = (scheme => $scheme);
619  
620 0 ▶ if (substr($rest, 0, 2) eq '//') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($rest, 0, 2) eq "//") 0 0 0
621 0 my $authority = substr($rest, 2);
622 0 $authority =~ s{[/?].*\z}{}s;
623 0 ▶ push @metadata, authority => $authority if length $authority;
Branch: 1 branch
BranchTrueFalseTotal
if length $authority 0 0 0
624 }
625  
626 0 return @metadata;
627 }
628  
629 25 ▶sub _upgrade_tokens {
Subroutine _upgrade_tokens: called CC=5 SCAR=16.6
630 25 my ($where, $fields) = @_;
631 25 my @token;
632 25 for my $value (@{ _values($fields, 'Upgrade') }) {
633 25 for my $member (split /,/, $value, -1) {
634 25 $member = _trim($member);
635 25 ▶ croak "invalid $where Upgrade field value"
Branch: 1 branch
BranchTrueFalseTotal
if $member eq "" or not $member =~ m[\A[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]+(?:/[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]+)?\z] 0 25 25
Condition33%1/3
$member eq "" or not $member =~ m[\A[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]+(?:/[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]+)?\z]
l!l&&r!l&&!r
0025
MC/DC0%0/2
$member eq "" or not $member =~ m[\A[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]+(?:/[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]+)?\z]
$member eq "" not $member =~ m[\A[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]+(?:/[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]+)?\z]
Truth table33%1/3
A or not(B)
A= $member eq ""B= not $member =~ m[\A[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]+(?:/[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]+)?\z]
ABresult
1X1
011
000
636 if $member eq ''
637 || $member !~ /\A[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]+(?:\/[!#\$%&'*+\-.^_\x60|~0-9A-Za-z]+)?\z/;
638 25 push @token, _lc($member);
639 }
640 }
641 25 return \@token;
642 }
643  
644 25 ▶sub _validate_connect_request {
Subroutine _validate_connect_request: called CC=16 SCAR=29.1
645 25 my ($request, $fields, $version, $body, $stream_body, $trailers, $view) = @_;
646 25 ▶ my $method = $view
Branch: 1 branch
BranchTrueFalseTotal
$view ? : 25 0 25
647 ? $view->[Uniform::HTTP::FastPath::SLOT_METHOD()]
648 : $request->method;
649 25 ▶ return unless $method eq 'CONNECT';
Branch: 1 branch
BranchTrueFalseTotal
unless $method eq "CONNECT" 16 9 25
650  
651 9 ▶ croak 'CONNECT requires HTTP/1.1 semantics'
Branch: 1 branch
BranchTrueFalseTotal
unless _semantics_version($version) eq "1.1" 0 9 9
652 unless _semantics_version($version) eq '1.1';
653 9 ▶ croak 'CONNECT cannot use a streaming request body' if $stream_body;
Branch: 1 branch
BranchTrueFalseTotal
if $stream_body 0 9 9
654 9 ▶ croak 'CONNECT request must not contain a buffered body' if defined $body;
Branch: 1 branch
BranchTrueFalseTotal
if defined $body 1 8 9
655 8 ▶ croak 'CONNECT request must not contain trailers' if $trailers && @$trailers;
Branch: 1 branch
BranchTrueFalseTotal
if $trailers and @$trailers 0 8 8
Condition33%1/3
$trailers and @$trailers
!ll&&!rl&&r
080
MC/DC0%0/2
$trailers and @$trailers
$trailers @$trailers
Truth table33%1/3
A and B
A= $trailersB= @$trailers
ABresult
0X0
100
111
656 8 my $connect_cl = _content_length($fields);
657 8 ▶ croak 'CONNECT request Content-Length must be zero when present'
Branch: 1 branch
BranchTrueFalseTotal
if defined $connect_cl and $connect_cl != 0 1 7 8
Condition100%3/3
defined $connect_cl and $connect_cl != 0
!ll&&!rl&&r
611
MC/DC100%2/2
defined $connect_cl and $connect_cl != 0
defined $connect_cl $connect_cl != 0
Truth table100%3/3
A and B
A= defined $connect_clB= $connect_cl != 0
ABresult
0X0
100
111
658 if defined($connect_cl) && $connect_cl != 0;
659 croak 'CONNECT request must not contain Transfer-Encoding'
660 7 ▶ if @{ _values($fields, 'Transfer-Encoding') };
Branch: 1 branch
BranchTrueFalseTotal
if @{_values($fields, "Transfer-Encoding");} 0 7 7
661  
662 7 ▶ my $target = $view
Branch: 1 branch
BranchTrueFalseTotal
$view ? : 7 0 7
663 ? $view->[Uniform::HTTP::FastPath::SLOT_TARGET()]
664 : $request->target;
665 7 my ($target_host, $target_port) = _authority_form($target);
666 7 my $host = _values($fields, 'Host');
667 7 ▶ croak 'CONNECT requires exactly one Host field' unless @$host == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$host == 1 0 7 7
668  
669 7 my ($host_name, $host_port) = _connect_host($host->[0]);
670 7 ▶ croak 'CONNECT Host must identify the authority-form request target'
Branch: 1 branch
BranchTrueFalseTotal
if _lc($host_name) ne _lc($target_host) or defined $host_port and $host_port != $target_port 1 6 7
Condition66%4/6
_lc($host_name) ne _lc($target_host) or defined $host_port and $host_port != $target_port
l!l&&r!l&&!r
106
defined $host_port and $host_port != $target_port
!ll&&!rl&&r
150
MC/DC33%1/3
_lc($host_name) ne _lc($target_host) or defined $host_port and $host_port != $target_port
_lc($host_name) ne _lc($target_host) defined $host_port $host_port != $target_port
Truth table75%3/4
A or B and C
A= _lc($host_name) ne _lc($target_host)B= defined $host_portC= $host_port != $target_port
ABCresult
1XX1
0111
00X0
0100
671 if _lc($host_name) ne _lc($target_host)
672 || (defined($host_port) && $host_port != $target_port);
673 6 return;
674 }
675  
676 13 ▶sub _validate_upgrade_request {
Subroutine _validate_upgrade_request: called CC=15 SCAR=29.9
677 13 my ($request, $fields, $version, $view) = @_;
678 13 ▶ croak 'HTTP/1 Upgrade requires HTTP/1.1 semantics'
Branch: 1 branch
BranchTrueFalseTotal
unless _semantics_version($version) eq "1.1" 0 13 13
679 unless _semantics_version($version) eq '1.1';
680  
681 13 my $connection = _connection_tokens($fields);
682 croak 'HTTP/1 Upgrade request requires Connection: Upgrade'
683 13 ▶ unless $connection->{upgrade};
Branch: 1 branch
BranchTrueFalseTotal
unless $connection->{"upgrade"} 0 13 13
684 croak 'HTTP/1 Upgrade request cannot combine Connection: close with Upgrade'
685 13 ▶ if $connection->{close};
Branch: 1 branch
BranchTrueFalseTotal
if $connection->{"close"} 0 13 13
686  
687 13 my $offered = _upgrade_tokens('request', $fields);
688 13 ▶ croak 'HTTP/1 Upgrade request requires an Upgrade field' unless @$offered;
Branch: 1 branch
BranchTrueFalseTotal
unless @$offered 0 13 13
689  
690 13 my $cl = _content_length($fields);
691 13 ▶ croak 'HTTP/1 Upgrade request body must be empty'
Branch: 1 branch
BranchTrueFalseTotal
if defined $cl and $cl != 0 1 12 13
Condition66%2/3
defined $cl and $cl != 0
!ll&&!rl&&r
1201
MC/DC50%1/2
defined $cl and $cl != 0
defined $cl $cl != 0
Truth table66%2/3
A and B
A= defined $clB= $cl != 0
ABresult
0X0
100
111
692 if defined($cl) && $cl != 0;
693 croak 'HTTP/1 Upgrade request cannot use Transfer-Encoding'
694 12 ▶ if @{ _values($fields, 'Transfer-Encoding') };
Branch: 1 branch
BranchTrueFalseTotal
if @{_values($fields, "Transfer-Encoding");} 0 12 12
695  
696 12 my ($has_body, $body);
697 12 ▶ if ($view) {
Branch: 1 branch
BranchTrueFalseTotal
if ($view) { } 12 0 12
698 12 ▶ $has_body =
Branch: 1 branch
BranchTrueFalseTotal
$view->[2] & 1 ? : 8 4 12
699 $view->[Uniform::HTTP::FastPath::SLOT_FLAGS()]
700 & Uniform::HTTP::FastPath::FLAG_HAS_BUFFERED_BODY() ? 1 : 0;
701 12 ▶ $body = $view->[Uniform::HTTP::FastPath::SLOT_BODY()] if $has_body;
Branch: 1 branch
BranchTrueFalseTotal
if $has_body 8 4 12
702 } else {
703 0 $has_body = $request->has_buffered_body;
704 0 ▶ $body = $request->body if $has_body;
Branch: 1 branch
BranchTrueFalseTotal
if $has_body 0 0 0
705 }
706 12 ▶ croak 'HTTP/1 Upgrade request body must be empty'
Branch: 1 branch
BranchTrueFalseTotal
if $has_body and defined $body and length $body 0 12 12
Condition66%4/6
$has_body and defined $body and length $body
!ll&&!rl&&r
480
$has_body and defined $body
!ll&&!rl&&r
408
MC/DC0%0/3
$has_body and defined $body and length $body
$has_body defined $body length $body
Truth table50%2/4
A and B and C
A= $has_bodyB= defined $bodyC= length $body
ABCresult
0XX0
10X0
1100
1111
707 if $has_body && defined($body) && length($body);
708 12 return $offered;
709 }
710  
711 13 ▶sub _validate_upgrade_response {
Subroutine _validate_upgrade_response: called CC=11 SCAR=24.8
712 13 my ($request, $request_fields, $response_fields, $response_version, $request_view) = @_;
713 13 ▶ croak 'HTTP/1 Upgrade response must use HTTP/1.1 semantics'
Branch: 1 branch
BranchTrueFalseTotal
unless _semantics_version($response_version) eq "1.1" 0 13 13
714 unless _semantics_version($response_version) eq '1.1';
715  
716 13 ▶ my $request_version = $request_view
Branch: 1 branch
BranchTrueFalseTotal
$request_view ? : 13 0 13
717 ? $request_view->[Uniform::HTTP::FastPath::SLOT_VERSION()]
718 : $request->version;
719 13 ▶ my $offered = _validate_upgrade_request(
Condition100%2/2
$request_version || '1.1'
l!l
94
MC/DC100%1/1
$request_version || '1.1'
$request_version
Truth table100%2/2
A
A= $request_version
Aresult
11
00
720 $request, $request_fields, $request_version || '1.1', $request_view,
721 );
722  
723 croak 'HTTP/1 Upgrade response cannot contain Content-Length'
724 12 ▶ if @{ _values($response_fields, 'Content-Length') };
Branch: 1 branch
BranchTrueFalseTotal
if @{_values($response_fields, "Content-Length");} 0 12 12
725 croak 'HTTP/1 Upgrade response cannot contain Transfer-Encoding'
726 12 ▶ if @{ _values($response_fields, 'Transfer-Encoding') };
Branch: 1 branch
BranchTrueFalseTotal
if @{_values($response_fields, "Transfer-Encoding");} 0 12 12
727  
728 12 my $connection = _connection_tokens($response_fields);
729 croak 'HTTP/1 Upgrade response requires Connection: Upgrade'
730 12 ▶ unless $connection->{upgrade};
Branch: 1 branch
BranchTrueFalseTotal
unless $connection->{"upgrade"} 0 12 12
731 croak 'HTTP/1 Upgrade response cannot combine Connection: close with Upgrade'
732 12 ▶ if $connection->{close};
Branch: 1 branch
BranchTrueFalseTotal
if $connection->{"close"} 0 12 12
733  
734 12 my $selected = _upgrade_tokens('response', $response_fields);
735 12 ▶ croak 'HTTP/1 Upgrade response must select a protocol' unless @$selected;
Branch: 1 branch
BranchTrueFalseTotal
unless @$selected 0 12 12
736 12 my %offered = map { $_ => 1 } @$offered;
737 12 for my $protocol (@$selected) {
738 croak "HTTP/1 Upgrade response selected protocol not offered by request: $protocol"
739 12 ▶ unless $offered{$protocol};
Branch: 1 branch
BranchTrueFalseTotal
unless $offered{$protocol} 2 10 12
740 }
741 10 return;
742 }
743  
744 1 ▶sub _replace_or_add {
Subroutine _replace_or_add: called CC=5 SCAR=19.3
745 1 my ($fields, $name, $value) = @_;
746 1 my $key = _lc($name);
747 1 my @out;
748 1 my $inserted = 0;
749 1 for my $field (@$fields) {
750 2 ▶ if (_lc($field->[0]) eq $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (_lc($field->[0]) eq $key) 0 2 2
751 0 ▶ if (!$inserted) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($inserted) 0 0 0
752 0 push @out, [ $name, "$value" ];
753 0 $inserted = 1;
754 }
755 0 next;
756 }
757 2 push @out, [ @$field ];
758 }
759 1 ▶ push @out, [ $name, "$value" ] unless $inserted;
Branch: 1 branch
BranchTrueFalseTotal
unless $inserted 1 0 1
760 1 return \@out;
761 }
762  
763 0 ▶sub _append_transfer_coding {
Subroutine _append_transfer_coding: not called CC=3 SCAR=24.8
764 0 my ($fields, $coding) = @_;
765 0 my @out = map { [ @$_ ] } @$fields;
766  
767 0 ▶ for (my $i = $#out; $i >= 0; --$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 0 0 0
768 0 ▶ next unless _lc($out[$i][0]) eq 'transfer-encoding';
Branch: 1 branch
BranchTrueFalseTotal
unless _lc($out[$i][0]) eq "transfer-encoding" 0 0 0
769 0 $out[$i][1] .= ', ' . $coding;
770 0 return \@out;
771 }
772  
773 0 push @out, [ 'Transfer-Encoding', $coding ];
774 0 return \@out;
775 }
776  
777 2 ▶sub _ensure_trailer_header {
Subroutine _ensure_trailer_header: called CC=12 SCAR=32.3
778 2 my ($fields, $trailers) = @_;
779 2 ▶ return $fields unless $trailers && @$trailers;
Branch: 1 branch
BranchTrueFalseTotal
unless $trailers and @$trailers 0 2 2
Condition33%1/3
$trailers and @$trailers
!ll&&!rl&&r
002
MC/DC0%0/2
$trailers and @$trailers
$trailers @$trailers
Truth table33%1/3
A and B
A= $trailersB= @$trailers
ABresult
0X0
100
111
780  
781 2 my @out = map { [ @$_ ] } @$fields;
782 2 my %announced;
783 my $last_trailer_field;
784  
785 2 for my $index (0 .. $#out) {
786 1 ▶ next unless _lc($out[$index][0]) eq 'trailer';
Branch: 1 branch
BranchTrueFalseTotal
unless _lc($out[$index][0]) eq "trailer" 1 0 1
787 0 $last_trailer_field = $index;
788  
789 0 for my $name (split /,/, $out[$index][1], -1) {
790 0 $name = _trim($name);
791 0 ▶ next unless length $name;
Branch: 1 branch
BranchTrueFalseTotal
unless length $name 0 0 0
792 0 $name = _field_name('Trailer', $name);
793 0 $announced{ _lc($name) } = 1;
794 }
795 }
796  
797 2 my @missing;
798 2 for my $field (@$trailers) {
799 2 my $name = _field_name('trailer', $field->[0]);
800 2 my $key = _lc($name);
801 2 ▶ next if $announced{$key}++;
Branch: 1 branch
BranchTrueFalseTotal
if $announced{$key}++ 0 2 2
802 2 push @missing, $name;
803 }
804  
805 2 ▶ return \@out unless @missing;
Branch: 1 branch
BranchTrueFalseTotal
unless @missing 0 2 2
806  
807 2 ▶ if (defined $last_trailer_field) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_trailer_field) { } 0 2 2
808 0 my $value = _trim($out[$last_trailer_field][1]);
809 0 ▶ $out[$last_trailer_field][1] =
Branch: 1 branch
BranchTrueFalseTotal
length $value ? : 0 0 0
810 length($value)
811 ? $value . ', ' . join(', ', @missing)
812 : join(', ', @missing);
813 } else {
814 2 push @out, [ 'Trailer', join(', ', @missing) ];
815 }
816  
817 2 return \@out;
818 }
819  
820 2 ▶sub _append_connection_token {
Subroutine _append_connection_token: called CC=4 SCAR=13.9
821 2 my ($fields, $token) = @_;
822 2 my @out = map { [ @$_ ] } @$fields;
823  
824 2 ▶ for (my $i = $#out; $i >= 0; --$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 4 1 5
825 4 ▶ next unless _lc($out[$i][0]) eq 'connection';
Branch: 1 branch
BranchTrueFalseTotal
unless _lc($out[$i][0]) eq "connection" 3 1 4
826 1 ▶ if (length _trim($out[$i][1])) {
Branch: 1 branch
BranchTrueFalseTotal
if (length _trim($out[$i][1])) { } 1 0 1
827 1 $out[$i][1] .= ', ' . $token;
828 } else {
829 0 $out[$i][1] = $token;
830 }
831 1 return \@out;
832 }
833  
834 1 push @out, [ 'Connection', $token ];
835 1 return \@out;
836 }
837  
838 57 ▶sub _serialize_fields {
Subroutine _serialize_fields: called CC=2 SCAR=6.9
839 57 my ($fields) = @_;
840 57 my $wire = '';
841 57 for my $field (@$fields) {
842 88 $wire .= $field->[0] . ': ' . $field->[1] . "\r\n";
843 }
844 57 return $wire;
845 }
846  
847 134 ▶sub _semantics_version {
Subroutine _semantics_version: called CC=3 SCAR=11.4
848 134 my ($version) = @_;
849 134 ▶ return '1.0' if $version eq '1.0';
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "1.0" 7 127 134
850 127 ▶ return '1.1' if $version =~ /\A1\.[1-9]\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $version =~ /\A1\.[1-9]\z/ 127 0 127
851 0 croak 'unsupported HTTP/1 version';
852 }
853  
854 0 ▶sub _version {
Subroutine _version: not called CC=4 SCAR=30.0
855 0 my ($message, $default) = @_;
856 0 my $version = $message->version;
857 0 ▶ $version = $default unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 0 0 0
858 0 ▶ croak 'HTTP/1 version must be 1.0 or 1.1'
Branch: 1 branch
BranchTrueFalseTotal
unless $version eq "1.0" or $version eq "1.1" 0 0 0
Condition0%0/3
$version eq "1.0" or $version eq "1.1"
l!l&&r!l&&!r
000
MC/DC0%0/2
$version eq "1.0" or $version eq "1.1"
$version eq "1.0" $version eq "1.1"
Truth table0%0/3
A or B
A= $version eq "1.0"B= $version eq "1.1"
ABresult
1X1
011
000
859 unless $version eq '1.0' || $version eq '1.1';
860 0 return $version;
861 }
862  
863 100 ▶sub _simple_request_plan {
Subroutine _simple_request_plan: called CC=45 SCAR=40.9
864 100 my ($request, $stream_body, $view) = @_;
865 100 ▶ return if $stream_body;
Branch: 1 branch
BranchTrueFalseTotal
if $stream_body 5 95 100
866  
867 95 ▶ my $version = $view
Branch: 1 branch
BranchTrueFalseTotal
$view ? : 90 5 95
868 ? $view->[Uniform::HTTP::FastPath::SLOT_VERSION()]
869 : $request->version;
870 95 ▶ $version = '1.1' unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 90 5 95
871 95 ▶ return unless $version eq '1.1';
Branch: 1 branch
BranchTrueFalseTotal
unless $version eq "1.1" 1 94 95
872  
873 94 ▶ my $method = $view
Branch: 1 branch
BranchTrueFalseTotal
$view ? : 89 5 94
874 ? $view->[Uniform::HTTP::FastPath::SLOT_METHOD()]
875 : _method($request->method);
876 93 ▶ return if $method eq 'CONNECT';
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "CONNECT" 8 85 93
877  
878 85 ▶ if ($view) {
Branch: 2 branches
BranchTrueFalseTotal
if ($view) { } 81 4 85
elsif ($request->can('protocol')) { } 4 0 4
879 81 ▶ return if defined $view->[Uniform::HTTP::FastPath::SLOT_PROTOCOL()];
Branch: 1 branch
BranchTrueFalseTotal
if defined $view->[8] 0 81 81
880 } elsif ($request->can('protocol')) {
881 4 ▶ return if defined $request->protocol;
Branch: 1 branch
BranchTrueFalseTotal
if defined $request->protocol 0 4 4
882 }
883  
884 85 my $body;
885 85 ▶ if ($view) {
Branch: 1 branch
BranchTrueFalseTotal
if ($view) { } 81 4 85
886 81 ▶ if ($view->[Uniform::HTTP::FastPath::SLOT_FLAGS()]
Branch: 1 branch
BranchTrueFalseTotal
if ($view->[2] & 1) 5 76 81
887 & Uniform::HTTP::FastPath::FLAG_HAS_BUFFERED_BODY()) {
888 5 $body = $view->[Uniform::HTTP::FastPath::SLOT_BODY()];
889 }
890 } else {
891 4 ▶ $body = $request->has_buffered_body
Branch: 1 branch
BranchTrueFalseTotal
$request->has_buffered_body ? : 0 4 4
892 ? _bytes('request body', $request->body)
893 : undef;
894 }
895  
896 my $trailer_count = $view
897 85 ▶ ? scalar @{ $view->[Uniform::HTTP::FastPath::SLOT_TRAILERS()] }
Branch: 1 branch
BranchTrueFalseTotal
$view ? : 81 4 85
898 : $request->trailer_count;
899 85 ▶ return unless defined($trailer_count) && $trailer_count == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $trailer_count and $trailer_count == 0 1 84 85
Condition66%2/3
defined $trailer_count and $trailer_count == 0
!ll&&!rl&&r
0184
MC/DC50%1/2
defined $trailer_count and $trailer_count == 0
defined $trailer_count $trailer_count == 0
Truth table66%2/3
A and B
A= defined $trailer_countB= $trailer_count == 0
ABresult
0X0
100
111
900  
901 84 ▶ my $target = $view
Branch: 1 branch
BranchTrueFalseTotal
$view ? : 80 4 84
902 ? $view->[Uniform::HTTP::FastPath::SLOT_TARGET()]
903 : _bytes('request target', $request->target);
904 84 _validate_request_target($method, $target);
905 80 my ($absolute_form) = _absolute_form_host($method, $target);
906 78 ▶ return if $absolute_form;
Branch: 1 branch
BranchTrueFalseTotal
if $absolute_form 4 74 78
907  
908 74 my $wire = $method . ' ' . $target . " HTTP/1.1\r\n";
909 74 my $host_count = 0;
910  
911 74 ▶ if ($view) {
Branch: 1 branch
BranchTrueFalseTotal
if ($view) { } 71 3 74
912 71 for my $field (@{ $view->[Uniform::HTTP::FastPath::SLOT_HEADERS()] }) {
913 70 my ($name, $value) = @$field;
914 70 my $key = _lc($name);
915  
916 70 ▶ if ($key eq 'host') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "host") 55 15 70
917 55 ++$host_count;
918 55 _validate_host_value($value);
919 }
920  
921 69 ▶ return if $key eq 'content-length'
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection" or $key eq "upgrade" or $key eq "expect" or $key eq "te" 12 57 69
Condition66%10/15
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection" or $key eq "upgrade" or $key eq "expect" or $key eq "te"
l!l&&r!l&&!r
6657
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection" or $key eq "upgrade" or $key eq "expect"
l!l&&r!l&&!r
6063
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection" or $key eq "upgrade"
l!l&&r!l&&!r
6063
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection"
l!l&&r!l&&!r
0663
$key eq "content-length" or $key eq "transfer-encoding"
l!l&&r!l&&!r
0069
MC/DC33%2/6
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection" or $key eq "upgrade" or $key eq "expect" or $key eq "te"
$key eq "content-length" $key eq "transfer-encoding" $key eq "connection" $key eq "upgrade" $key eq "expect" $key eq "te"
Truth table42%3/7
A or B or C or D or E or F
A= $key eq "content-length"B= $key eq "transfer-encoding"C= $key eq "connection"D= $key eq "upgrade"E= $key eq "expect"F= $key eq "te"
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
922 || $key eq 'transfer-encoding'
923 || $key eq 'connection'
924 || $key eq 'upgrade'
925 || $key eq 'expect'
926 || $key eq 'te';
927  
928 57 $wire .= $name . ': ' . $value . "\r\n";
929 }
930 } else {
931 3 my $count = $request->header_count;
932 3 ▶ return unless defined $count;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $count 0 3 3
933 3 for my $index (0 .. $count - 1) {
934 5 my $name = _field_name('header', $request->header_name($index));
935 4 my $value = _field_value('header', $request->header_value($index));
936 3 my $key = _lc($name);
937  
938 3 ▶ if ($key eq 'host') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "host") 3 0 3
939 3 ++$host_count;
940 3 _validate_host_value($value);
941 }
942  
943 3 ▶ return if $key eq 'content-length'
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection" or $key eq "upgrade" or $key eq "expect" or $key eq "te" 0 3 3
Condition33%5/15
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection" or $key eq "upgrade" or $key eq "expect" or $key eq "te"
l!l&&r!l&&!r
003
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection" or $key eq "upgrade" or $key eq "expect"
l!l&&r!l&&!r
003
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection" or $key eq "upgrade"
l!l&&r!l&&!r
003
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection"
l!l&&r!l&&!r
003
$key eq "content-length" or $key eq "transfer-encoding"
l!l&&r!l&&!r
003
MC/DC0%0/6
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection" or $key eq "upgrade" or $key eq "expect" or $key eq "te"
$key eq "content-length" $key eq "transfer-encoding" $key eq "connection" $key eq "upgrade" $key eq "expect" $key eq "te"
Truth table14%1/7
A or B or C or D or E or F
A= $key eq "content-length"B= $key eq "transfer-encoding"C= $key eq "connection"D= $key eq "upgrade"E= $key eq "expect"F= $key eq "te"
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
944 || $key eq 'transfer-encoding'
945 || $key eq 'connection'
946 || $key eq 'upgrade'
947 || $key eq 'expect'
948 || $key eq 'te';
949  
950 3 $wire .= $name . ': ' . $value . "\r\n";
951 }
952 }
953  
954 59 ▶ return if $host_count > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $host_count > 1 0 59 59
955  
956 59 ▶ if (!$host_count) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($host_count) 14 45 59
957 14 my $authority;
958 14 ▶ if ($view) {
Branch: 1 branch
BranchTrueFalseTotal
if ($view) { } 14 0 14
959 14 $authority = $view->[Uniform::HTTP::FastPath::SLOT_AUTHORITY()];
960 } else {
961 0 ▶ return unless $request->can('authority');
Branch: 1 branch
BranchTrueFalseTotal
unless $request->can("authority") 0 0 0
962 0 $authority = $request->authority;
963 }
964 14 ▶ return unless defined $authority;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $authority 0 14 14
965 14 ▶ $authority = _bytes('request authority', $authority) unless $view;
Branch: 1 branch
BranchTrueFalseTotal
unless $view 0 14 14
966 14 _validate_host_value($authority);
967 14 $wire .= 'Host: ' . $authority . "\r\n";
968 }
969  
970 59 my $mode = 'none';
971 59 my $remaining;
972 59 ▶ if (defined $body) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $body) 4 55 59
973 4 my $length = length($body);
974 4 $wire .= 'Content-Length: ' . $length . "\r\n";
975 4 $mode = 'content-length';
976 4 $remaining = 0;
977 }
978  
979 59 $wire .= "\r\n";
980 59 ▶ $wire .= $body if defined $body;
Branch: 1 branch
BranchTrueFalseTotal
if defined $body 4 55 59
981  
982 return {
983 59 wire => $wire,
984 version => '1.1',
985 mode => $mode,
986 remaining => $remaining,
987 stream_body => 0,
988 trailers => [],
989 keep_alive => 1,
990 body_finalized => 1,
991 };
992 }
993  
994 1 ▶sub _simple_response_plan_portable {
Subroutine _simple_response_plan_portable: called CC=25 SCAR=45.1
995 1 my ($request, $response, $stream_body) = @_;
996 1 ▶ return if $stream_body;
Branch: 1 branch
BranchTrueFalseTotal
if $stream_body 0 1 1
997  
998 1 my $request_version = $request->version;
999 1 ▶ $request_version = '1.1' unless defined $request_version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $request_version 1 0 1
1000 1 ▶ return unless $request_version eq '1.1';
Branch: 1 branch
BranchTrueFalseTotal
unless $request_version eq "1.1" 0 1 1
1001  
1002 1 my $method = _method($request->method);
1003 1 ▶ return if $method eq 'HEAD' || $method eq 'CONNECT';
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "HEAD" or $method eq "CONNECT" 0 1 1
Condition33%1/3
$method eq "HEAD" or $method eq "CONNECT"
l!l&&r!l&&!r
001
MC/DC0%0/2
$method eq "HEAD" or $method eq "CONNECT"
$method eq "HEAD" $method eq "CONNECT"
Truth table33%1/3
A or B
A= $method eq "HEAD"B= $method eq "CONNECT"
ABresult
1X1
011
000
1004  
1005 1 my $request_connection = $request->header_values('Connection');
1006 1 ▶ return unless defined($request_connection) && !@$request_connection;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $request_connection and not @$request_connection 0 1 1
Condition33%1/3
defined $request_connection and not @$request_connection
!ll&&!rl&&r
001
MC/DC0%0/2
defined $request_connection and not @$request_connection
defined $request_connection not @$request_connection
Truth table33%1/3
A and not(B)
A= defined $request_connectionB= not @$request_connection
ABresult
0X0
100
111
1007  
1008 1 my $response_version = $response->version;
1009 1 ▶ return if defined($response_version) && $response_version ne '1.1';
Branch: 1 branch
BranchTrueFalseTotal
if defined $response_version and $response_version ne "1.1" 0 1 1
Condition33%1/3
defined $response_version and $response_version ne "1.1"
!ll&&!rl&&r
100
MC/DC0%0/2
defined $response_version and $response_version ne "1.1"
defined $response_version $response_version ne "1.1"
Truth table33%1/3
A and B
A= defined $response_versionB= $response_version ne "1.1"
ABresult
0X0
100
111
1010  
1011 1 my $status = _status_code($response->status);
1012 1 ▶ return if $status < 200 || $status > 599
Branch: 1 branch
BranchTrueFalseTotal
if $status < 200 or $status > 599 or $status == 204 or $status == 205 or $status == 304 0 1 1
Condition33%4/12
$status < 200 or $status > 599 or $status == 204 or $status == 205 or $status == 304
l!l&&r!l&&!r
001
$status < 200 or $status > 599 or $status == 204 or $status == 205
l!l&&r!l&&!r
001
$status < 200 or $status > 599 or $status == 204
l!l&&r!l&&!r
001
$status < 200 or $status > 599
l!l&&r!l&&!r
001
MC/DC0%0/5
$status < 200 or $status > 599 or $status == 204 or $status == 205 or $status == 304
$status < 200 $status > 599 $status == 204 $status == 205 $status == 304
Truth table16%1/6
A or B or C or D or E
A= $status < 200B= $status > 599C= $status == 204D= $status == 205E= $status == 304
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1013 || $status == 204 || $status == 205 || $status == 304;
1014  
1015 1 my $trailer_count = $response->trailer_count;
1016 1 ▶ return unless defined($trailer_count) && $trailer_count == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $trailer_count and $trailer_count == 0 0 1 1
Condition33%1/3
defined $trailer_count and $trailer_count == 0
!ll&&!rl&&r
001
MC/DC0%0/2
defined $trailer_count and $trailer_count == 0
defined $trailer_count $trailer_count == 0
Truth table33%1/3
A and B
A= defined $trailer_countB= $trailer_count == 0
ABresult
0X0
100
111
1017  
1018 1 my $body;
1019 1 ▶ if ($response->has_buffered_body) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->has_buffered_body) { } 1 0 1
1020 1 $body = _bytes('response body', $response->body);
1021 } else {
1022 0 $body = '';
1023 }
1024  
1025 1 my $reason_value = $response->reason;
1026 my $reason = defined($reason_value)
1027 ? _reason_phrase($reason_value)
1028 1 ▶ : ($REASON{$status} || '');
Branch: 1 branch
BranchTrueFalseTotal
defined $reason_value ? : 0 1 1
Condition50%1/2
$REASON{$status} or ""
l!l
10
MC/DC0%0/1
$REASON{$status} or ""
$REASON{$status}
Truth table50%1/2
A
A= $REASON{$status}
Aresult
11
00
1029  
1030 1 my $count = $response->header_count;
1031 1 ▶ return unless defined $count;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $count 0 1 1
1032  
1033 1 my $wire = 'HTTP/1.1 ' . sprintf('%03d', $status)
1034 . ' ' . $reason . "\r\n";
1035  
1036 1 for my $index (0 .. $count - 1) {
1037 0 my $name = _field_name('header', $response->header_name($index));
1038 0 my $value = _field_value('header', $response->header_value($index));
1039 0 my $key = _lc($name);
1040  
1041 0 ▶ return if $key eq 'content-length'
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection" 0 0 0
Condition0%0/6
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection"
l!l&&r!l&&!r
000
$key eq "content-length" or $key eq "transfer-encoding"
l!l&&r!l&&!r
000
MC/DC0%0/3
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection"
$key eq "content-length" $key eq "transfer-encoding" $key eq "connection"
Truth table0%0/4
A or B or C
A= $key eq "content-length"B= $key eq "transfer-encoding"C= $key eq "connection"
ABCresult
1XX1
01X1
0011
0000
1042 || $key eq 'transfer-encoding'
1043 || $key eq 'connection';
1044  
1045 0 $wire .= $name . ': ' . $value . "\r\n";
1046 }
1047  
1048 1 my $length = length($body);
1049 1 $wire .= 'Content-Length: ' . $length . "\r\n\r\n" . $body;
1050  
1051 return {
1052 1 wire => $wire,
1053 version => '1.1',
1054 mode => 'content-length',
1055 remaining => 0,
1056 stream_body => 0,
1057 trailers => [],
1058 keep_alive => 1,
1059 close_after => 0,
1060 switch => 0,
1061 body_finalized => 1,
1062 };
1063 }
1064  
1065 96 ▶sub _simple_response_plan {
Subroutine _simple_response_plan: called CC=42 SCAR=40.8
1066 96 my ($request, $response, $stream_body, $request_view, $response_view) = @_;
1067 96 ▶ return _simple_response_plan_portable($request, $response, $stream_body)
Branch: 1 branch
BranchTrueFalseTotal
unless $request_view or $response_view 1 95 96
Condition66%2/3
$request_view or $response_view
l!l&&r!l&&!r
9501
MC/DC50%1/2
$request_view or $response_view
$request_view $response_view
Truth table66%2/3
A or B
A= $request_viewB= $response_view
ABresult
1X1
011
000
1068 unless $request_view || $response_view;
1069 95 ▶ return if $stream_body;
Branch: 1 branch
BranchTrueFalseTotal
if $stream_body 4 91 95
1070  
1071 91 ▶ my $request_version = $request_view
Branch: 1 branch
BranchTrueFalseTotal
$request_view ? : 91 0 91
1072 ? $request_view->[Uniform::HTTP::FastPath::SLOT_VERSION()]
1073 : $request->version;
1074 91 ▶ $request_version = '1.1' unless defined $request_version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $request_version 10 81 91
1075 91 ▶ return unless $request_version eq '1.1';
Branch: 1 branch
BranchTrueFalseTotal
unless $request_version eq "1.1" 6 85 91
1076  
1077 85 ▶ my $method = $request_view
Branch: 1 branch
BranchTrueFalseTotal
$request_view ? : 85 0 85
1078 ? $request_view->[Uniform::HTTP::FastPath::SLOT_METHOD()]
1079 : _method($request->method);
1080 85 ▶ return if $method eq 'HEAD' || $method eq 'CONNECT';
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "HEAD" or $method eq "CONNECT" 5 80 85
Condition100%3/3
$method eq "HEAD" or $method eq "CONNECT"
l!l&&r!l&&!r
2380
MC/DC100%2/2
$method eq "HEAD" or $method eq "CONNECT"
$method eq "HEAD" $method eq "CONNECT"
Truth table100%3/3
A or B
A= $method eq "HEAD"B= $method eq "CONNECT"
ABresult
1X1
011
000
1081  
1082 80 ▶ my $request_connection = $request_view
Branch: 1 branch
BranchTrueFalseTotal
$request_view ? : 80 0 80
1083 ? _values($request_view->[Uniform::HTTP::FastPath::SLOT_HEADERS()], 'Connection')
1084 : $request->header_values('Connection');
1085 80 ▶ return unless defined($request_connection) && !@$request_connection;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $request_connection and not @$request_connection 19 61 80
Condition66%2/3
defined $request_connection and not @$request_connection
!ll&&!rl&&r
01961
MC/DC50%1/2
defined $request_connection and not @$request_connection
defined $request_connection not @$request_connection
Truth table66%2/3
A and not(B)
A= defined $request_connectionB= not @$request_connection
ABresult
0X0
100
111
1086  
1087 61 ▶ my $response_version = $response_view
Branch: 1 branch
BranchTrueFalseTotal
$response_view ? : 57 4 61
1088 ? $response_view->[Uniform::HTTP::FastPath::SLOT_VERSION()]
1089 : $response->version;
1090 61 ▶ return if defined($response_version) && $response_version ne '1.1';
Branch: 1 branch
BranchTrueFalseTotal
if defined $response_version and $response_version ne "1.1" 0 61 61
Condition33%1/3
defined $response_version and $response_version ne "1.1"
!ll&&!rl&&r
6100
MC/DC0%0/2
defined $response_version and $response_version ne "1.1"
defined $response_version $response_version ne "1.1"
Truth table33%1/3
A and B
A= defined $response_versionB= $response_version ne "1.1"
ABresult
0X0
100
111
1091  
1092 61 ▶ my $status = $response_view
Branch: 1 branch
BranchTrueFalseTotal
$response_view ? : 57 4 61
1093 ? $response_view->[Uniform::HTTP::FastPath::SLOT_STATUS()]
1094 : _status_code($response->status);
1095 60 ▶ return if $status < 200 || $status > 599
Branch: 1 branch
BranchTrueFalseTotal
if $status < 200 or $status > 599 or $status == 204 or $status == 205 or $status == 304 7 53 60
Condition75%9/12
$status < 200 or $status > 599 or $status == 204 or $status == 205 or $status == 304
l!l&&r!l&&!r
7053
$status < 200 or $status > 599 or $status == 204 or $status == 205
l!l&&r!l&&!r
7053
$status < 200 or $status > 599 or $status == 204
l!l&&r!l&&!r
1653
$status < 200 or $status > 599
l!l&&r!l&&!r
1059
MC/DC40%2/5
$status < 200 or $status > 599 or $status == 204 or $status == 205 or $status == 304
$status < 200 $status > 599 $status == 204 $status == 205 $status == 304
Truth table50%3/6
A or B or C or D or E
A= $status < 200B= $status > 599C= $status == 204D= $status == 205E= $status == 304
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1096 || $status == 204 || $status == 205 || $status == 304;
1097  
1098 my $trailer_count = $response_view
1099 53 ▶ ? scalar @{ $response_view->[Uniform::HTTP::FastPath::SLOT_TRAILERS()] }
Branch: 1 branch
BranchTrueFalseTotal
$response_view ? : 50 3 53
1100 : $response->trailer_count;
1101 53 ▶ return unless defined($trailer_count) && $trailer_count == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $trailer_count and $trailer_count == 0 1 52 53
Condition66%2/3
defined $trailer_count and $trailer_count == 0
!ll&&!rl&&r
0152
MC/DC50%1/2
defined $trailer_count and $trailer_count == 0
defined $trailer_count $trailer_count == 0
Truth table66%2/3
A and B
A= defined $trailer_countB= $trailer_count == 0
ABresult
0X0
100
111
1102  
1103 52 my $body;
1104 52 ▶ if ($response_view) {
Branch: 2 branches
BranchTrueFalseTotal
if ($response_view) { } 49 3 52
elsif ($response->has_buffered_body) { } 0 3 3
1105 49 ▶ if ($response_view->[Uniform::HTTP::FastPath::SLOT_FLAGS()]
Branch: 1 branch
BranchTrueFalseTotal
if ($response_view->[2] & 1) { } 47 2 49
1106 & Uniform::HTTP::FastPath::FLAG_HAS_BUFFERED_BODY()) {
1107 47 $body = $response_view->[Uniform::HTTP::FastPath::SLOT_BODY()];
1108 } else {
1109 2 $body = '';
1110 }
1111 } elsif ($response->has_buffered_body) {
1112 0 $body = _bytes('response body', $response->body);
1113 } else {
1114 3 $body = '';
1115 }
1116  
1117 52 ▶ my $reason_value = $response_view
Branch: 1 branch
BranchTrueFalseTotal
$response_view ? : 49 3 52
1118 ? $response_view->[Uniform::HTTP::FastPath::SLOT_REASON()]
1119 : $response->reason;
1120 my $reason = defined($reason_value)
1121 ? ($response_view ? $reason_value : _reason_phrase($reason_value))
1122 52 ▶ : ($REASON{$status} || '');
Branch: 2 branches
BranchTrueFalseTotal
defined $reason_value ? : 1 51 52
$response_view ? : 0 1 1
Condition50%1/2
$REASON{$status} or ""
l!l
510
MC/DC0%0/1
$REASON{$status} or ""
$REASON{$status}
Truth table50%1/2
A
A= $REASON{$status}
Aresult
11
00
1123  
1124 51 my $wire = 'HTTP/1.1 ' . sprintf('%03d', $status)
1125 . ' ' . $reason . "\r\n";
1126  
1127 51 ▶ if ($response_view) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response_view) { } 49 2 51
1128 49 for my $field (@{ $response_view->[Uniform::HTTP::FastPath::SLOT_HEADERS()] }) {
1129 4 my ($name, $value) = @$field;
1130 4 my $key = _lc($name);
1131  
1132 4 ▶ return if $key eq 'content-length'
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection" 2 2 4
Condition83%5/6
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection"
l!l&&r!l&&!r
112
$key eq "content-length" or $key eq "transfer-encoding"
l!l&&r!l&&!r
103
MC/DC66%2/3
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection"
$key eq "content-length" $key eq "transfer-encoding" $key eq "connection"
Truth table75%3/4
A or B or C
A= $key eq "content-length"B= $key eq "transfer-encoding"C= $key eq "connection"
ABCresult
1XX1
01X1
0011
0000
1133 || $key eq 'transfer-encoding'
1134 || $key eq 'connection';
1135  
1136 2 $wire .= $name . ': ' . $value . "\r\n";
1137 }
1138 } else {
1139 2 my $count = $response->header_count;
1140 2 ▶ return unless defined $count;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $count 0 2 2
1141 2 for my $index (0 .. $count - 1) {
1142 2 my $name = _field_name('header', $response->header_name($index));
1143 1 my $value = _field_value('header', $response->header_value($index));
1144 0 my $key = _lc($name);
1145  
1146 0 ▶ return if $key eq 'content-length'
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection" 0 0 0
Condition0%0/6
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection"
l!l&&r!l&&!r
000
$key eq "content-length" or $key eq "transfer-encoding"
l!l&&r!l&&!r
000
MC/DC0%0/3
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "connection"
$key eq "content-length" $key eq "transfer-encoding" $key eq "connection"
Truth table0%0/4
A or B or C
A= $key eq "content-length"B= $key eq "transfer-encoding"C= $key eq "connection"
ABCresult
1XX1
01X1
0011
0000
1147 || $key eq 'transfer-encoding'
1148 || $key eq 'connection';
1149  
1150 0 $wire .= $name . ': ' . $value . "\r\n";
1151 }
1152 }
1153  
1154 47 my $length = length($body);
1155 47 $wire .= 'Content-Length: ' . $length . "\r\n\r\n" . $body;
1156  
1157 return {
1158 47 wire => $wire,
1159 version => '1.1',
1160 mode => 'content-length',
1161 remaining => 0,
1162 stream_body => 0,
1163 trailers => [],
1164 keep_alive => 1,
1165 close_after => 0,
1166 switch => 0,
1167 body_finalized => 1,
1168 };
1169 }
1170  
1171 100 ▶sub request_plan {
Subroutine request_plan: called CC=62 SCAR=49.5
Pod undocumented
1172 100 my ($request, %option) = @_;
1173 100 my $view = _fast_request_view($request);
1174 100 ▶ croak 'request does not implement the Uniform HTTP request contract'
Branch: 1 branch
BranchTrueFalseTotal
unless $view or ref $request and $request->can("method") and $request->can("target") and $request->can("header_count") and $request->can("has_buffered_body") 0 100 100
Condition40%6/15
$view or ref $request and $request->can("method") and $request->can("target") and $request->can("header_count") and $request->can("has_buffered_body")
l!l&&r!l&&!r
9550
ref $request and $request->can("method") and $request->can("target") and $request->can("header_count") and $request->can("has_buffered_body")
!ll&&!rl&&r
005
ref $request and $request->can("method") and $request->can("target") and $request->can("header_count")
!ll&&!rl&&r
005
ref $request and $request->can("method") and $request->can("target")
!ll&&!rl&&r
005
ref $request and $request->can("method")
!ll&&!rl&&r
005
MC/DC0%0/6
$view or ref $request and $request->can("method") and $request->can("target") and $request->can("header_count") and $request->can("has_buffered_body")
$view ref $request $request->can("method") $request->can("target") $request->can("header_count") $request->can("has_buffered_body")
Truth table28%2/7
A or B and C and D and E and F
A= $viewB= ref $requestC= $request->can("method")D= $request->can("target")E= $request->can("header_count")F= $request->can("has_buffered_body")
ABCDEFresult
1XXXXX1
0111111
00XXXX0
010XXX0
0110XX0
01110X0
0111100
1175 unless $view
1176 || (ref($request) && $request->can('method') && $request->can('target')
1177 && $request->can('header_count') && $request->can('has_buffered_body'));
1178  
1179 100 ▶ my $protocol = $view
Branch: 2 branches
BranchTrueFalseTotal
$view ? : 95 5 100
$request->can('protocol') ? : 5 0 5
1180 ? $view->[Uniform::HTTP::FastPath::SLOT_PROTOCOL()]
1181 : ($request->can('protocol') ? $request->protocol : undef);
1182 100 ▶ croak 'HTTP/1 cannot directly encode Uniform Extended CONNECT protocol metadata'
Branch: 1 branch
BranchTrueFalseTotal
if defined $protocol 0 100 100
1183 if defined $protocol;
1184  
1185 100 ▶ my $stream_body = $option{stream_body} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$option{'stream_body'} ? : 5 95 100
1186 100 ▶ if (my $simple = _simple_request_plan($request, $stream_body, $view)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $simple = _simple_request_plan($request, $stream_body, $view)) 59 31 90
1187 59 return $simple;
1188 }
1189  
1190 31 ▶ my $version = $view
Branch: 1 branch
BranchTrueFalseTotal
$view ? : 31 0 31
1191 ? $view->[Uniform::HTTP::FastPath::SLOT_VERSION()]
1192 : $request->version;
1193 31 ▶ $version = '1.1' unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 30 1 31
1194 31 ▶ croak 'HTTP/1 version must be 1.0 or 1.1'
Branch: 1 branch
BranchTrueFalseTotal
unless $version eq "1.0" or $version eq "1.1" 0 31 31
Condition66%2/3
$version eq "1.0" or $version eq "1.1"
l!l&&r!l&&!r
1300
MC/DC0%0/2
$version eq "1.0" or $version eq "1.1"
$version eq "1.0" $version eq "1.1"
Truth table66%2/3
A or B
A= $version eq "1.0"B= $version eq "1.1"
ABresult
1X1
011
000
1195 unless $version eq '1.0' || $version eq '1.1';
1196  
1197 31 ▶ my $method = $view
Branch: 1 branch
BranchTrueFalseTotal
$view ? : 31 0 31
1198 ? $view->[Uniform::HTTP::FastPath::SLOT_METHOD()]
1199 : _method($request->method);
1200 31 ▶ my $target = $view
Branch: 1 branch
BranchTrueFalseTotal
$view ? : 31 0 31
1201 ? $view->[Uniform::HTTP::FastPath::SLOT_TARGET()]
1202 : _bytes('request target', $request->target);
1203 31 _validate_request_target($method, $target);
1204  
1205 30 my $fields = _fields($request, 'header', $view);
1206 30 my $body;
1207 30 ▶ if ($view) {
Branch: 1 branch
BranchTrueFalseTotal
if ($view) { } 30 0 30
1208 30 ▶ if ($view->[Uniform::HTTP::FastPath::SLOT_FLAGS()]
Branch: 1 branch
BranchTrueFalseTotal
if ($view->[2] & 1) 2 28 30
1209 & Uniform::HTTP::FastPath::FLAG_HAS_BUFFERED_BODY()) {
1210 2 $body = $view->[Uniform::HTTP::FastPath::SLOT_BODY()];
1211 }
1212 } else {
1213 0 ▶ $body = $request->has_buffered_body
Branch: 1 branch
BranchTrueFalseTotal
$request->has_buffered_body ? : 0 0 0
1214 ? _bytes('request body', $request->body)
1215 : undef;
1216 }
1217 30 ▶ croak 'stream_body cannot be combined with a buffered request body'
Branch: 1 branch
BranchTrueFalseTotal
if $stream_body and defined $body 0 30 30
Condition66%2/3
$stream_body and defined $body
!ll&&!rl&&r
2550
MC/DC0%0/2
$stream_body and defined $body
$stream_body defined $body
Truth table66%2/3
A and B
A= $stream_bodyB= defined $body
ABresult
0X0
100
111
1218 if $stream_body && defined $body;
1219  
1220 30 my $host = _values($fields, 'Host');
1221 30 ▶ croak 'HTTP/1 request must not contain multiple Host fields' if @$host > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$host > 1 0 30 30
1222  
1223 30 my ($absolute_form, $absolute_host) = _absolute_form_host($method, $target);
1224 30 ▶ if ($version eq '1.1' && $absolute_form) {
Branch: 2 branches
BranchTrueFalseTotal
if ($version eq '1.1' and $absolute_form) { } 4 26 30
elsif (not @$host and $version eq '1.1') { } 4 43 47
Condition100%3/3
$version eq "1.1" and $absolute_form
!ll&&!rl&&r
1254
MC/DC100%2/2
$version eq "1.1" and $absolute_form
$version eq "1.1" $absolute_form
Truth table100%3/3
A and B
A= $version eq "1.1"B= $absolute_form
ABresult
0X0
100
111
1225 4 ▶ if (@$host) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$host) { } 3 1 4
1226 3 ▶ croak 'HTTP/1.1 absolute-form Host must match request-target authority'
Branch: 1 branch
BranchTrueFalseTotal
if $host->[0] ne $absolute_host 1 2 3
1227 if $host->[0] ne $absolute_host;
1228 } else {
1229 1 $fields = [ @$fields, [ 'Host', $absolute_host ] ];
1230 1 $host = [ $absolute_host ];
1231 }
1232 ▶ } elsif (!@$host && $version eq '1.1') {
Condition100%3/3
not @$host and $version eq "1.1"
!ll&&!rl&&r
2114
MC/DC100%2/2
not @$host and $version eq "1.1"
not @$host $version eq "1.1"
Truth table100%3/3
not(A) and B
A= not @$hostB= $version eq "1.1"
ABresult
0X0
100
111
1233 4 ▶ my $authority = $view
Branch: 2 branches
BranchTrueFalseTotal
$view ? : 4 0 4
$request->can('authority') ? : 0 0 0
1234 ? $view->[Uniform::HTTP::FastPath::SLOT_AUTHORITY()]
1235 : ($request->can('authority') ? $request->authority : undef);
1236 4 ▶ croak 'HTTP/1.1 request requires Host or Uniform authority metadata'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $authority 0 4 4
1237 unless defined $authority;
1238 4 ▶ $fields = [ @$fields, [
Branch: 1 branch
BranchTrueFalseTotal
$view ? : 4 0 4
1239 'Host',
1240 $view ? $authority : _bytes('request authority', $authority),
1241 ] ];
1242 }
1243  
1244 29 _validate_host_value($_) for @{ _values($fields, 'Host') };
1245  
1246 29 my $te_preferences = _request_te_preferences($fields);
1247 24 ▶ if ($te_preferences->{present}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($te_preferences->{"present"}) 3 21 24
1248 3 ▶ croak 'HTTP/1.0 request cannot send TE'
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "1.0" 1 2 3
1249 if $version eq '1.0';
1250 2 my $connection = _connection_tokens($fields);
1251 $fields = _append_connection_token($fields, 'TE')
1252 2 ▶ unless $connection->{te};
Branch: 1 branch
BranchTrueFalseTotal
unless $connection->{"te"} 2 0 2
1253 }
1254  
1255 23 my $cl = _content_length($fields);
1256 23 my $te = _transfer_encoding($fields);
1257 23 ▶ croak 'request cannot contain both Transfer-Encoding and Content-Length'
Branch: 1 branch
BranchTrueFalseTotal
if @$te and defined $cl 0 23 23
Condition33%1/3
@$te and defined $cl
!ll&&!rl&&r
2300
MC/DC0%0/2
@$te and defined $cl
@$te defined $cl
Truth table33%1/3
A and B
A= @$teB= defined $cl
ABresult
0X0
100
111
1258 if @$te && defined $cl;
1259  
1260 23 my $trailers = _fields($request, 'trailer', $view);
1261 23 ▶ my $has_trailers = @$trailers ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@$trailers ? : 1 22 23
1262 23 ▶ $fields = _ensure_trailer_header($fields, $trailers)
Branch: 1 branch
BranchTrueFalseTotal
if $has_trailers 1 22 23
1263 if $has_trailers;
1264  
1265 23 _validate_connect_request(
1266 $request, $fields, $version, $body, $stream_body, $trailers, $view,
1267 );
1268  
1269 20 my ($mode, $remaining);
1270  
1271 20 ▶ if ($has_trailers) {
Branch: 5 branches
BranchTrueFalseTotal
if ($has_trailers) { } 1 19 20
elsif (@$te) { } 0 19 19
elsif (defined $cl) { } 3 16 19
elsif ($stream_body) { } 3 13 16
elsif (defined $body) { } 0 13 13
1272 1 ▶ croak 'HTTP/1.0 cannot send trailer fields' if $version eq '1.0';
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "1.0" 0 1 1
1273 1 ▶ croak 'trailers cannot be combined with Content-Length' if defined $cl;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cl 0 1 1
1274 1 $fields = _replace_or_add($fields, 'Transfer-Encoding', 'chunked');
1275 1 $mode = 'chunked';
1276 } elsif (@$te) {
1277 0 ▶ croak 'HTTP/1.0 does not support chunked transfer coding' if $version eq '1.0';
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "1.0" 0 0 0
1278 0 $mode = 'chunked';
1279 } elsif (defined $cl) {
1280 3 $mode = 'content-length';
1281 3 $remaining = $cl;
1282 3 ▶ croak 'request Content-Length does not match buffered body length'
Branch: 1 branch
BranchTrueFalseTotal
if defined $body and length $body != $cl 0 3 3
Condition33%1/3
defined $body and length $body != $cl
!ll&&!rl&&r
300
MC/DC0%0/2
defined $body and length $body != $cl
defined $body length $body != $cl
Truth table33%1/3
A and B
A= defined $bodyB= length $body != $cl
ABresult
0X0
100
111
1283 if defined($body) && length($body) != $cl;
1284 } elsif ($stream_body) {
1285 3 ▶ croak 'streaming HTTP/1.0 request body requires Content-Length'
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "1.0" 0 3 3
1286 if $version eq '1.0';
1287 3 $fields = [ @$fields, [ 'Transfer-Encoding', 'chunked' ] ];
1288 3 $mode = 'chunked';
1289 } elsif (defined $body) {
1290 0 $fields = [ @$fields, [ 'Content-Length', length($body) ] ];
1291 0 $mode = 'content-length';
1292 0 $remaining = length($body);
1293 } else {
1294 13 $mode = 'none';
1295 }
1296  
1297 20 my $wire = $method . ' ' . $target . ' HTTP/' . $version . "\r\n"
1298 . _serialize_fields($fields) . "\r\n";
1299  
1300 20 ▶ if (defined $body) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $body) { } 1 19 20
elsif (not $stream_body and $mode eq 'chunked') { } 0 24 24
1301 1 ▶ $wire .= $mode eq 'chunked'
Branch: 1 branch
BranchTrueFalseTotal
$mode eq 'chunked' ? : 1 0 1
1302 ? chunk($body) . final_chunk($trailers)
1303 : $body;
1304 1 ▶ $remaining = 0 if defined $remaining;
Branch: 1 branch
BranchTrueFalseTotal
if defined $remaining 0 1 1
1305 ▶ } elsif (!$stream_body && $mode eq 'chunked') {
Condition66%2/3
not $stream_body and $mode eq "chunked"
!ll&&!rl&&r
5140
MC/DC0%0/2
not $stream_body and $mode eq "chunked"
not $stream_body $mode eq "chunked"
Truth table66%2/3
not(A) and B
A= not $stream_bodyB= $mode eq "chunked"
ABresult
0X0
100
111
1306 0 $wire .= final_chunk($trailers);
1307 }
1308  
1309 20 my $tokens = _connection_tokens($fields);
1310 my $keep_alive = $tokens->{close} ? 0
1311 : $version eq '1.1' ? 1
1312 19 ▶ : $tokens->{'keep-alive'} ? 1 : 0;
Branch: 3 branches
BranchTrueFalseTotal
$tokens->{'close'} ? : 1 18 19
$version eq '1.1' ? : 18 0 18
$tokens->{'keep-alive'} ? : 0 0 0
1313  
1314 return {
1315 19 ▶ wire => $wire,
Branch: 1 branch
BranchTrueFalseTotal
$stream_body ? : 5 14 19
1316 version => $version,
1317 mode => $mode,
1318 remaining => $remaining,
1319 stream_body => $stream_body,
1320 trailers => $trailers,
1321 keep_alive => $keep_alive,
1322 body_finalized => $stream_body ? 0 : 1,
1323 };
1324 }
1325  
1326 59 ▶sub response_receive_plan {
Subroutine response_receive_plan: called CC=37 SCAR=36.3
Pod undocumented
1327 59 my ($request, $head, $response) = @_;
1328 59 my $request_view = _fast_request_view($request);
1329 59 ▶ my $response_view = $response ? _fast_response_view($response) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$response ? : 5 54 59
1330 my $fields = $response_view
1331 ? $response_view->[Uniform::HTTP::FastPath::SLOT_HEADERS()]
1332 59 ▶ : $head->{headers};
Branch: 1 branch
BranchTrueFalseTotal
$response_view ? : 5 54 59
1333 my $status = $response_view
1334 ? $response_view->[Uniform::HTTP::FastPath::SLOT_STATUS()]
1335 59 ▶ : $head->{status};
Branch: 1 branch
BranchTrueFalseTotal
$response_view ? : 5 54 59
1336 my $version = $response_view
1337 ? $response_view->[Uniform::HTTP::FastPath::SLOT_VERSION()]
1338 59 ▶ : $head->{version};
Branch: 1 branch
BranchTrueFalseTotal
$response_view ? : 5 54 59
1339 59 ▶ my $method = $request_view
Branch: 1 branch
BranchTrueFalseTotal
$request_view ? : 59 0 59
1340 ? $request_view->[Uniform::HTTP::FastPath::SLOT_METHOD()]
1341 : $request->method;
1342  
1343 59 ▶ if ($method eq 'CONNECT' && $status >= 200 && $status < 300) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "CONNECT" and $status >= 200 and $status < 300) 1 58 59
Condition83%5/6
$method eq "CONNECT" and $status >= 200 and $status < 300
!ll&&!rl&&r
5711
$method eq "CONNECT" and $status >= 200
!ll&&!rl&&r
5702
MC/DC66%2/3
$method eq "CONNECT" and $status >= 200 and $status < 300
$method eq "CONNECT" $status >= 200 $status < 300
Truth table75%3/4
A and B and C
A= $method eq "CONNECT"B= $status >= 200C= $status < 300
ABCresult
0XX0
10X0
1100
1111
1344 1 ▶ croak 'HTTP/1 CONNECT successful response must use HTTP/1.1 semantics'
Branch: 1 branch
BranchTrueFalseTotal
unless _semantics_version($version) eq "1.1" 0 1 1
1345 unless _semantics_version($version) eq '1.1';
1346 return {
1347 1 mode => 'none',
1348 remaining => undef,
1349 switch => 1,
1350 keep_alive => 0,
1351 };
1352 }
1353  
1354 58 ▶ if ($status == 101) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status == 101) 4 54 58
1355 4 _validate_upgrade_response(
1356 $request,
1357 _fields($request, 'header', $request_view),
1358 $fields,
1359 $version,
1360 $request_view,
1361 );
1362 return {
1363 3 mode => 'none',
1364 remaining => undef,
1365 switch => 1,
1366 keep_alive => 0,
1367 };
1368 }
1369  
1370 54 my $response_semantics = _semantics_version($version);
1371 54 my $tokens = _connection_tokens($fields);
1372 my $keep_alive = $tokens->{close} ? 0
1373 : $response_semantics eq '1.1' ? 1
1374 53 ▶ : $tokens->{'keep-alive'} ? 1 : 0;
Branch: 3 branches
BranchTrueFalseTotal
$tokens->{'close'} ? : 2 51 53
$response_semantics eq '1.1' ? : 49 2 51
$tokens->{'keep-alive'} ? : 0 2 2
1375  
1376 53 my $raw_te = _values($fields, 'Transfer-Encoding');
1377 53 ▶ croak 'HTTP/1.0 response must not contain Transfer-Encoding'
Branch: 1 branch
BranchTrueFalseTotal
if $response_semantics eq "1.0" and @$raw_te 1 52 53
Condition100%3/3
$response_semantics eq "1.0" and @$raw_te
!ll&&!rl&&r
5111
MC/DC100%2/2
$response_semantics eq "1.0" and @$raw_te
$response_semantics eq "1.0" @$raw_te
Truth table100%3/3
A and B
A= $response_semantics eq "1.0"B= @$raw_te
ABresult
0X0
100
111
1378 if $response_semantics eq '1.0' && @$raw_te;
1379  
1380 52 ▶ if ($method eq 'HEAD' || $status == 304) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "HEAD" or $status == 304) 2 50 52
Condition100%3/3
$method eq "HEAD" or $status == 304
l!l&&r!l&&!r
1150
MC/DC100%2/2
$method eq "HEAD" or $status == 304
$method eq "HEAD" $status == 304
Truth table100%3/3
A or B
A= $method eq "HEAD"B= $status == 304
ABresult
1X1
011
000
1381 return {
1382 2 mode => 'none',
1383 remaining => undef,
1384 switch => 0,
1385 keep_alive => $keep_alive,
1386 };
1387 }
1388  
1389 50 my $cl = _content_length($fields);
1390 49 my $te = _response_transfer_encoding($fields);
1391 46 ▶ croak 'response contains both Transfer-Encoding and Content-Length'
Branch: 1 branch
BranchTrueFalseTotal
if @$te and defined $cl 0 46 46
Condition66%2/3
@$te and defined $cl
!ll&&!rl&&r
3790
MC/DC0%0/2
@$te and defined $cl
@$te defined $cl
Truth table66%2/3
A and B
A= @$teB= defined $cl
ABresult
0X0
100
111
1392 if @$te && defined $cl;
1393  
1394 46 ▶ my $body_forbidden = ($status >= 100 && $status < 200)
Condition83%5/6
$status >= 100 && $status < 200 || $status == 204
l!l&&r!l&&!r
4636
$status >= 100 and $status < 200
!ll&&!rl&&r
0424
MC/DC66%2/3
$status >= 100 && $status < 200 || $status == 204
$status >= 100 $status < 200 $status == 204
Truth table60%3/5
A and B || C
A= $status >= 100B= $status < 200C= $status == 204
ABCresult
11X1
0X11
1011
0X00
1000
1395 || $status == 204;
1396  
1397 46 ▶ croak '1xx and 204 responses must not contain Content-Length'
Branch: 1 branch
BranchTrueFalseTotal
if $status >= 100 && $status < 200 || $status == 204 and defined $cl 2 44 46
Condition88%8/9
$status >= 100 && $status < 200 || $status == 204 and defined $cl
!ll&&!rl&&r
3682
$status >= 100 and $status < 200 or $status == 204
l!l&&r!l&&!r
4636
$status >= 100 and $status < 200
!ll&&!rl&&r
0424
MC/DC75%3/4
$status >= 100 && $status < 200 || $status == 204 and defined $cl
$status >= 100 $status < 200 $status == 204 defined $cl
Truth table62%5/8
A and B or C and D
A= $status >= 100B= $status < 200C= $status == 204D= defined $cl
ABCDresult
0X0X0
100X0
11X00
0X100
10100
11X11
0X111
10111
1398 if (($status >= 100 && $status < 200) || $status == 204) && defined $cl;
1399 44 ▶ croak '205 response Content-Length must be zero'
Branch: 1 branch
BranchTrueFalseTotal
if $status == 205 and defined $cl and $cl != 0 1 43 44
Condition100%6/6
$status == 205 and defined $cl and $cl != 0
!ll&&!rl&&r
4211
$status == 205 and defined $cl
!ll&&!rl&&r
4022
MC/DC100%3/3
$status == 205 and defined $cl and $cl != 0
$status == 205 defined $cl $cl != 0
Truth table100%4/4
A and B and C
A= $status == 205B= defined $clC= $cl != 0
ABCresult
0XX0
10X0
1100
1111
1400 if $status == 205 && defined($cl) && $cl != 0;
1401 43 ▶ croak 'bodyless response must not contain Transfer-Encoding'
Branch: 1 branch
BranchTrueFalseTotal
if $body_forbidden and @$te 0 43 43
Condition66%2/3
$body_forbidden and @$te
!ll&&!rl&&r
3580
MC/DC0%0/2
$body_forbidden and @$te
$body_forbidden @$te
Truth table66%2/3
A and B
A= $body_forbiddenB= @$te
ABresult
0X0
100
111
1402 if $body_forbidden && @$te;
1403  
1404 43 my $mode = 'none';
1405 43 my $remaining;
1406 43 ▶ if (!$body_forbidden) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($body_forbidden) 35 8 43
1407 35 ▶ if (@$te) {
Branch: 2 branches
BranchTrueFalseTotal
if (@$te) { } 9 26 35
elsif (defined $cl) { } 25 1 26
1408 9 ▶ $mode = $te->[-1] eq 'chunked' ? 'chunked' : 'close';
Branch: 1 branch
BranchTrueFalseTotal
$te->[-1] eq 'chunked' ? : 8 1 9
1409 } elsif (defined $cl) {
1410 25 $mode = 'content-length';
1411 25 $remaining = $cl;
1412 } else {
1413 1 $mode = 'close';
1414 }
1415 }
1416  
1417 43 ▶ $keep_alive = 0 if $mode eq 'close';
Branch: 1 branch
BranchTrueFalseTotal
if $mode eq "close" 2 41 43
1418  
1419 return {
1420 43 ▶ mode => $mode,
Branch: 1 branch
BranchTrueFalseTotal
$status == 205 ? : 3 40 43
1421 remaining => $remaining,
1422 switch => 0,
1423 keep_alive => $keep_alive,
1424 forbid_content => $status == 205 ? 1 : 0,
1425 };
1426 }
1427  
1428 96 ▶sub response_plan {
Subroutine response_plan: called CC=136 SCAR=62.3
Pod undocumented
1429 96 my ($request, $response, %option) = @_;
1430 96 my $request_view = _fast_request_view($request);
1431 96 my $response_view = _fast_response_view($response);
1432  
1433 96 ▶ croak 'response does not implement the Uniform HTTP response contract'
Branch: 1 branch
BranchTrueFalseTotal
unless $response_view or ref $response and $response->can("status") and $response->can("header_count") and $response->can("has_buffered_body") 0 96 96
Condition41%5/12
$response_view or ref $response and $response->can("status") and $response->can("header_count") and $response->can("has_buffered_body")
l!l&&r!l&&!r
9150
ref $response and $response->can("status") and $response->can("header_count") and $response->can("has_buffered_body")
!ll&&!rl&&r
005
ref $response and $response->can("status") and $response->can("header_count")
!ll&&!rl&&r
005
ref $response and $response->can("status")
!ll&&!rl&&r
005
MC/DC0%0/5
$response_view or ref $response and $response->can("status") and $response->can("header_count") and $response->can("has_buffered_body")
$response_view ref $response $response->can("status") $response->can("header_count") $response->can("has_buffered_body")
Truth table33%2/6
A or B and C and D and E
A= $response_viewB= ref $responseC= $response->can("status")D= $response->can("header_count")E= $response->can("has_buffered_body")
ABCDEresult
1XXXX1
011111
00XXX0
010XX0
0110X0
011100
1434 unless $response_view
1435 || (ref($response) && $response->can('status')
1436 && $response->can('header_count')
1437 && $response->can('has_buffered_body'));
1438  
1439 96 ▶ my $stream_body = $option{stream_body} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$option{'stream_body'} ? : 4 92 96
1440 96 ▶ if (my $simple = _simple_response_plan(
Branch: 1 branch
BranchTrueFalseTotal
if (my $simple = _simple_response_plan($request, $response, $stream_body, $request_view, $response_view)) 48 44 92
1441 $request, $response, $stream_body, $request_view, $response_view,
1442 )) {
1443 48 return $simple;
1444 }
1445  
1446 44 ▶ my $received_request_version = $request_view
Branch: 1 branch
BranchTrueFalseTotal
$request_view ? : 44 0 44
1447 ? $request_view->[Uniform::HTTP::FastPath::SLOT_VERSION()]
1448 : $request->version;
1449 44 ▶ $received_request_version ||= '1.1';
Condition100%2/2
$received_request_version ||= "1.1"
l!l
404
MC/DC100%1/1
$received_request_version ||= "1.1"
$received_request_version
Truth table100%2/2
A
A= $received_request_version
Aresult
11
00
1450 44 my $request_version = _semantics_version($received_request_version);
1451  
1452 44 ▶ my $response_version = $response_view
Branch: 1 branch
BranchTrueFalseTotal
$response_view ? : 44 0 44
1453 ? $response_view->[Uniform::HTTP::FastPath::SLOT_VERSION()]
1454 : $response->version;
1455 44 ▶ if (defined $response_version && $response_version ne $request_version) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response_version and $response_version ne $request_version) 0 44 44
Condition33%1/3
defined $response_version and $response_version ne $request_version
!ll&&!rl&&r
4400
MC/DC0%0/2
defined $response_version and $response_version ne $request_version
defined $response_version $response_version ne $request_version
Truth table33%1/3
A and B
A= defined $response_versionB= $response_version ne $request_version
ABresult
0X0
100
111
1456 0 croak 'response version conflicts with supported HTTP/1 response semantics';
1457 }
1458  
1459 44 ▶ my $status = $response_view
Branch: 1 branch
BranchTrueFalseTotal
$response_view ? : 44 0 44
1460 ? $response_view->[Uniform::HTTP::FastPath::SLOT_STATUS()]
1461 : _status_code($response->status);
1462 44 ▶ my $reason_value = $response_view
Branch: 1 branch
BranchTrueFalseTotal
$response_view ? : 44 0 44
1463 ? $response_view->[Uniform::HTTP::FastPath::SLOT_REASON()]
1464 : $response->reason;
1465 my $reason = defined($reason_value)
1466 ? ($response_view ? $reason_value : _reason_phrase($reason_value))
1467 44 ▶ : ($REASON{$status} || '');
Branch: 2 branches
BranchTrueFalseTotal
defined $reason_value ? : 0 44 44
$response_view ? : 0 0 0
Condition50%1/2
$REASON{$status} or ""
l!l
440
MC/DC0%0/1
$REASON{$status} or ""
$REASON{$status}
Truth table50%1/2
A
A= $REASON{$status}
Aresult
11
00
1468  
1469 44 my $fields = _fields($response, 'header', $response_view);
1470 44 my $trailers = _fields($response, 'trailer', $response_view);
1471 44 ▶ $fields = _ensure_trailer_header($fields, $trailers)
Branch: 1 branch
BranchTrueFalseTotal
if @$trailers 1 43 44
1472 if @$trailers;
1473  
1474 44 my $body;
1475 44 ▶ if ($response_view) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response_view) { } 44 0 44
1476 44 ▶ if ($response_view->[Uniform::HTTP::FastPath::SLOT_FLAGS()]
Branch: 1 branch
BranchTrueFalseTotal
if ($response_view->[2] & 1) 16 28 44
1477 & Uniform::HTTP::FastPath::FLAG_HAS_BUFFERED_BODY()) {
1478 16 $body = $response_view->[Uniform::HTTP::FastPath::SLOT_BODY()];
1479 }
1480 } else {
1481 0 ▶ $body = $response->has_buffered_body
Branch: 1 branch
BranchTrueFalseTotal
$response->has_buffered_body ? : 0 0 0
1482 ? _bytes('response body', $response->body)
1483 : undef;
1484 }
1485 44 ▶ croak 'stream_body cannot be combined with a buffered response body'
Branch: 1 branch
BranchTrueFalseTotal
if $stream_body and defined $body 0 44 44
Condition66%2/3
$stream_body and defined $body
!ll&&!rl&&r
4040
MC/DC0%0/2
$stream_body and defined $body
$stream_body defined $body
Truth table66%2/3
A and B
A= $stream_bodyB= defined $body
ABresult
0X0
100
111
1486 if $stream_body && defined $body;
1487  
1488 44 ▶ my $method = $request_view
Branch: 1 branch
BranchTrueFalseTotal
$request_view ? : 44 0 44
1489 ? $request_view->[Uniform::HTTP::FastPath::SLOT_METHOD()]
1490 : $request->method;
1491 44 ▶ my $connect_switch = $method eq 'CONNECT'
Branch: 1 branch
BranchTrueFalseTotal
$method eq 'CONNECT' && $status >= 200 && $status < 300 ? : 2 42 44
Condition83%5/6
$method eq "CONNECT" and $status >= 200 and $status < 300
!ll&&!rl&&r
4112
$method eq "CONNECT" and $status >= 200
!ll&&!rl&&r
4103
MC/DC66%2/3
$method eq "CONNECT" and $status >= 200 and $status < 300
$method eq "CONNECT" $status >= 200 $status < 300
Truth table75%3/4
A and B and C
A= $method eq "CONNECT"B= $status >= 200C= $status < 300
ABCresult
0XX0
10X0
1100
1111
1492 && $status >= 200 && $status < 300 ? 1 : 0;
1493 44 ▶ my $upgrade_switch = $status == 101 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$status == 101 ? : 9 35 44
1494 44 ▶ my $switch = $connect_switch || $upgrade_switch ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$connect_switch || $upgrade_switch ? : 11 33 44
Condition100%3/3
$connect_switch or $upgrade_switch
l!l&&r!l&&!r
2933
MC/DC100%2/2
$connect_switch or $upgrade_switch
$connect_switch $upgrade_switch
Truth table100%3/3
A or B
A= $connect_switchB= $upgrade_switch
ABresult
1X1
011
000
1495 44 ▶ my $body_forbidden = $switch || ($status >= 100 && $status < 200)
Condition91%11/12
$switch || $status >= 100 && $status < 200 || $status == 204 || $status == 304
l!l&&r!l&&!r
20123
$switch or $status >= 100 and $status < 200 or $status == 204
l!l&&r!l&&!r
14624
$switch or $status >= 100 and $status < 200
l!l&&r!l&&!r
11330
$status >= 100 and $status < 200
!ll&&!rl&&r
0303
MC/DC80%4/5
$switch || $status >= 100 && $status < 200 || $status == 204 || $status == 304
$switch $status >= 100 $status < 200 $status == 204 $status == 304
Truth table62%5/8
A or B and C or D || E
A= $switchB= $status >= 100C= $status < 200D= $status == 204E= $status == 304
ABCDEresult
1XXXX1
011XX1
00X1X1
0101X1
00X011
010011
00X000
010000
1496 || $status == 204 || $status == 304;
1497 44 ▶ my $head_only = $method eq 'HEAD' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$method eq 'HEAD' ? : 2 42 44
1498  
1499 44 ▶ if ($connect_switch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($connect_switch) 2 42 44
1500 2 _validate_connect_request(
1501 $request,
1502 _fields($request, 'header', $request_view),
1503 $request_version,
1504 undef,
1505 0,
1506 [],
1507 $request_view,
1508 );
1509 2 ▶ croak 'successful CONNECT response must not contain a buffered body'
Branch: 1 branch
BranchTrueFalseTotal
if defined $body 0 2 2
1510 if defined $body;
1511 2 ▶ croak 'successful CONNECT response cannot stream a body' if $stream_body;
Branch: 1 branch
BranchTrueFalseTotal
if $stream_body 0 2 2
1512 2 ▶ croak 'successful CONNECT response must not contain trailers' if @$trailers;
Branch: 1 branch
BranchTrueFalseTotal
if @$trailers 0 2 2
1513 }
1514  
1515 44 ▶ croak 'protocol-switch responses cannot carry a body or trailers'
Branch: 1 branch
BranchTrueFalseTotal
if $upgrade_switch and defined $body || $stream_body || @$trailers 0 44 44
Condition44%4/9
$upgrade_switch and defined $body || $stream_body || @$trailers
!ll&&!rl&&r
3590
defined $body or $stream_body or @$trailers
l!l&&r!l&&!r
009
defined $body or $stream_body
l!l&&r!l&&!r
009
MC/DC0%0/4
$upgrade_switch and defined $body || $stream_body || @$trailers
$upgrade_switch defined $body $stream_body @$trailers
Truth table40%2/5
A and B or C or D
A= $upgrade_switchB= defined $bodyC= $stream_bodyD= @$trailers
ABCDresult
0XXX0
10000
11XX1
101X1
10011
1516 if $upgrade_switch && (defined($body) || $stream_body || @$trailers);
1517 44 ▶ croak 'this response status cannot carry a body or trailers'
Branch: 1 branch
BranchTrueFalseTotal
if $body_forbidden and not $switch and defined $body && length $body || $stream_body || @$trailers 0 44 44
Condition53%8/15
$body_forbidden and not $switch and defined $body && length $body || $stream_body || @$trailers
!ll&&!rl&&r
34100
$body_forbidden and not $switch
!ll&&!rl&&r
231110
defined $body and length $body or $stream_body or @$trailers
l!l&&r!l&&!r
0010
defined $body and length $body or $stream_body
l!l&&r!l&&!r
0010
defined $body and length $body
!ll&&!rl&&r
1000
MC/DC0%0/6
$body_forbidden and not $switch and defined $body && length $body || $stream_body || @$trailers
$body_forbidden not $switch defined $body length $body $stream_body @$trailers
Truth table33%3/9
A and not(B) and C and D or E or F
A= $body_forbiddenB= not $switchC= defined $bodyD= length $bodyE= $stream_bodyF= @$trailers
ABCDEFresult
0XXXXX0
10XXXX0
110X000
1110000
1111XX1
110X1X1
11101X1
110X011
1110011
1518 if $body_forbidden && !$switch
1519 && ((defined($body) && length($body)) || $stream_body || @$trailers);
1520  
1521 44 ▶ croak '205 response must not contain content'
Branch: 1 branch
BranchTrueFalseTotal
if $status == 205 and defined $body and length $body 0 44 44
Condition33%2/6
$status == 205 and defined $body and length $body
!ll&&!rl&&r
4400
$status == 205 and defined $body
!ll&&!rl&&r
4400
MC/DC0%0/3
$status == 205 and defined $body and length $body
$status == 205 defined $body length $body
Truth table25%1/4
A and B and C
A= $status == 205B= defined $bodyC= length $body
ABCresult
0XX0
10X0
1100
1111
1522 if $status == 205 && defined($body) && length($body);
1523 44 ▶ croak '205 response cannot use a streaming content producer'
Branch: 1 branch
BranchTrueFalseTotal
if $status == 205 and $stream_body 0 44 44
Condition33%1/3
$status == 205 and $stream_body
!ll&&!rl&&r
4400
MC/DC0%0/2
$status == 205 and $stream_body
$status == 205 $stream_body
Truth table33%1/3
A and B
A= $status == 205B= $stream_body
ABresult
0X0
100
111
1524 if $status == 205 && $stream_body;
1525  
1526 44 my $cl = _content_length($fields);
1527 43 ▶ croak '205 response Content-Length must be zero'
Branch: 1 branch
BranchTrueFalseTotal
if $status == 205 and defined $cl and $cl != 0 0 43 43
Condition33%2/6
$status == 205 and defined $cl and $cl != 0
!ll&&!rl&&r
4300
$status == 205 and defined $cl
!ll&&!rl&&r
4300
MC/DC0%0/3
$status == 205 and defined $cl and $cl != 0
$status == 205 defined $cl $cl != 0
Truth table25%1/4
A and B and C
A= $status == 205B= defined $clC= $cl != 0
ABCresult
0XX0
10X0
1100
1111
1528 if $status == 205 && defined($cl) && $cl != 0;
1529  
1530 43 ▶ my $metadata_only_framing = $head_only || $status == 304 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$head_only || $status == 304 ? : 3 40 43
Condition100%3/3
$head_only or $status == 304
l!l&&r!l&&!r
2140
MC/DC100%2/2
$head_only or $status == 304
$head_only $status == 304
Truth table100%3/3
A or B
A= $head_onlyB= $status == 304
ABresult
1X1
011
000
1531 43 my $te = _response_transfer_encoding($fields);
1532 43 ▶ croak 'response cannot contain both Transfer-Encoding and Content-Length'
Branch: 1 branch
BranchTrueFalseTotal
if not $connect_switch and @$te and defined $cl 0 43 43
Condition83%5/6
not $connect_switch and @$te and defined $cl
!ll&&!rl&&r
3940
not $connect_switch and @$te
!ll&&!rl&&r
2374
MC/DC0%0/3
not $connect_switch and @$te and defined $cl
not $connect_switch @$te defined $cl
Truth table75%3/4
not(A) and B and C
A= not $connect_switchB= @$teC= defined $cl
ABCresult
0XX0
10X0
1100
1111
1533 if !$connect_switch && @$te && defined $cl;
1534  
1535 43 ▶ if (grep { $_ ne 'chunked' } @$te) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ ne "chunked";} @$te) 4 39 43
1536 4 my $request_fields = _fields($request, 'header', $request_view);
1537 4 my $request_connection = _connection_tokens($request_fields);
1538 4 my $preferences = _request_te_preferences($request_fields);
1539  
1540 4 for my $coding (grep { $_ ne 'chunked' } @$te) {
1541 4 ▶ my $quality = $preferences->{quality}{$coding} || 0;
Condition100%2/2
$preferences->{'quality'}{$coding} || 0
l!l
31
MC/DC100%1/1
$preferences->{'quality'}{$coding} || 0
$preferences->{'quality'}{$coding}
Truth table100%2/2
A
A= $preferences->{'quality'}{$coding}
Aresult
11
00
1542 croak "response transfer coding was not accepted by request TE: $coding"
1543 unless $preferences->{present}
1544 && $request_connection->{te}
1545 4 ▶ && $quality > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $preferences->{"present"} and $request_connection->{"te"} and $quality > 0 1 3 4
Condition50%3/6
$preferences->{"present"} and $request_connection->{"te"} and $quality > 0
!ll&&!rl&&r
013
$preferences->{"present"} and $request_connection->{"te"}
!ll&&!rl&&r
004
MC/DC33%1/3
$preferences->{"present"} and $request_connection->{"te"} and $quality > 0
$preferences->{"present"} $request_connection->{"te"} $quality > 0
Truth table50%2/4
A and B and C
A= $preferences->{"present"}B= $request_connection->{"te"}C= $quality > 0
ABCresult
0XX0
10X0
1100
1111
1546 }
1547 }
1548  
1549 42 ▶ if ($connect_switch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($connect_switch) 2 40 42
1550 2 ▶ croak 'successful CONNECT response must not contain Content-Length'
Branch: 1 branch
BranchTrueFalseTotal
if defined $cl 1 1 2
1551 if defined $cl;
1552 1 ▶ croak 'successful CONNECT response must not contain Transfer-Encoding'
Branch: 1 branch
BranchTrueFalseTotal
if @$te 0 1 1
1553 if @$te;
1554 1 my $connection = _connection_tokens($fields);
1555 croak 'successful CONNECT response cannot request Connection: close'
1556 1 ▶ if $connection->{close};
Branch: 1 branch
BranchTrueFalseTotal
if $connection->{"close"} 0 1 1
1557 }
1558  
1559 41 ▶ if ($upgrade_switch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($upgrade_switch) 9 32 41
1560 9 my $response_connection = _connection_tokens($fields);
1561 9 ▶ if (!$response_connection->{upgrade}
Branch: 1 branch
BranchTrueFalseTotal
unless ($response_connection->{"upgrade"} or @{_values($fields, "Connection");}) 4 5 9
Condition66%2/3
$response_connection->{"upgrade"} or @{_values($fields, "Connection");}
l!l&&r!l&&!r
504
MC/DC50%1/2
$response_connection->{"upgrade"} or @{_values($fields, "Connection");}
$response_connection->{"upgrade"} @{_values($fields, "Connection");}
Truth table66%2/3
A or B
A= $response_connection->{"upgrade"}B= @{_values($fields, "Connection");}
ABresult
1X1
011
000
1562 4 && !@{ _values($fields, 'Connection') }) {
1563 4 $fields = [ @$fields, [ 'Connection', 'Upgrade' ] ];
1564 }
1565 _validate_upgrade_response(
1566 9 $request,
1567 _fields($request, 'header', $request_view),
1568 $fields,
1569 $request_version,
1570 $request_view,
1571 );
1572 }
1573  
1574 39 my ($mode, $remaining, $close_after) = ('none', undef, 0);
1575 39 ▶ if ($body_forbidden) {
Branch: 6 branches
BranchTrueFalseTotal
if ($body_forbidden) { } 18 21 39
elsif ($head_only) { } 2 19 21
elsif (@$trailers) { } 1 18 19
elsif (@$te) { } 1 17 18
elsif (defined $cl) { } 0 17 17
elsif ($stream_body) { } 4 13 17
1576 18 ▶ croak '1xx and 204 responses must not contain Content-Length'
Branch: 1 branch
BranchTrueFalseTotal
if $status >= 100 && $status < 200 || $status == 204 and defined $cl 1 17 18
Condition88%8/9
$status >= 100 && $status < 200 || $status == 204 and defined $cl
!ll&&!rl&&r
2151
$status >= 100 and $status < 200 or $status == 204
l!l&&r!l&&!r
1062
$status >= 100 and $status < 200
!ll&&!rl&&r
0810
MC/DC50%2/4
$status >= 100 && $status < 200 || $status == 204 and defined $cl
$status >= 100 $status < 200 $status == 204 defined $cl
Truth table50%4/8
A and B or C and D
A= $status >= 100B= $status < 200C= $status == 204D= defined $cl
ABCDresult
0X0X0
100X0
11X00
0X100
10100
11X11
0X111
10111
1577 if (($status >= 100 && $status < 200) || $status == 204) && defined $cl;
1578 17 ▶ croak '205 response Content-Length must be zero'
Branch: 1 branch
BranchTrueFalseTotal
if $status == 205 and defined $cl and $cl != 0 0 17 17
Condition33%2/6
$status == 205 and defined $cl and $cl != 0
!ll&&!rl&&r
1700
$status == 205 and defined $cl
!ll&&!rl&&r
1700
MC/DC0%0/3
$status == 205 and defined $cl and $cl != 0
$status == 205 defined $cl $cl != 0
Truth table25%1/4
A and B and C
A= $status == 205B= defined $clC= $cl != 0
ABCresult
0XX0
10X0
1100
1111
1579 if $status == 205 && defined($cl) && $cl != 0;
1580 17 ▶ croak 'bodyless response must not contain Transfer-Encoding'
Branch: 1 branch
BranchTrueFalseTotal
if $status != 304 and @$te 0 17 17
Condition66%2/3
$status != 304 and @$te
!ll&&!rl&&r
1160
MC/DC0%0/2
$status != 304 and @$te
$status != 304 @$te
Truth table66%2/3
A and B
A= $status != 304B= @$te
ABresult
0X0
100
111
1581 if $status != 304 && @$te;
1582 17 ▶ croak 'HTTP/1.0 cannot send Transfer-Encoding metadata'
Branch: 1 branch
BranchTrueFalseTotal
if $status == 304 and @$te and $request_version eq "1.0" 0 17 17
Condition66%4/6
$status == 304 and @$te and $request_version eq "1.0"
!ll&&!rl&&r
1610
$status == 304 and @$te
!ll&&!rl&&r
1601
MC/DC0%0/3
$status == 304 and @$te and $request_version eq "1.0"
$status == 304 @$te $request_version eq "1.0"
Truth table50%2/4
A and B and C
A= $status == 304B= @$teC= $request_version eq "1.0"
ABCresult
0XX0
10X0
1100
1111
1583 if $status == 304 && @$te && $request_version eq '1.0';
1584 } elsif ($head_only) {
1585 2 ▶ croak 'HEAD response cannot stream a body' if $stream_body;
Branch: 1 branch
BranchTrueFalseTotal
if $stream_body 0 2 2
1586 2 ▶ croak 'HEAD response cannot carry trailer fields' if @$trailers;
Branch: 1 branch
BranchTrueFalseTotal
if @$trailers 0 2 2
1587 2 ▶ croak 'HTTP/1.0 cannot send Transfer-Encoding metadata'
Branch: 1 branch
BranchTrueFalseTotal
if @$te and $request_version eq "1.0" 0 2 2
Condition66%2/3
@$te and $request_version eq "1.0"
!ll&&!rl&&r
110
MC/DC0%0/2
@$te and $request_version eq "1.0"
@$te $request_version eq "1.0"
Truth table66%2/3
A and B
A= @$teB= $request_version eq "1.0"
ABresult
0X0
100
111
1588 if @$te && $request_version eq '1.0';
1589 2 ▶ if (!defined $cl && !@$te && defined $body) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $cl || @$te and defined $body) 1 1 2
Condition66%4/6
not defined $cl || @$te and defined $body
!ll&&!rl&&r
101
defined $cl || @$te
l!l&&r!l&&!r
011
MC/DC33%1/3
not defined $cl || @$te and defined $body
defined $cl @$te defined $body
Truth table50%2/4
not(A || B) and C
A= defined $clB= @$teC= defined $body
ABCresult
1XX0
01X0
0000
0011
1590 1 $fields = [ @$fields, [ 'Content-Length', length($body) ] ];
1591 }
1592 } elsif (@$trailers) {
1593 1 ▶ croak 'HTTP/1.0 cannot send trailer fields' if $request_version eq '1.0';
Branch: 1 branch
BranchTrueFalseTotal
if $request_version eq "1.0" 0 1 1
1594 1 ▶ croak 'trailers cannot be combined with Content-Length' if defined $cl;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cl 0 1 1
1595  
1596 1 ▶ if (@$te) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$te) { } 0 1 1
1597 0 my $has_chunked = grep { $_ eq 'chunked' } @$te;
1598 0 ▶ croak 'cannot add final chunked framing after an earlier chunked transfer coding'
Branch: 1 branch
BranchTrueFalseTotal
if $has_chunked and $te->[-1] ne "chunked" 0 0 0
Condition0%0/3
$has_chunked and $te->[-1] ne "chunked"
!ll&&!rl&&r
000
MC/DC0%0/2
$has_chunked and $te->[-1] ne "chunked"
$has_chunked $te->[-1] ne "chunked"
Truth table0%0/3
A and B
A= $has_chunkedB= $te->[-1] ne "chunked"
ABresult
0X0
100
111
1599 if $has_chunked && $te->[-1] ne 'chunked';
1600 0 ▶ if ($te->[-1] ne 'chunked') {
Branch: 1 branch
BranchTrueFalseTotal
if ($te->[-1] ne "chunked") 0 0 0
1601 0 $fields = _append_transfer_coding($fields, 'chunked');
1602 }
1603 } else {
1604 1 $fields = [ @$fields, [ 'Transfer-Encoding', 'chunked' ] ];
1605 }
1606 1 $mode = 'chunked';
1607 } elsif (@$te) {
1608 1 ▶ croak 'HTTP/1.0 does not support Transfer-Encoding'
Branch: 1 branch
BranchTrueFalseTotal
if $request_version eq "1.0" 0 1 1
1609 if $request_version eq '1.0';
1610 1 ▶ if ($te->[-1] eq 'chunked') {
Branch: 1 branch
BranchTrueFalseTotal
if ($te->[-1] eq 'chunked') { } 1 0 1
1611 1 $mode = 'chunked';
1612 } else {
1613 0 $mode = 'close';
1614 0 $close_after = 1;
1615 }
1616 } elsif (defined $cl) {
1617 0 $mode = 'content-length';
1618 0 $remaining = $cl;
1619 0 ▶ croak 'response Content-Length does not match buffered body length'
Branch: 1 branch
BranchTrueFalseTotal
if defined $body and length $body != $cl 0 0 0
Condition0%0/3
defined $body and length $body != $cl
!ll&&!rl&&r
000
MC/DC0%0/2
defined $body and length $body != $cl
defined $body length $body != $cl
Truth table0%0/3
A and B
A= defined $bodyB= length $body != $cl
ABresult
0X0
100
111
1620 if defined($body) && length($body) != $cl;
1621 } elsif ($stream_body) {
1622 4 ▶ if ($request_version eq '1.1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($request_version eq '1.1') { } 3 1 4
1623 3 $fields = [ @$fields, [ 'Transfer-Encoding', 'chunked' ] ];
1624 3 $mode = 'chunked';
1625 } else {
1626 1 $mode = 'close';
1627 1 $close_after = 1;
1628 }
1629 } else {
1630 13 ▶ my $length = defined($body) ? length($body) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $body ? : 12 1 13
1631 13 $fields = [ @$fields, [ 'Content-Length', $length ] ];
1632 13 $mode = 'content-length';
1633 13 $remaining = $length;
1634 }
1635  
1636 38 my $request_tokens =
1637 _connection_tokens(_fields($request, 'header', $request_view));
1638 38 my $response_tokens = _connection_tokens($fields);
1639 my $request_keep = $request_tokens->{close} ? 0
1640 : $request_version eq '1.1' ? 1
1641 37 ▶ : $request_tokens->{'keep-alive'} ? 1 : 0;
Branch: 3 branches
BranchTrueFalseTotal
$request_tokens->{'close'} ? : 8 29 37
$request_version eq '1.1' ? : 24 5 29
$request_tokens->{'keep-alive'} ? : 2 3 5
1642 my $keep_alive =
1643 37 ▶ $request_keep && !$response_tokens->{close} && !$close_after && !$switch;
Condition88%8/9
$request_keep && !$response_tokens->{'close'} && !$close_after && !$switch
!ll&&!rl&&r
12817
$request_keep and not $response_tokens->{"close"} and not $close_after
!ll&&!rl&&r
11125
$request_keep and not $response_tokens->{"close"}
!ll&&!rl&&r
11026
MC/DC75%3/4
$request_keep && !$response_tokens->{'close'} && !$close_after && !$switch
$request_keep not $response_tokens->{"close"} not $close_after !$switch
Truth table80%4/5
A and not(B) and not(C) && not(D)
A= $request_keepB= not $response_tokens->{"close"}C= not $close_afterD= !$switch
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1644 37 ▶ if (!$keep_alive && !$switch && $request_version eq '1.1'
Branch: 2 branches
BranchTrueFalseTotal
if (not $keep_alive || $switch and $request_version eq '1.1' and not $response_tokens->{'close'}) { } 8 29 37
elsif ($keep_alive and $request_version eq '1.0' and not $response_tokens->{'keep-alive'}) { } 1 56 57
Condition88%8/9
not $keep_alive || $switch and $request_version eq "1.1" and not $response_tokens->{"close"}
!ll&&!rl&&r
2908
not $keep_alive || $switch and $request_version eq "1.1"
!ll&&!rl&&r
2548
$keep_alive || $switch
l!l&&r!l&&!r
17812
MC/DC75%3/4
not $keep_alive || $switch and $request_version eq "1.1" and not $response_tokens->{"close"}
$keep_alive $switch $request_version eq "1.1" not $response_tokens->{"close"}
Truth table80%4/5
not(A || B) and C and not(D)
A= $keep_aliveB= $switchC= $request_version eq "1.1"D= not $response_tokens->{"close"}
ABCDresult
1XXX0
01XX0
000X0
00100
00111
1645 && !$response_tokens->{close}) {
1646 8 $fields = [ @$fields, [ 'Connection', 'close' ] ];
1647 ▶ } elsif ($keep_alive && $request_version eq '1.0'
Condition83%5/6
$keep_alive and $request_version eq "1.0" and not $response_tokens->{"keep-alive"}
!ll&&!rl&&r
2801
$keep_alive and $request_version eq "1.0"
!ll&&!rl&&r
12161
MC/DC66%2/3
$keep_alive and $request_version eq "1.0" and not $response_tokens->{"keep-alive"}
$keep_alive $request_version eq "1.0" not $response_tokens->{"keep-alive"}
Truth table75%3/4
A and B and not(C)
A= $keep_aliveB= $request_version eq "1.0"C= not $response_tokens->{"keep-alive"}
ABCresult
0XX0
10X0
1100
1111
1648 && !$response_tokens->{'keep-alive'}) {
1649 1 $fields = [ @$fields, [ 'Connection', 'keep-alive' ] ];
1650 }
1651  
1652 37 my $wire = 'HTTP/' . $request_version . ' ' . sprintf('%03d', $status)
1653 . ' ' . $reason . "\r\n" . _serialize_fields($fields) . "\r\n";
1654  
1655 37 ▶ if (!$head_only && !$body_forbidden && defined $body) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $head_only || $body_forbidden and defined $body) { } 14 23 37
elsif (not $head_only || $body_forbidden || $stream_body and $mode eq 'chunked') { } 0 46 46
Condition100%6/6
not $head_only || $body_forbidden and defined $body
!ll&&!rl&&r
19414
$head_only || $body_forbidden
l!l&&r!l&&!r
21718
MC/DC100%3/3
not $head_only || $body_forbidden and defined $body
$head_only $body_forbidden defined $body
Truth table100%4/4
not(A || B) and C
A= $head_onlyB= $body_forbiddenC= defined $body
ABCresult
1XX0
01X0
0000
0011
1656 14 ▶ $wire .= $mode eq 'chunked'
Branch: 1 branch
BranchTrueFalseTotal
$mode eq 'chunked' ? : 2 12 14
1657 ? chunk($body) . final_chunk($trailers)
1658 : $body;
1659 14 ▶ $remaining = 0 if defined $remaining;
Branch: 1 branch
BranchTrueFalseTotal
if defined $remaining 12 2 14
1660 ▶ } elsif (!$head_only && !$body_forbidden && !$stream_body
Condition66%6/9
not $head_only || $body_forbidden || $stream_body and $mode eq "chunked"
!ll&&!rl&&r
2300
$head_only || $body_forbidden || $stream_body
l!l&&r!l&&!r
1940
$head_only or $body_forbidden
l!l&&r!l&&!r
2174
MC/DC0%0/4
not $head_only || $body_forbidden || $stream_body and $mode eq "chunked"
$head_only $body_forbidden $stream_body $mode eq "chunked"
Truth table60%3/5
not(A or B || C) and D
A= $head_onlyB= $body_forbiddenC= $stream_bodyD= $mode eq "chunked"
ABCDresult
1XXX0
01XX0
001X0
00000
00011
1661 && $mode eq 'chunked') {
1662 0 $wire .= final_chunk($trailers);
1663 }
1664  
1665 return {
1666 37 ▶ wire => $wire,
Branch: 1 branch
BranchTrueFalseTotal
$stream_body ? : 4 33 37
1667 version => $request_version,
1668 mode => $mode,
1669 remaining => $remaining,
1670 stream_body => $stream_body,
1671 trailers => $trailers,
1672 keep_alive => $keep_alive,
1673 close_after => $close_after,
1674 switch => $switch,
1675 body_finalized => $stream_body ? 0 : 1,
1676 };
1677 }
1678  
1679 16 ▶sub chunk {
Subroutine chunk: called CC=2 SCAR=6.9
Pod undocumented
1680 16 my ($bytes) = @_;
1681 16 $bytes = _bytes('body chunk', $bytes);
1682 16 ▶ return '' unless length $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless length $bytes 5 11 16
1683 11 return sprintf('%X', length($bytes)) . "\r\n" . $bytes . "\r\n";
1684 }
1685  
1686 8 ▶sub final_chunk {
Subroutine final_chunk: called CC=8 SCAR=25.4
Pod undocumented
1687 8 my ($trailers) = @_;
1688 8 ▶ $trailers ||= [];
Condition50%1/2
$trailers ||= []
l!l
80
MC/DC0%0/1
$trailers ||= []
$trailers
Truth table50%1/2
A
A= $trailers
Aresult
11
00
1689 8 my $wire = "0\r\n";
1690 8 for my $field (@$trailers) {
1691 2 my $key = _lc($field->[0]);
1692 2 ▶ croak 'framing fields are forbidden in HTTP/1 trailers'
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "content-length" or $key eq "transfer-encoding" or $key eq "host" or $key eq "connection" or $key eq "trailer" 0 2 2
Condition33%4/12
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "host" or $key eq "connection" or $key eq "trailer"
l!l&&r!l&&!r
002
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "host" or $key eq "connection"
l!l&&r!l&&!r
002
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "host"
l!l&&r!l&&!r
002
$key eq "content-length" or $key eq "transfer-encoding"
l!l&&r!l&&!r
002
MC/DC0%0/5
$key eq "content-length" or $key eq "transfer-encoding" or $key eq "host" or $key eq "connection" or $key eq "trailer"
$key eq "content-length" $key eq "transfer-encoding" $key eq "host" $key eq "connection" $key eq "trailer"
Truth table16%1/6
A or B or C or D or E
A= $key eq "content-length"B= $key eq "transfer-encoding"C= $key eq "host"D= $key eq "connection"E= $key eq "trailer"
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1693 if $key eq 'content-length' || $key eq 'transfer-encoding'
1694 || $key eq 'host' || $key eq 'connection' || $key eq 'trailer';
1695 2 $wire .= $field->[0] . ': ' . $field->[1] . "\r\n";
1696 }
1697 8 return $wire . "\r\n";
1698 }
1699  
1700 35 1;
↑ Summary blib/lib/Unblock/HTTP1/Client.pm »