blib/lib/Unblock/HTTP1/_Wire.pm

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