blib/lib/Unblock/HTTP2/_Headers.pm

filter: Statementstmt 92.4% 184 / 199 Branchbran 58.3% 77 / 132 Conditioncond 34.2% 36 / 105 MC/DCmcdc 3.2% 2 / 62 Subroutinesub 91.6% 22 / 24 Podpod 0.0% 0 / 8 totaltotal 60.5% 321 / 530 CC 109 SCAR 33.0
CC
109
Cov
68%
request_from_headers
60.1
_validate_request_value
42.1
request_headers
32.5
CRAP 27.1
« blib/lib/Unblock/HTTP2/Client.pm ↑ Summary blib/lib/Unblock/HTTP2/Server.pm »
1 package Unblock::HTTP2::_Headers;
2  
3 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 29 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 29 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 29 ▶use Uniform::HTTP::FastPath 0.06 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 29 ▶use Uniform::HTTP::Request 0.06;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 29 ▶use Uniform::HTTP::Response 0.06;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 29 our $VERSION = '0.11';
13  
14 29 my %FORBIDDEN = map { $_ => 1 } qw(
15 connection
16 keep-alive
17 proxy-connection
18 transfer-encoding
19 upgrade
20 );
21  
22 29 my $TOKEN_RE = qr/\A[!\#\$%&'*+\-.\^_`|~0-9A-Za-z]+\z/;
23  
24 67 ▶sub native_message {
Subroutine native_message: called CC=2 SCAR=6.9
Pod undocumented
25 67 my ($class, $message) = @_;
26 67 ▶ return unless Uniform::HTTP::FastPath::can_view($message);
Branch: 1 branch
BranchTrueFalseTotal
unless Uniform::HTTP::FastPath::can_view($message) 1 66 67
27 66 return $message;
28 }
29  
30 5 ▶sub _received_flags {
Subroutine _received_flags: called CC=3 SCAR=11.0
31 5 my ($kind, $end_stream) = @_;
32  
33 5 my $flags =
34 Uniform::HTTP::FastPath::FLAG_HEADERS_LOSSLESS()
35 | Uniform::HTTP::FastPath::FLAG_TRAILERS_LOSSLESS();
36  
37 5 ▶ $flags |= Uniform::HTTP::FastPath::FLAG_TARGET_EXACT()
Branch: 1 branch
BranchTrueFalseTotal
if $kind == 1 3 2 5
38 if $kind == Uniform::HTTP::FastPath::KIND_REQUEST();
39  
40 5 ▶ if ($end_stream) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end_stream) { } 3 2 5
41 3 $flags |= Uniform::HTTP::FastPath::FLAG_COMPLETE();
42 }
43 else {
44 2 $flags |= Uniform::HTTP::FastPath::FLAG_MUTABLE()
45 | Uniform::HTTP::FastPath::FLAG_BODY_MUTABLE()
46 | Uniform::HTTP::FastPath::FLAG_TRAILERS_MUTABLE();
47 }
48  
49 5 return $flags;
50 }
51  
52 13 ▶sub _validate_request_value {
Subroutine _validate_request_value: called CC=20 SCAR=37.4
53 13 my ($operation, $name, $value) = @_;
54  
55 13 ▶ if ($name eq 'method' || $name eq 'protocol') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "method" or $name eq "protocol") 4 9 13
Condition100%3/3
$name eq "method" or $name eq "protocol"
l!l&&r!l&&!r
319
MC/DC100%2/2
$name eq "method" or $name eq "protocol"
$name eq "method" $name eq "protocol"
Truth table100%3/3
A or B
A= $name eq "method"B= $name eq "protocol"
ABresult
1X1
011
000
56 4 ▶ croak "$operation: $name must be an HTTP token"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and not ref $value and $value =~ /$TOKEN_RE/ 0 4 4
Condition33%2/6
defined $value and not ref $value and $value =~ /$TOKEN_RE/
!ll&&!rl&&r
004
defined $value and not ref $value
!ll&&!rl&&r
004
MC/DC0%0/3
defined $value and not ref $value and $value =~ /$TOKEN_RE/
defined $value not ref $value $value =~ /$TOKEN_RE/
Truth table25%1/4
A and not(B) and C
A= defined $valueB= not ref $valueC= $value =~ /$TOKEN_RE/
ABCresult
0XX0
10X0
1100
1111
57 unless defined($value) && !ref($value) && $value =~ $TOKEN_RE;
58 4 return;
59 }
60  
61 9 ▶ if ($name eq 'target') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "target") 3 6 9
62 3 ▶ croak "$operation: target must not be empty"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and not ref $value and length $value 0 3 3
Condition33%2/6
defined $value and not ref $value and length $value
!ll&&!rl&&r
003
defined $value and not ref $value
!ll&&!rl&&r
003
MC/DC0%0/3
defined $value and not ref $value and length $value
defined $value not ref $value length $value
Truth table25%1/4
A and not(B) and C
A= defined $valueB= not ref $valueC= length $value
ABCresult
0XX0
10X0
1100
1111
63 unless defined($value) && !ref($value) && length($value);
64 3 ▶ croak "$operation: target contains spaces or control bytes"
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /[\x00-\x20\x7f]/ 0 3 3
65 if $value =~ /[\x00-\x20\x7f]/;
66 3 return;
67 }
68  
69 6 ▶ if ($name eq 'scheme') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "scheme") 3 3 6
70 3 ▶ croak "$operation: scheme must be a valid URI scheme"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and not ref $value and $value =~ /\A[A-Za-z][A-Za-z0-9+.-]*\z/ 0 3 3
Condition33%2/6
defined $value and not ref $value and $value =~ /\A[A-Za-z][A-Za-z0-9+.-]*\z/
!ll&&!rl&&r
003
defined $value and not ref $value
!ll&&!rl&&r
003
MC/DC0%0/3
defined $value and not ref $value and $value =~ /\A[A-Za-z][A-Za-z0-9+.-]*\z/
defined $value not ref $value $value =~ /\A[A-Za-z][A-Za-z0-9+.-]*\z/
Truth table25%1/4
A and not(B) and C
A= defined $valueB= not ref $valueC= $value =~ /\A[A-Za-z][A-Za-z0-9+.-]*\z/
ABCresult
0XX0
10X0
1100
1111
71 unless defined($value) && !ref($value)
72 && $value =~ /\A[A-Za-z][A-Za-z0-9+.-]*\z/;
73 3 return;
74 }
75  
76 3 ▶ if ($name eq 'authority') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "authority") 3 0 3
77 3 ▶ croak "$operation: authority must not be empty"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and not ref $value and length $value 0 3 3
Condition33%2/6
defined $value and not ref $value and length $value
!ll&&!rl&&r
003
defined $value and not ref $value
!ll&&!rl&&r
003
MC/DC0%0/3
defined $value and not ref $value and length $value
defined $value not ref $value length $value
Truth table25%1/4
A and not(B) and C
A= defined $valueB= not ref $valueC= length $value
ABCresult
0XX0
10X0
1100
1111
78 unless defined($value) && !ref($value) && length($value);
79 3 ▶ croak "$operation: authority contains a prohibited delimiter or control byte"
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ m[[\x00-\x20\x7f/?#]] 0 3 3
80 if $value =~ /[\x00-\x20\x7f\/?#]/;
81 3 return;
82 }
83  
84 0 croak "$operation: unknown request value '$name'";
85 }
86  
87 13 ▶sub _pairs {
Subroutine _pairs: called CC=9 SCAR=28.2
88 13 my ($operation, $pairs) = @_;
89  
90 13 ▶ croak "$operation: header block must be an array reference"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pairs eq "ARRAY" 0 13 13
91 unless ref($pairs) eq 'ARRAY';
92  
93 13 for my $pair (@$pairs) {
94 43 ▶ croak "$operation: each field must be a [name, value] pair"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pair eq "ARRAY" and @$pair == 2 0 43 43
Condition33%1/3
ref $pair eq "ARRAY" and @$pair == 2
!ll&&!rl&&r
0043
MC/DC0%0/2
ref $pair eq "ARRAY" and @$pair == 2
ref $pair eq "ARRAY" @$pair == 2
Truth table33%1/3
A and B
A= ref $pair eq "ARRAY"B= @$pair == 2
ABresult
0X0
100
111
95 unless ref($pair) eq 'ARRAY' && @$pair == 2;
96 43 ▶ croak "$operation: field name and value must be defined scalars"
Branch: 1 branch
BranchTrueFalseTotal
if not defined $pair->[0] or ref $pair->[0] or not defined $pair->[1] or ref $pair->[1] 0 43 43
Condition33%3/9
not defined $pair->[0] or ref $pair->[0] or not defined $pair->[1] or ref $pair->[1]
l!l&&r!l&&!r
0043
not defined $pair->[0] or ref $pair->[0] or not defined $pair->[1]
l!l&&r!l&&!r
0043
not defined $pair->[0] or ref $pair->[0]
l!l&&r!l&&!r
0043
MC/DC0%0/4
not defined $pair->[0] or ref $pair->[0] or not defined $pair->[1] or ref $pair->[1]
not defined $pair->[0] ref $pair->[0] not defined $pair->[1] ref $pair->[1]
Truth table20%1/5
not(A) or B or not(C) or D
A= not defined $pair->[0]B= ref $pair->[0]C= not defined $pair->[1]D= ref $pair->[1]
ABCDresult
1XXX1
01XX1
001X1
00011
00000
97 if !defined($pair->[0]) || ref($pair->[0])
98 || !defined($pair->[1]) || ref($pair->[1]);
99 }
100  
101 13 return $pairs;
102 }
103  
104 25 ▶sub _check_normal_field {
Subroutine _check_normal_field: called CC=7 SCAR=20.5
105 25 my ($operation, $name, $value) = @_;
106  
107 25 ▶ croak "$operation: HTTP/2 field names must be lowercase"
Branch: 1 branch
BranchTrueFalseTotal
unless $name eq lc $name 1 24 25
108 unless $name eq lc $name;
109 24 ▶ croak "$operation: field name must be an HTTP token"
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /$TOKEN_RE/ 0 24 24
110 unless $name =~ $TOKEN_RE;
111 24 ▶ croak "$operation: field value contains a prohibited control byte"
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /[\x00-\x08\x0a-\x1f\x7f]/ 0 24 24
112 if $value =~ /[\x00-\x08\x0a-\x1f\x7f]/;
113  
114 croak "$operation: HTTP/2 forbids connection-specific field '$name'"
115 24 ▶ if $FORBIDDEN{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $FORBIDDEN{$name} 1 23 24
116  
117 23 ▶ croak "$operation: HTTP/2 TE is limited to trailers"
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "te" and lc $value ne "trailers" 0 23 23
Condition33%1/3
$name eq "te" and lc $value ne "trailers"
!ll&&!rl&&r
2300
MC/DC0%0/2
$name eq "te" and lc $value ne "trailers"
$name eq "te" lc $value ne "trailers"
Truth table33%1/3
A and B
A= $name eq "te"B= lc $value ne "trailers"
ABresult
0X0
100
111
118 if $name eq 'te' && lc($value) ne 'trailers';
119  
120 23 return;
121 }
122  
123 10 ▶sub _normal_field {
Subroutine _normal_field: called CC=1 SCAR=0.0
124 10 my ($operation, $name, $value) = @_;
125 10 _check_normal_field($operation, $name, $value);
126 10 return [ $name, $value ];
127 }
128  
129 13 ▶sub _split_header_block {
Subroutine _split_header_block: called CC=6 SCAR=18.0
130 13 my ($operation, $pairs, $allowed) = @_;
131 13 _pairs($operation, $pairs);
132  
133 13 my %pseudo;
134 my @normal;
135 13 my $saw_normal = 0;
136  
137 13 for my $pair (@$pairs) {
138 43 my ($name, $value) = @$pair;
139  
140 43 ▶ if (substr($name, 0, 1) eq ':') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($name, 0, 1) eq ":") 28 15 43
141 28 ▶ croak "$operation: pseudo-header follows a regular field"
Branch: 1 branch
BranchTrueFalseTotal
if $saw_normal 0 28 28
142 if $saw_normal;
143 croak "$operation: unsupported pseudo-header '$name'"
144 28 ▶ unless $allowed->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $allowed->{$name} 0 28 28
145 croak "$operation: duplicate pseudo-header '$name'"
146 28 ▶ if exists $pseudo{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $pseudo{$name} 0 28 28
147 28 $pseudo{$name} = $value;
148 28 next;
149 }
150  
151 15 $saw_normal = 1;
152 15 _check_normal_field($operation, $name, $value);
153 13 push @normal, $pair;
154 }
155  
156 11 return (\%pseudo, \@normal);
157 }
158  
159 6 ▶sub request_from_headers {
Subroutine request_from_headers: called CC=26 SCAR=41.0
Pod undocumented
160 6 my ($class, $pairs, %option) = @_;
161  
162 6 ▶ my $end_stream = delete($option{end_stream}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $option{'end_stream'} ? : 4 2 6
163 6 ▶ croak 'request_from_headers(): unknown options: '
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 6 6
164 . join(', ', sort keys %option)
165 if %option;
166  
167 6 my ($pseudo, $normal) = _split_header_block(
168 'request_from_headers()',
169 $pairs,
170 {
171 ':method' => 1,
172 ':scheme' => 1,
173 ':authority' => 1,
174 ':path' => 1,
175 ':protocol' => 1,
176 },
177 );
178  
179 4 my $method = $pseudo->{':method'};
180 4 ▶ croak 'request_from_headers(): missing :method'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $method and length $method 0 4 4
Condition33%1/3
defined $method and length $method
!ll&&!rl&&r
004
MC/DC0%0/2
defined $method and length $method
defined $method length $method
Truth table33%1/3
A and B
A= defined $methodB= length $method
ABresult
0X0
100
111
181 unless defined($method) && length($method);
182  
183 4 my ($target, $scheme, $authority, $protocol);
184  
185 4 ▶ if (uc($method) eq 'CONNECT') {
Branch: 1 branch
BranchTrueFalseTotal
if (uc $method eq 'CONNECT') { } 1 3 4
186 croak 'request_from_headers(): CONNECT requires :authority'
187 unless defined($pseudo->{':authority'})
188 1 ▶ && length($pseudo->{':authority'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pseudo->{":authority"} and length $pseudo->{":authority"} 0 1 1
Condition33%1/3
defined $pseudo->{":authority"} and length $pseudo->{":authority"}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $pseudo->{":authority"} and length $pseudo->{":authority"}
defined $pseudo->{":authority"} length $pseudo->{":authority"}
Truth table33%1/3
A and B
A= defined $pseudo->{":authority"}B= length $pseudo->{":authority"}
ABresult
0X0
100
111
189  
190 1 $authority = $pseudo->{':authority'};
191  
192 1 ▶ if (exists $pseudo->{':protocol'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pseudo->{':protocol'}) { } 1 0 1
193 1 $protocol = $pseudo->{':protocol'};
194 1 ▶ croak 'request_from_headers(): extended CONNECT requires nonempty :protocol'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $protocol and length $protocol 0 1 1
Condition33%1/3
defined $protocol and length $protocol
!ll&&!rl&&r
001
MC/DC0%0/2
defined $protocol and length $protocol
defined $protocol length $protocol
Truth table33%1/3
A and B
A= defined $protocolB= length $protocol
ABresult
0X0
100
111
195 unless defined($protocol) && length($protocol);
196 croak 'request_from_headers(): extended CONNECT requires :scheme'
197 unless defined($pseudo->{':scheme'})
198 1 ▶ && length($pseudo->{':scheme'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pseudo->{":scheme"} and length $pseudo->{":scheme"} 0 1 1
Condition33%1/3
defined $pseudo->{":scheme"} and length $pseudo->{":scheme"}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $pseudo->{":scheme"} and length $pseudo->{":scheme"}
defined $pseudo->{":scheme"} length $pseudo->{":scheme"}
Truth table33%1/3
A and B
A= defined $pseudo->{":scheme"}B= length $pseudo->{":scheme"}
ABresult
0X0
100
111
199 croak 'request_from_headers(): extended CONNECT requires :path'
200 unless defined($pseudo->{':path'})
201 1 ▶ && length($pseudo->{':path'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pseudo->{":path"} and length $pseudo->{":path"} 0 1 1
Condition33%1/3
defined $pseudo->{":path"} and length $pseudo->{":path"}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $pseudo->{":path"} and length $pseudo->{":path"}
defined $pseudo->{":path"} length $pseudo->{":path"}
Truth table33%1/3
A and B
A= defined $pseudo->{":path"}B= length $pseudo->{":path"}
ABresult
0X0
100
111
202  
203 1 $scheme = $pseudo->{':scheme'};
204 1 $target = $pseudo->{':path'};
205 }
206 else {
207 croak 'request_from_headers(): ordinary CONNECT must omit :scheme and :path'
208 0 ▶ if exists($pseudo->{':scheme'}) || exists($pseudo->{':path'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $pseudo->{":scheme"} or exists $pseudo->{":path"} 0 0 0
Condition0%0/3
exists $pseudo->{":scheme"} or exists $pseudo->{":path"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $pseudo->{":scheme"} or exists $pseudo->{":path"}
exists $pseudo->{":scheme"} exists $pseudo->{":path"}
Truth table0%0/3
A or B
A= exists $pseudo->{":scheme"}B= exists $pseudo->{":path"}
ABresult
1X1
011
000
209 0 $target = $authority;
210 }
211 }
212 else {
213 croak 'request_from_headers(): :protocol requires CONNECT'
214 3 ▶ if exists $pseudo->{':protocol'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $pseudo->{":protocol"} 1 2 3
215 croak 'request_from_headers(): missing :scheme'
216 unless defined($pseudo->{':scheme'})
217 2 ▶ && length($pseudo->{':scheme'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pseudo->{":scheme"} and length $pseudo->{":scheme"} 0 2 2
Condition33%1/3
defined $pseudo->{":scheme"} and length $pseudo->{":scheme"}
!ll&&!rl&&r
002
MC/DC0%0/2
defined $pseudo->{":scheme"} and length $pseudo->{":scheme"}
defined $pseudo->{":scheme"} length $pseudo->{":scheme"}
Truth table33%1/3
A and B
A= defined $pseudo->{":scheme"}B= length $pseudo->{":scheme"}
ABresult
0X0
100
111
218 croak 'request_from_headers(): missing :path'
219 unless defined($pseudo->{':path'})
220 2 ▶ && length($pseudo->{':path'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pseudo->{":path"} and length $pseudo->{":path"} 0 2 2
Condition33%1/3
defined $pseudo->{":path"} and length $pseudo->{":path"}
!ll&&!rl&&r
002
MC/DC0%0/2
defined $pseudo->{":path"} and length $pseudo->{":path"}
defined $pseudo->{":path"} length $pseudo->{":path"}
Truth table33%1/3
A and B
A= defined $pseudo->{":path"}B= length $pseudo->{":path"}
ABresult
0X0
100
111
221 croak 'request_from_headers(): missing :authority'
222 unless defined($pseudo->{':authority'})
223 2 ▶ && length($pseudo->{':authority'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pseudo->{":authority"} and length $pseudo->{":authority"} 0 2 2
Condition33%1/3
defined $pseudo->{":authority"} and length $pseudo->{":authority"}
!ll&&!rl&&r
002
MC/DC0%0/2
defined $pseudo->{":authority"} and length $pseudo->{":authority"}
defined $pseudo->{":authority"} length $pseudo->{":authority"}
Truth table33%1/3
A and B
A= defined $pseudo->{":authority"}B= length $pseudo->{":authority"}
ABresult
0X0
100
111
224  
225 2 $scheme = $pseudo->{':scheme'};
226 2 $authority = $pseudo->{':authority'};
227 2 $target = $pseudo->{':path'};
228 }
229  
230 3 _validate_request_value('request_from_headers()', 'method', $method);
231 3 _validate_request_value('request_from_headers()', 'target', $target);
232 3 _validate_request_value('request_from_headers()', 'authority', $authority);
233 3 ▶ _validate_request_value('request_from_headers()', 'scheme', $scheme)
Branch: 1 branch
BranchTrueFalseTotal
if defined $scheme 3 0 3
234 if defined $scheme;
235 3 ▶ _validate_request_value('request_from_headers()', 'protocol', $protocol)
Branch: 1 branch
BranchTrueFalseTotal
if defined $protocol 1 2 3
236 if defined $protocol;
237  
238 3 my $view = [
239 Uniform::HTTP::FastPath::ABI_VERSION(),
240 Uniform::HTTP::FastPath::KIND_REQUEST(),
241 _received_flags(
242 Uniform::HTTP::FastPath::KIND_REQUEST(),
243 $end_stream,
244 ),
245 '2',
246 $method,
247 $target,
248 $scheme,
249 $authority,
250 $protocol,
251 undef,
252 undef,
253 $normal,
254 [],
255 undef,
256 ];
257  
258 3 return Uniform::HTTP::FastPath::request_from_validated($view);
259 }
260  
261 2 ▶sub response_from_headers {
Subroutine response_from_headers: called CC=8 SCAR=24.5
Pod undocumented
262 2 my ($class, $pairs, %option) = @_;
263  
264 2 ▶ my $end_stream = delete($option{end_stream}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $option{'end_stream'} ? : 2 0 2
265 2 ▶ croak 'response_from_headers(): unknown options: '
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 2 2
266 . join(', ', sort keys %option)
267 if %option;
268  
269 2 my ($pseudo, $normal) = _split_header_block(
270 'response_from_headers()',
271 $pairs,
272 { ':status' => 1 },
273 );
274  
275 2 my $status = $pseudo->{':status'};
276 2 ▶ croak 'response_from_headers(): missing :status'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status and length $status 0 2 2
Condition33%1/3
defined $status and length $status
!ll&&!rl&&r
002
MC/DC0%0/2
defined $status and length $status
defined $status length $status
Truth table33%1/3
A and B
A= defined $statusB= length $status
ABresult
0X0
100
111
277 unless defined($status) && length($status);
278  
279 2 ▶ croak 'response_from_headers(): status must be an integer from 100 through 599'
Branch: 1 branch
BranchTrueFalseTotal
unless $status =~ /\A[0-9]+\z/ and $status >= 100 and $status <= 599 0 2 2
Condition33%2/6
$status =~ /\A[0-9]+\z/ and $status >= 100 and $status <= 599
!ll&&!rl&&r
002
$status =~ /\A[0-9]+\z/ and $status >= 100
!ll&&!rl&&r
002
MC/DC0%0/3
$status =~ /\A[0-9]+\z/ and $status >= 100 and $status <= 599
$status =~ /\A[0-9]+\z/ $status >= 100 $status <= 599
Truth table25%1/4
A and B and C
A= $status =~ /\A[0-9]+\z/B= $status >= 100C= $status <= 599
ABCresult
0XX0
10X0
1100
1111
280 unless $status =~ /\A[0-9]+\z/
281 && $status >= 100
282 && $status <= 599;
283  
284 2 my $view = [
285 Uniform::HTTP::FastPath::ABI_VERSION(),
286 Uniform::HTTP::FastPath::KIND_RESPONSE(),
287 _received_flags(
288 Uniform::HTTP::FastPath::KIND_RESPONSE(),
289 $end_stream,
290 ),
291 '2',
292 undef,
293 undef,
294 undef,
295 undef,
296 undef,
297 0 + $status,
298 undef,
299 $normal,
300 [],
301 undef,
302 ];
303  
304 2 return Uniform::HTTP::FastPath::response_from_validated($view);
305 }
306  
307 5 ▶sub apply_trailers {
Subroutine apply_trailers: called CC=5 SCAR=17.8
Pod undocumented
308 5 my ($class, $message, $pairs) = @_;
309  
310 5 ▶ croak 'apply_trailers(): requires a canonical Uniform HTTP message'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($message) and $message->can("add_trailer") and $message->can("freeze_trailers") 0 5 5
Condition33%2/6
builtin::blessed($message) and $message->can("add_trailer") and $message->can("freeze_trailers")
!ll&&!rl&&r
005
builtin::blessed($message) and $message->can("add_trailer")
!ll&&!rl&&r
005
MC/DC0%0/3
builtin::blessed($message) and $message->can("add_trailer") and $message->can("freeze_trailers")
builtin::blessed($message) $message->can("add_trailer") $message->can("freeze_trailers")
Truth table25%1/4
A and B and C
A= builtin::blessed($message)B= $message->can("add_trailer")C= $message->can("freeze_trailers")
ABCresult
0XX0
10X0
1100
1111
311 unless blessed($message)
312 && $message->can('add_trailer')
313 && $message->can('freeze_trailers');
314  
315 5 my ($pseudo, $normal) = _split_header_block(
316 'apply_trailers()',
317 $pairs,
318 {},
319 );
320  
321 5 for my $field (@$normal) {
322 8 $message->add_trailer(@$field);
323 }
324  
325 5 $message->freeze_trailers;
326 5 return $message;
327 }
328  
329 4 ▶sub _request_contract {
Subroutine _request_contract: called CC=4 SCAR=14.3
330 4 my ($request) = @_;
331 4 ▶ return unless blessed($request);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($request) 0 4 4
332  
333 4 for my $method (qw(
334 method target scheme authority protocol version
335 header_count header_name header_value
336 trailer_count trailer_name trailer_value
337 has_buffered_body body
338 )) {
339 56 ▶ return unless $request->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $request->can($method) 0 56 56
340 }
341  
342 4 return 1;
343 }
344  
345 0 ▶sub _response_contract {
Subroutine _response_contract: not called CC=4 SCAR=30.0
346 0 my ($response) = @_;
347 0 ▶ return unless blessed($response);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($response) 0 0 0
348  
349 0 for my $method (qw(
350 status version
351 header_count header_name header_value
352 trailer_count trailer_name trailer_value
353 has_buffered_body body
354 )) {
355 0 ▶ return unless $response->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $response->can($method) 0 0 0
356 }
357  
358 0 return 1;
359 }
360  
361 4 ▶sub _check_version {
Subroutine _check_version: called CC=3 SCAR=12.0
362 4 my ($operation, $message) = @_;
363 4 my $version = $message->version;
364 4 ▶ croak "$operation: explicit HTTP version must be 2"
Branch: 1 branch
BranchTrueFalseTotal
if defined $version and $version ne 2 0 4 4
Condition33%1/3
defined $version and $version ne 2
!ll&&!rl&&r
400
MC/DC0%0/2
defined $version and $version ne 2
defined $version $version ne 2
Truth table33%1/3
A and B
A= defined $versionB= $version ne 2
ABresult
0X0
100
111
365 if defined($version) && $version ne '2';
366 4 return;
367 }
368  
369 4 ▶sub normal_fields {
Subroutine normal_fields: called CC=2 SCAR=6.9
Pod undocumented
370 4 my ($class, $operation, $message) = @_;
371  
372 4 my @fields;
373 4 for my $index (0 .. $message->header_count - 1) {
374 2 my $name = lc $message->header_name($index);
375 2 my $value = $message->header_value($index);
376 2 push @fields, _normal_field($operation, $name, $value);
377 }
378  
379 4 return \@fields;
380 }
381  
382 74 ▶sub trailer_fields {
Subroutine trailer_fields: called CC=3 SCAR=11.0
Pod undocumented
383 74 my ($class, $operation, $message) = @_;
384  
385 74 my $count = $message->trailer_count;
386 74 ▶ croak "$operation: trailer section is unavailable"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $count 0 74 74
387 unless defined $count;
388  
389 74 my @fields;
390 74 for my $index (0 .. $count - 1) {
391 8 my $name = lc $message->trailer_name($index);
392 8 my $value = $message->trailer_value($index);
393 8 push @fields, _normal_field($operation, $name, $value);
394 }
395  
396 74 return \@fields;
397 }
398  
399 4 ▶sub request_headers {
Subroutine request_headers: called CC=20 SCAR=34.8
Pod undocumented
400 4 my ($class, $request) = @_;
401  
402 4 ▶ croak 'request_headers(): requires the Uniform HTTP request contract'
Branch: 1 branch
BranchTrueFalseTotal
unless _request_contract($request) 0 4 4
403 unless _request_contract($request);
404 4 _check_version('request_headers()', $request);
405  
406 4 my $method = $request->method;
407 4 my $protocol = $request->protocol;
408 4 my @block = ([ ':method', $method ]);
409  
410 4 ▶ if (uc($method) eq 'CONNECT') {
Branch: 1 branch
BranchTrueFalseTotal
if (uc $method eq 'CONNECT') { } 2 2 4
411 2 my $authority = $request->authority;
412 2 ▶ croak 'request_headers(): CONNECT requires authority'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $authority and length $authority 0 2 2
Condition33%1/3
defined $authority and length $authority
!ll&&!rl&&r
002
MC/DC0%0/2
defined $authority and length $authority
defined $authority length $authority
Truth table33%1/3
A and B
A= defined $authorityB= length $authority
ABresult
0X0
100
111
413 unless defined($authority) && length($authority);
414  
415 2 ▶ if (defined $protocol) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $protocol) { } 1 1 2
416 1 ▶ croak 'request_headers(): extended CONNECT requires nonempty protocol'
Branch: 1 branch
BranchTrueFalseTotal
unless length $protocol 0 1 1
417 unless length($protocol);
418  
419 1 my $scheme = $request->scheme;
420 1 ▶ croak 'request_headers(): extended CONNECT requires scheme'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $scheme and length $scheme 0 1 1
Condition33%1/3
defined $scheme and length $scheme
!ll&&!rl&&r
001
MC/DC0%0/2
defined $scheme and length $scheme
defined $scheme length $scheme
Truth table33%1/3
A and B
A= defined $schemeB= length $scheme
ABresult
0X0
100
111
421 unless defined($scheme) && length($scheme);
422 1 ▶ croak 'request_headers(): extended CONNECT requires a path target'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $request->target and length $request->target 0 1 1
Condition33%1/3
defined $request->target and length $request->target
!ll&&!rl&&r
001
MC/DC0%0/2
defined $request->target and length $request->target
defined $request->target length $request->target
Truth table33%1/3
A and B
A= defined $request->targetB= length $request->target
ABresult
0X0
100
111
423 unless defined($request->target) && length($request->target);
424  
425 1 push @block,
426 [ ':protocol', $protocol ],
427 [ ':scheme', $scheme ],
428 [ ':authority', $authority ],
429 [ ':path', $request->target ];
430 }
431 else {
432 1 ▶ croak 'request_headers(): ordinary CONNECT target must equal authority'
Branch: 1 branch
BranchTrueFalseTotal
unless $request->target eq $authority 0 1 1
433 unless $request->target eq $authority;
434 1 ▶ croak 'request_headers(): ordinary CONNECT must not have scheme'
Branch: 1 branch
BranchTrueFalseTotal
if defined $request->scheme 0 1 1
435 if defined $request->scheme;
436 1 push @block, [ ':authority', $authority ];
437 }
438 }
439 else {
440 2 ▶ croak 'request_headers(): protocol metadata requires CONNECT'
Branch: 1 branch
BranchTrueFalseTotal
if defined $protocol 0 2 2
441 if defined $protocol;
442  
443 2 my $scheme = $request->scheme;
444 2 my $authority = $request->authority;
445 2 my $target = $request->target;
446  
447 2 ▶ croak 'request_headers(): HTTP/2 Request requires nonempty path target'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target and length $target 0 2 2
Condition33%1/3
defined $target and length $target
!ll&&!rl&&r
002
MC/DC0%0/2
defined $target and length $target
defined $target length $target
Truth table33%1/3
A and B
A= defined $targetB= length $target
ABresult
0X0
100
111
448 unless defined($target) && length($target);
449 2 ▶ croak 'request_headers(): HTTP/2 Request requires scheme'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $scheme and length $scheme 0 2 2
Condition33%1/3
defined $scheme and length $scheme
!ll&&!rl&&r
002
MC/DC0%0/2
defined $scheme and length $scheme
defined $scheme length $scheme
Truth table33%1/3
A and B
A= defined $schemeB= length $scheme
ABresult
0X0
100
111
450 unless defined($scheme) && length($scheme);
451 2 ▶ croak 'request_headers(): HTTP/2 Request requires authority'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $authority and length $authority 0 2 2
Condition33%1/3
defined $authority and length $authority
!ll&&!rl&&r
002
MC/DC0%0/2
defined $authority and length $authority
defined $authority length $authority
Truth table33%1/3
A and B
A= defined $authorityB= length $authority
ABresult
0X0
100
111
452 unless defined($authority) && length($authority);
453  
454 2 push @block,
455 [ ':scheme', $scheme ],
456 [ ':authority', $authority ],
457 [ ':path', $target ];
458 }
459  
460 4 push @block, @{ $class->normal_fields('request_headers()', $request) };
461 4 return \@block;
462 }
463  
464 0 ▶sub response_headers {
Subroutine response_headers: not called CC=2 SCAR=17.9
Pod undocumented
465 0 my ($class, $response) = @_;
466  
467 0 ▶ croak 'response_headers(): requires the Uniform HTTP response contract'
Branch: 1 branch
BranchTrueFalseTotal
unless _response_contract($response) 0 0 0
468 unless _response_contract($response);
469 0 _check_version('response_headers()', $response);
470  
471 0 my @block = ([ ':status', '' . $response->status ]);
472 0 push @block, @{ $class->normal_fields('response_headers()', $response) };
473 0 return \@block;
474 }
475  
476 29 1;
« blib/lib/Unblock/HTTP2/Client.pm ↑ Summary blib/lib/Unblock/HTTP2/Server.pm »