HTTP/Request.pm

filter: Statementstmt 99.3% 284 / 286 Branchbran 80.9% 149 / 184 Conditioncond 52.1% 37 / 71 MC/DCmcdc 27.5% 11 / 40 Subroutinesub 98.1% 53 / 54 Podpod 95.0% 19 / 20 totaltotal 84.4% 553 / 655 CC 124 SCAR 17.2
CC
124
Cov
87%
new
13.2
header
11.0
_parse_content_length_values
8.3
CRAP 5.6
« HTTP/Transaction.pm ↑ Summary HTTP/_HTTP2/ClientSelectorConnection.pm »
1 package Linux::Event::HTTP::Request;
2 42 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 42 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 42 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 42 ▶use Hash::Util::FieldHash qw(fieldhash);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 42 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 42 ▶use utf8 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 42 ▶use Linux::Event::HTTP::_HTTP1 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 42 our $VERSION = '0.003';
13  
14 my (
15 42 $NATIVE_METHOD,
16 $NATIVE_TARGET,
17 $NATIVE_VERSION,
18 $NATIVE_BODY_MODE,
19 $NATIVE_CONTENT_LENGTH,
20 $NATIVE_KEEP_ALIVE,
21 $NATIVE_HEADER_COUNT,
22 $NATIVE_HEADER_NAME,
23 $NATIVE_HEADER_VALUE,
24 $NATIVE_HEADER,
25 $NATIVE_HEADER_VALUES,
26 $NATIVE_DESTROY,
27 );
28  
29 42 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
30 42 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 42 $NATIVE_METHOD = \&{__PACKAGE__ . '::method'};
32 42 $NATIVE_TARGET = \&{__PACKAGE__ . '::target'};
33 42 $NATIVE_VERSION = \&{__PACKAGE__ . '::http_version'};
34 42 $NATIVE_BODY_MODE = \&{__PACKAGE__ . '::body_mode'};
35 42 $NATIVE_CONTENT_LENGTH = \&{__PACKAGE__ . '::content_length'};
36 42 $NATIVE_KEEP_ALIVE = \&{__PACKAGE__ . '::keep_alive'};
37 42 $NATIVE_HEADER_COUNT = \&{__PACKAGE__ . '::header_count'};
38 42 $NATIVE_HEADER_NAME = \&{__PACKAGE__ . '::header_name'};
39 42 $NATIVE_HEADER_VALUE = \&{__PACKAGE__ . '::header_value'};
40 42 $NATIVE_HEADER = \&{__PACKAGE__ . '::header'};
41 42 $NATIVE_HEADER_VALUES = \&{__PACKAGE__ . '::header_values'};
42 42 $NATIVE_DESTROY = \&{__PACKAGE__ . '::DESTROY'};
43 }
44  
45 42 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 42 fieldhash my %NATIVE_COMPLETE;
48  
49 0 ▶sub CLONE_SKIP { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
50  
51 3214 ▶sub _is_native ($self) {
Subroutine _is_native: called CC=2 SCAR=7.6
52 3214 ▶ return (reftype($self) // '') eq 'SCALAR';
Condition50%1/2
builtin::reftype($self) // ""
l!l
32140
MC/DC0%0/1
builtin::reftype($self) // ""
builtin::reftype($self)
Truth table50%1/2
A
A= builtin::reftype($self)
Aresult
11
00
53 }
54  
55 292 ▶sub _byte_string ($operation, $value) {
Subroutine _byte_string: called CC=5 SCAR=16.2
56 292 ▶ die "$operation(): value must be a defined scalar byte string"
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or ref $value 1 291 292
Condition66%2/3
not defined $value or ref $value
l!l&&r!l&&!r
10291
MC/DC50%1/2
not defined $value or ref $value
not defined $value ref $value
Truth table66%2/3
not(A) or B
A= not defined $valueB= ref $value
ABresult
1X1
011
000
57 if !defined($value) || ref($value);
58 291 my $bytes = "$value";
59 291 ▶ if (utf8::is_utf8($bytes)) {
Branch: 1 branch
BranchTrueFalseTotal
if (utf8::is_utf8($bytes)) 1 290 291
60 1 ▶ die "$operation(): value contains wide characters; encode it to bytes first"
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::downgrade($bytes, 1) 1 0 1
61 if !utf8::downgrade($bytes, 1);
62 }
63 290 return $bytes;
64 }
65  
66 113 ▶sub _validate_method ($method) {
Subroutine _validate_method: called CC=5 SCAR=19.2
67 113 ▶ die 'request method is required' if !defined($method) || ref($method) || $method eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $method or ref $method or $method eq "" 0 113 113
Condition33%2/6
not defined $method or ref $method or $method eq ""
l!l&&r!l&&!r
00113
not defined $method or ref $method
l!l&&r!l&&!r
00113
MC/DC0%0/3
not defined $method or ref $method or $method eq ""
not defined $method ref $method $method eq ""
Truth table25%1/4
not(A) or B or C
A= not defined $methodB= ref $methodC= $method eq ""
ABCresult
1XX1
01X1
0011
0000
68 113 ▶ die 'invalid request method'
Branch: 1 branch
BranchTrueFalseTotal
if not $method =~ /\A[!#\$%&'*+\-.^_`|~0-9A-Za-z]+\z/u 1 112 113
69 if $method !~ /\A[!#\$%&'*+\-.^_`|~0-9A-Za-z]+\z/;
70 }
71  
72 112 ▶sub _validate_target ($target) {
Subroutine _validate_target: called CC=5 SCAR=18.1
73 112 ▶ die 'request target is required' if !defined($target) || ref($target) || $target eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $target or ref $target or $target eq "" 0 112 112
Condition33%2/6
not defined $target or ref $target or $target eq ""
l!l&&r!l&&!r
00112
not defined $target or ref $target
l!l&&r!l&&!r
00112
MC/DC0%0/3
not defined $target or ref $target or $target eq ""
not defined $target ref $target $target eq ""
Truth table25%1/4
not(A) or B or C
A= not defined $targetB= ref $targetC= $target eq ""
ABCresult
1XX1
01X1
0011
0000
74 112 my $bytes = _byte_string('target', $target);
75 112 ▶ die 'invalid request target' if $bytes =~ /[\x00-\x20\x7f]/;
Branch: 1 branch
BranchTrueFalseTotal
if $bytes =~ /[\x00-\x20\x7f]/u 1 111 112
76 111 return $bytes;
77 }
78  
79 6 ▶sub _validate_scheme ($scheme) {
Subroutine _validate_scheme: called CC=3 SCAR=11.0
80 6 ▶ return undef if !defined $scheme;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $scheme 1 5 6
81 5 my $bytes = _byte_string('scheme', $scheme);
82 5 ▶ die 'invalid request scheme'
Branch: 1 branch
BranchTrueFalseTotal
unless $bytes =~ /\A[A-Za-z][A-Za-z0-9+.-]*\z/u 0 5 5
83 if $bytes !~ /\A[A-Za-z][A-Za-z0-9+.-]*\z/;
84 5 return $bytes;
85 }
86  
87 8 ▶sub _validate_authority ($authority) {
Subroutine _validate_authority: called CC=4 SCAR=14.6
88 8 ▶ return undef if !defined $authority;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $authority 1 7 8
89 7 my $bytes = _byte_string('authority', $authority);
90 7 ▶ die 'invalid request authority'
Branch: 1 branch
BranchTrueFalseTotal
if $bytes eq "" or $bytes =~ m[[\x00-\x20\x7f/?#]]u 0 7 7
Condition33%1/3
$bytes eq "" or $bytes =~ m[[\x00-\x20\x7f/?#]]u
l!l&&r!l&&!r
007
MC/DC0%0/2
$bytes eq "" or $bytes =~ m[[\x00-\x20\x7f/?#]]u
$bytes eq "" $bytes =~ m[[\x00-\x20\x7f/?#]]u
Truth table33%1/3
A or B
A= $bytes eq ""B= $bytes =~ m[[\x00-\x20\x7f/?#]]u
ABresult
1X1
011
000
91 if $bytes eq '' || $bytes =~ /[\x00-\x20\x7f\/?#]/;
92 7 return $bytes;
93 }
94  
95 9 ▶sub _target_metadata ($method, $target) {
Subroutine _target_metadata: called CC=4 SCAR=13.9
96 9 ▶ if ($target =~ /\A([A-Za-z][A-Za-z0-9+.-]*):\/\/([^\/?#]+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target =~ m[\A([A-Za-z][A-Za-z0-9+.-]*)://([^/?#]+)]u) 2 7 9
97 2 return ($1, $2);
98 }
99 7 ▶ if (uc($method) eq 'CONNECT' && $target !~ /[\/?#]/) {
Branch: 1 branch
BranchTrueFalseTotal
if (uc $method eq "CONNECT" and not $target =~ m[[/?#]]u) 3 4 7
Condition66%2/3
uc $method eq "CONNECT" and not $target =~ m[[/?#]]u
!ll&&!rl&&r
403
MC/DC50%1/2
uc $method eq "CONNECT" and not $target =~ m[[/?#]]u
uc $method eq "CONNECT" not $target =~ m[[/?#]]u
Truth table66%2/3
A and not(B)
A= uc $method eq "CONNECT"B= not $target =~ m[[/?#]]u
ABresult
0X0
100
111
100 3 return (undef, $target);
101 }
102 4 return (undef, undef);
103 }
104  
105 111 ▶sub _validate_version ($version) {
Subroutine _validate_version: called CC=4 SCAR=19.1
106 111 ▶ die 'invalid HTTP version'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $version or ref $version or not "$version" =~ /\A[0-9]+(?:\.[0-9]+)?\z/u 0 111 111
Condition33%2/6
not defined $version or ref $version or not "$version" =~ /\A[0-9]+(?:\.[0-9]+)?\z/u
l!l&&r!l&&!r
00111
not defined $version or ref $version
l!l&&r!l&&!r
00111
MC/DC0%0/3
not defined $version or ref $version or not "$version" =~ /\A[0-9]+(?:\.[0-9]+)?\z/u
not defined $version ref $version not "$version" =~ /\A[0-9]+(?:\.[0-9]+)?\z/u
Truth table25%1/4
not(A) or B or not(C)
A= not defined $versionB= ref $versionC= not "$version" =~ /\A[0-9]+(?:\.[0-9]+)?\z/u
ABCresult
1XX1
01X1
0011
0000
107 if !defined($version) || ref($version)
108 || "$version" !~ /\A[0-9]+(?:\.[0-9]+)?\z/;
109 }
110  
111 584 ▶sub _validate_name ($name) {
Subroutine _validate_name: called CC=5 SCAR=19.2
112 584 ▶ die 'header field name is required' if !defined($name) || ref($name) || $name eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $name or ref $name or $name eq "" 0 584 584
Condition33%2/6
not defined $name or ref $name or $name eq ""
l!l&&r!l&&!r
00584
not defined $name or ref $name
l!l&&r!l&&!r
00584
MC/DC0%0/3
not defined $name or ref $name or $name eq ""
not defined $name ref $name $name eq ""
Truth table25%1/4
not(A) or B or C
A= not defined $nameB= ref $nameC= $name eq ""
ABCresult
1XX1
01X1
0011
0000
113 584 ▶ die 'invalid header field name'
Branch: 1 branch
BranchTrueFalseTotal
if not $name =~ /\A[!#\$%&'*+\-.^_`|~0-9A-Za-z]+\z/u 1 583 584
114 if $name !~ /\A[!#\$%&'*+\-.^_`|~0-9A-Za-z]+\z/;
115 }
116  
117 155 ▶sub _validate_value ($value) {
Subroutine _validate_value: called CC=4 SCAR=15.6
118 155 ▶ die 'header field value must be defined' if !defined($value) || ref($value);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or ref $value 0 155 155
Condition33%1/3
not defined $value or ref $value
l!l&&r!l&&!r
00155
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
119 155 my $bytes = _byte_string('header', $value);
120 155 ▶ die 'header field value contains invalid control characters'
Branch: 1 branch
BranchTrueFalseTotal
if $bytes =~ /[\x00-\x08\x0a-\x1f\x7f]/u 0 155 155
121 if $bytes =~ /[\x00-\x08\x0a-\x1f\x7f]/;
122 155 return $bytes;
123 }
124  
125 268 ▶sub _validate_header_index ($index) {
Subroutine _validate_header_index: called CC=4 SCAR=14.9
126 268 ▶ die 'header index must be a non-negative integer'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $index or ref $index or not "$index" =~ /\A[0-9]+\z/u 4 264 268
Condition50%3/6
not defined $index or ref $index or not "$index" =~ /\A[0-9]+\z/u
l!l&&r!l&&!r
04264
not defined $index or ref $index
l!l&&r!l&&!r
00268
MC/DC33%1/3
not defined $index or ref $index or not "$index" =~ /\A[0-9]+\z/u
not defined $index ref $index not "$index" =~ /\A[0-9]+\z/u
Truth table50%2/4
not(A) or B or not(C)
A= not defined $indexB= ref $indexC= not "$index" =~ /\A[0-9]+\z/u
ABCresult
1XX1
01X1
0011
0000
127 if !defined($index) || ref($index) || "$index" !~ /\A[0-9]+\z/;
128 264 return 0 + $index;
129 }
130  
131 187 ▶sub _assert_mutable ($self) {
Subroutine _assert_mutable: called CC=3 SCAR=11.1
132 187 ▶ die 'received request metadata is read-only' if _is_native($self);
Branch: 1 branch
BranchTrueFalseTotal
if _is_native($self) 0 187 187
133 die 'request metadata cannot change after the message is committed'
134 187 ▶ if $self->{committed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"committed"} 2 185 187
135 }
136  
137 112 ▶sub new ($class, %args) {
Subroutine new: called CC=13 SCAR=25.8
Pod undocumented
138 112 my $method = delete $args{method};
139 112 my $target = delete $args{target};
140 112 ▶ my $version = delete($args{version}) // '1.1';
Condition100%2/2
delete $args{"version"} // "1.1"
l!l
6448
MC/DC100%1/1
delete $args{"version"} // "1.1"
delete $args{"version"}
Truth table100%2/2
A
A= delete $args{"version"}
Aresult
11
00
141 112 my $has_scheme = exists $args{scheme};
142 112 my $scheme = delete $args{scheme};
143 112 my $has_authority = exists $args{authority};
144 112 my $authority = delete $args{authority};
145 112 my $headers = delete $args{headers};
146 112 my $has_body = exists $args{body};
147 112 my $body = delete $args{body};
148  
149 112 ▶ die 'unknown request option: ' . join(', ', sort keys %args) if %args;
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 112 112
150  
151 112 _validate_method($method);
152 111 $target = _validate_target($target);
153 110 _validate_version($version);
154 110 ▶ $scheme = _validate_scheme($scheme) if $has_scheme;
Branch: 1 branch
BranchTrueFalseTotal
if $has_scheme 4 106 110
155 110 ▶ $authority = _validate_authority($authority) if $has_authority;
Branch: 1 branch
BranchTrueFalseTotal
if $has_authority 6 104 110
156  
157 110 ▶ my $self = bless {
Branch: 2 branches
BranchTrueFalseTotal
$has_scheme ? : 4 106 110
$has_authority ? : 6 104 110
158 method => "$method",
159 target => $target,
160 version => "$version",
161 ($has_scheme ? (scheme => $scheme) : ()),
162 ($has_authority ? (authority => $authority) : ()),
163 headers => [],
164 body_kind => undef,
165 body => undef,
166 committed => 0,
167 complete => 1,
168 }, $class;
169  
170 110 ▶ if (defined $headers) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $headers) 94 16 110
171 94 ▶ die 'headers must be an array reference of [name, value] pairs'
Branch: 1 branch
BranchTrueFalseTotal
if ref $headers ne "ARRAY" 0 94 94
172 if ref($headers) ne 'ARRAY';
173 94 for my $pair (@$headers) {
174 142 ▶ die 'each request header must be a [name, value] pair'
Branch: 1 branch
BranchTrueFalseTotal
if ref $pair ne "ARRAY" or @$pair != 2 0 142 142
Condition33%1/3
ref $pair ne "ARRAY" or @$pair != 2
l!l&&r!l&&!r
00142
MC/DC0%0/2
ref $pair ne "ARRAY" or @$pair != 2
ref $pair ne "ARRAY" @$pair != 2
Truth table33%1/3
A or B
A= ref $pair ne "ARRAY"B= @$pair != 2
ABresult
1X1
011
000
175 if ref($pair) ne 'ARRAY' || @$pair != 2;
176 142 $self->add_header($pair->[0], $pair->[1]);
177 }
178 }
179  
180 109 ▶ $self->body($body) if $has_body;
Branch: 1 branch
BranchTrueFalseTotal
if $has_body 11 98 109
181 108 return $self;
182 }
183  
184 406 ▶sub method ($self, @args) {
Subroutine method: called CC=5 SCAR=16.1
Pod documented
185 406 ▶ if (_is_native($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_native($self)) 75 331 406
186 75 ▶ die 'received request metadata is read-only' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 1 74 75
187 74 return $NATIVE_METHOD->($self);
188 }
189 331 ▶ return $self->{method} if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 330 1 331
190 1 ▶ die 'method accepts exactly one value' if @args != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args != 1 0 1 1
191 1 $self->_assert_mutable;
192 1 _validate_method($args[0]);
193 1 $self->{method} = "$args[0]";
194 1 return $self;
195 }
196  
197 450 ▶sub target ($self, @args) {
Subroutine target: called CC=5 SCAR=16.2
Pod documented
198 450 ▶ if (_is_native($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_native($self)) 338 112 450
199 338 ▶ die 'received request metadata is read-only' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 338 338
200 338 return $NATIVE_TARGET->($self);
201 }
202 112 ▶ return $self->{target} if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 110 2 112
203 2 ▶ die 'target accepts exactly one value' if @args != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args != 1 0 2 2
204 2 $self->_assert_mutable;
205 1 $self->{target} = _validate_target($args[0]);
206 1 return $self;
207 }
208  
209 4 ▶sub target_is_exact ($self) {
Subroutine target_is_exact: called CC=1 SCAR=0.0
Pod documented
210 4 return 1;
211 }
212  
213 12 ▶sub scheme ($self, @args) {
Subroutine scheme: called CC=6 SCAR=18.0
Pod documented
214 12 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 2 10 12
215 2 ▶ die 'scheme accepts exactly one value' if @args != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args != 1 0 2 2
216 2 ▶ die 'received request metadata is read-only' if _is_native($self);
Branch: 1 branch
BranchTrueFalseTotal
if _is_native($self) 0 2 2
217 2 $self->_assert_mutable;
218 2 $self->{scheme} = _validate_scheme($args[0]);
219 2 return $self;
220 }
221  
222 10 ▶ if (!_is_native($self) && exists $self->{scheme}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not _is_native($self) and exists $self->{"scheme"}) 5 5 10
Condition100%3/3
not _is_native($self) and exists $self->{"scheme"}
!ll&&!rl&&r
145
MC/DC100%2/2
not _is_native($self) and exists $self->{"scheme"}
not _is_native($self) exists $self->{"scheme"}
Truth table100%3/3
not(A) and B
A= not _is_native($self)B= exists $self->{"scheme"}
ABresult
0X0
100
111
223 5 return $self->{scheme};
224 }
225 5 my ($scheme) = _target_metadata($self->method, $self->target);
226 5 return $scheme;
227 }
228  
229 14 ▶sub authority ($self, @args) {
Subroutine authority: called CC=8 SCAR=21.0
Pod documented
230 14 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 2 12 14
231 2 ▶ die 'authority accepts exactly one value' if @args != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args != 1 0 2 2
232 2 ▶ die 'received request metadata is read-only' if _is_native($self);
Branch: 1 branch
BranchTrueFalseTotal
if _is_native($self) 0 2 2
233 2 $self->_assert_mutable;
234 2 $self->{authority} = _validate_authority($args[0]);
235 2 return $self;
236 }
237  
238 12 ▶ if (!_is_native($self) && exists $self->{authority}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not _is_native($self) and exists $self->{"authority"}) 8 4 12
Condition100%3/3
not _is_native($self) and exists $self->{"authority"}
!ll&&!rl&&r
138
MC/DC100%2/2
not _is_native($self) and exists $self->{"authority"}
not _is_native($self) exists $self->{"authority"}
Truth table100%3/3
not(A) and B
A= not _is_native($self)B= exists $self->{"authority"}
ABresult
0X0
100
111
239 8 return $self->{authority};
240 }
241  
242 4 my (undef, $authority) = _target_metadata($self->method, $self->target);
243 4 ▶ return $authority if defined $authority;
Branch: 1 branch
BranchTrueFalseTotal
if defined $authority 2 2 4
244  
245 2 my @host = $self->_header_values_list('Host');
246 2 ▶ return $host[0] if @host == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @host == 1 2 0 2
247 0 return undef;
248 }
249  
250 243 ▶sub version ($self, @args) {
Subroutine version: called CC=6 SCAR=18.0
Pod documented
251 243 ▶ if (_is_native($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_native($self)) 66 177 243
252 66 ▶ die 'received request metadata is read-only' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 66 66
253 66 return $NATIVE_VERSION->($self);
254 }
255 177 ▶ return $self->{version} if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 175 2 177
256 2 ▶ die 'version accepts exactly one value' if @args != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args != 1 0 2 2
257 2 $self->_assert_mutable;
258 2 ▶ if (!defined $args[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args[0]) 1 1 2
259 1 $self->{version} = undef;
260 1 return $self;
261 }
262 1 _validate_version($args[0]);
263 1 $self->{version} = "$args[0]";
264 1 return $self;
265 }
266  
267 114 ▶sub header ($self, $name, @args) {
Subroutine header: called CC=11 SCAR=24.0
Pod documented
268 114 _validate_name($name);
269 114 ▶ if (_is_native($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_native($self)) 87 27 114
270 87 ▶ die 'received request metadata is read-only' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 1 86 87
271 86 return $NATIVE_HEADER->($self, $name);
272 }
273  
274 27 ▶ if (!@args) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@args) 13 14 27
275 13 my $wanted = lc $name;
276 13 for my $pair (@{$self->{headers}}) {
277 20 ▶ return $pair->[1] if lc($pair->[0]) eq $wanted;
Branch: 1 branch
BranchTrueFalseTotal
if lc $pair->[0] eq $wanted 11 9 20
278 }
279 2 return undef;
280 }
281  
282 14 ▶ die 'header setter accepts exactly one value' if @args != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args != 1 0 14 14
283 14 $self->_assert_mutable;
284 13 my $value = _validate_value($args[0]);
285 13 my $wanted = lc $name;
286 13 my @headers;
287 13 my $inserted = 0;
288 13 for my $pair (@{$self->{headers}}) {
289 24 ▶ if (lc($pair->[0]) eq $wanted) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $pair->[0] eq $wanted) 4 20 24
290 4 ▶ if (!$inserted) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($inserted) 2 2 4
291 2 push @headers, [ "$name", $value ];
292 2 $inserted = 1;
293 }
294 4 next;
295 }
296 20 push @headers, [ @$pair ];
297 }
298 13 ▶ push @headers, [ "$name", $value ] if !$inserted;
Branch: 1 branch
BranchTrueFalseTotal
unless $inserted 11 2 13
299 13 $self->{headers} = \@headers;
300 13 return $self;
301 }
302  
303 143 ▶sub add_header ($self, $name, $value) {
Subroutine add_header: called CC=1 SCAR=0.0
Pod documented
304 143 $self->_assert_mutable;
305 143 _validate_name($name);
306 142 $value = _validate_value($value);
307 142 push @{$self->{headers}}, [ "$name", $value ];
308 142 return $self;
309 }
310  
311 1 ▶sub remove_header ($self, $name) {
Subroutine remove_header: called CC=1 SCAR=0.0
Pod documented
312 1 $self->_assert_mutable;
313 1 _validate_name($name);
314 1 my $wanted = lc $name;
315 1 $self->{headers} = [ grep { lc($_->[0]) ne $wanted } @{$self->{headers}} ];
316 1 return $self;
317 }
318  
319 326 ▶sub _header_values_list ($self, $name) {
Subroutine _header_values_list: called CC=2 SCAR=6.9
320 326 _validate_name($name);
321 326 ▶ return $NATIVE_HEADER_VALUES->($self, $name) if _is_native($self);
Branch: 1 branch
BranchTrueFalseTotal
if _is_native($self) 37 289 326
322 289 my $wanted = lc $name;
323 118 return map { $_->[1] }
324 483 grep { lc($_->[0]) eq $wanted }
325 289 @{$self->{headers}};
326 }
327  
328 10 ▶sub header_values ($self, $name) {
Subroutine header_values: called CC=1 SCAR=0.0
Pod documented
329 10 return [ $self->_header_values_list($name) ];
330 }
331  
332 349 ▶sub header_count ($self) {
Subroutine header_count: called CC=2 SCAR=6.9
Pod documented
333 349 ▶ return $NATIVE_HEADER_COUNT->($self) if _is_native($self);
Branch: 1 branch
BranchTrueFalseTotal
if _is_native($self) 8 341 349
334 341 return scalar @{$self->{headers}};
335 }
336  
337 136 ▶sub header_name ($self, $index) {
Subroutine header_name: called CC=3 SCAR=11.0
Pod documented
338 136 $index = _validate_header_index($index);
339 134 ▶ return undef if $index >= $self->header_count;
Branch: 1 branch
BranchTrueFalseTotal
if $index >= $self->header_count 3 131 134
340 131 ▶ return $NATIVE_HEADER_NAME->($self, $index) if _is_native($self);
Branch: 1 branch
BranchTrueFalseTotal
if _is_native($self) 2 129 131
341 129 return $self->{headers}[$index][0];
342 }
343  
344 132 ▶sub header_value ($self, $index) {
Subroutine header_value: called CC=3 SCAR=11.0
Pod documented
345 132 $index = _validate_header_index($index);
346 130 ▶ return undef if $index >= $self->header_count;
Branch: 1 branch
BranchTrueFalseTotal
if $index >= $self->header_count 2 128 130
347 128 ▶ return $NATIVE_HEADER_VALUE->($self, $index) if _is_native($self);
Branch: 1 branch
BranchTrueFalseTotal
if _is_native($self) 1 127 128
348 127 return $self->{headers}[$index][1];
349 }
350  
351 4 ▶sub headers_are_lossless ($self) {
Subroutine headers_are_lossless: called CC=1 SCAR=0.0
Pod documented
352 4 return 1;
353 }
354  
355 86 ▶sub _parse_content_length_values (@values) {
Subroutine _parse_content_length_values: called CC=8 SCAR=21.2
356 86 ▶ return undef if !@values;
Branch: 1 branch
BranchTrueFalseTotal
unless @values 77 9 86
357 9 my $length;
358 9 for my $value (@values) {
359 10 for my $member (split /,/, $value, -1) {
360 10 $member =~ s/\A[ \t]+//;
361 10 $member =~ s/[ \t]+\z//;
362 10 ▶ die 'invalid or conflicting Content-Length'
Branch: 1 branch
BranchTrueFalseTotal
if $member eq "" or not $member =~ /\A[0-9]+\z/u 0 10 10
Condition33%1/3
$member eq "" or not $member =~ /\A[0-9]+\z/u
l!l&&r!l&&!r
0010
MC/DC0%0/2
$member eq "" or not $member =~ /\A[0-9]+\z/u
$member eq "" not $member =~ /\A[0-9]+\z/u
Truth table33%1/3
A or not(B)
A= $member eq ""B= not $member =~ /\A[0-9]+\z/u
ABresult
1X1
011
000
363 if $member eq '' || $member !~ /\A[0-9]+\z/;
364 10 my $number = 0 + $member;
365 10 ▶ die 'invalid or conflicting Content-Length'
Branch: 1 branch
BranchTrueFalseTotal
if defined $length and $length != $number 1 9 10
Condition66%2/3
defined $length and $length != $number
!ll&&!rl&&r
901
MC/DC50%1/2
defined $length and $length != $number
defined $length $length != $number
Truth table66%2/3
A and B
A= defined $lengthB= $length != $number
ABresult
0X0
100
111
366 if defined($length) && $length != $number;
367 9 $length = $number;
368 }
369 }
370 8 return $length;
371 }
372  
373 113 ▶sub content_length ($self) {
Subroutine content_length: called CC=2 SCAR=6.9
Pod documented
374 113 ▶ return $NATIVE_CONTENT_LENGTH->($self) if _is_native($self);
Branch: 1 branch
BranchTrueFalseTotal
if _is_native($self) 27 86 113
375 86 return _parse_content_length_values($self->_header_values_list('Content-Length'));
376 }
377  
378 101 ▶sub body ($self, @args) {
Subroutine body: called CC=7 SCAR=19.8
Pod documented
379 101 ▶ if (_is_native($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_native($self)) 1 100 101
380 1 ▶ die 'received request body is delivered incrementally and is not buffered by Request'
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 1 1
381 if @args;
382 1 return undef;
383 }
384 100 ▶ return $self->{body} if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 87 13 100
385 13 ▶ die 'body accepts exactly one value' if @args != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args != 1 0 13 13
386 13 $self->_assert_mutable;
387 die 'body(): Request already has an incremental body producer'
388 13 ▶ if ($self->{body_kind} // '') eq 'stream';
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"body_kind"} // "") eq "stream" 0 13 13
Condition50%1/2
$self->{"body_kind"} // ""
l!l
013
MC/DC0%0/1
$self->{"body_kind"} // ""
$self->{"body_kind"}
Truth table50%1/2
A
A= $self->{"body_kind"}
Aresult
11
00
389 13 $self->{body_kind} = 'scalar';
390 13 $self->{body} = _byte_string('body', $args[0]);
391 11 $self->{complete} = 1;
392 11 return $self;
393 }
394  
395 30 ▶sub has_buffered_body ($self) {
Subroutine has_buffered_body: called CC=4 SCAR=13.9
Pod documented
396 30 ▶ return 0 if _is_native($self);
Branch: 1 branch
BranchTrueFalseTotal
if _is_native($self) 2 28 30
397 28 ▶ return ($self->{body_kind} // '') eq 'scalar' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
($self->{'body_kind'} // '') eq 'scalar' ? : 3 25 28
Condition100%2/2
$self->{"body_kind"} // ""
l!l
523
MC/DC100%1/1
$self->{"body_kind"} // ""
$self->{"body_kind"}
Truth table100%2/2
A
A= $self->{"body_kind"}
Aresult
11
00
398 }
399  
400 28 ▶sub is_complete ($self) {
Subroutine is_complete: called CC=4 SCAR=13.9
Pod documented
401 28 ▶ if (_is_native($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_native($self)) 19 9 28
402 19 ▶ return $NATIVE_COMPLETE{$self} if exists $NATIVE_COMPLETE{$self};
Branch: 1 branch
BranchTrueFalseTotal
if exists $NATIVE_COMPLETE{$self} 3 16 19
403 16 ▶ return $NATIVE_BODY_MODE->($self) eq 'none' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
&$NATIVE_BODY_MODE($self) eq 'none' ? : 15 1 16
404 }
405 9 return !!$self->{complete};
406 }
407  
408 7 ▶sub is_mutable ($self) {
Subroutine is_mutable: called CC=3 SCAR=11.0
Pod documented
409 7 ▶ return 0 if _is_native($self);
Branch: 1 branch
BranchTrueFalseTotal
if _is_native($self) 2 5 7
410 5 ▶ return $self->{committed} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'committed'} ? : 3 2 5
411 }
412  
413 7 ▶sub _begin_stream_body ($self) {
Subroutine _begin_stream_body: called CC=5 SCAR=17.2
414 7 $self->_assert_mutable;
415 die 'request_body(): Request already has a complete scalar body'
416 7 ▶ if ($self->{body_kind} // '') eq 'scalar';
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"body_kind"} // "") eq "scalar" 0 7 7
Condition50%1/2
$self->{"body_kind"} // ""
l!l
07
MC/DC0%0/1
$self->{"body_kind"} // ""
$self->{"body_kind"}
Truth table50%1/2
A
A= $self->{"body_kind"}
Aresult
11
00
417 die 'request_body(): Request already has an incremental body producer'
418 7 ▶ if ($self->{body_kind} // '') eq 'stream';
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"body_kind"} // "") eq "stream" 0 7 7
Condition50%1/2
$self->{"body_kind"} // ""
l!l
07
MC/DC0%0/1
$self->{"body_kind"} // ""
$self->{"body_kind"}
Truth table50%1/2
A
A= $self->{"body_kind"}
Aresult
11
00
419 7 $self->{body_kind} = 'stream';
420 7 $self->{complete} = 0;
421 7 return $self;
422 }
423  
424 19 ▶sub _has_scalar_body ($self) {
Subroutine _has_scalar_body: called CC=1 SCAR=0.0
425 19 return $self->has_buffered_body;
426 }
427  
428 24 ▶sub _has_incremental_body ($self) {
Subroutine _has_incremental_body: called CC=3 SCAR=11.1
429 24 ▶ return 0 if _is_native($self);
Branch: 1 branch
BranchTrueFalseTotal
if _is_native($self) 0 24 24
430 24 ▶ return ($self->{body_kind} // '') eq 'stream';
Condition100%2/2
$self->{"body_kind"} // ""
l!l
915
MC/DC100%1/1
$self->{"body_kind"} // ""
$self->{"body_kind"}
Truth table100%2/2
A
A= $self->{"body_kind"}
Aresult
11
00
431 }
432  
433 29 ▶sub _mark_complete ($self) {
Subroutine _mark_complete: called CC=2 SCAR=6.9
434 29 ▶ if (_is_native($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_native($self)) { } 23 6 29
435 23 $NATIVE_COMPLETE{$self} = 1;
436 } else {
437 6 $self->{complete} = 1;
438 }
439 29 return $self;
440 }
441  
442 2 ▶sub _mark_incomplete ($self) {
Subroutine _mark_incomplete: called CC=2 SCAR=7.1
443 2 ▶ die 'cannot mark a received Request incomplete' if _is_native($self);
Branch: 1 branch
BranchTrueFalseTotal
if _is_native($self) 0 2 2
444 2 $self->{complete} = 0;
445 2 return $self;
446 }
447  
448 79 ▶sub _mark_committed ($self) {
Subroutine _mark_committed: called CC=2 SCAR=7.1
449 79 ▶ die 'cannot commit a received Request' if _is_native($self);
Branch: 1 branch
BranchTrueFalseTotal
if _is_native($self) 0 79 79
450 79 $self->{committed} = 1;
451 79 return $self;
452 }
453  
454 163 ▶sub _http1_body_mode ($self) {
Subroutine _http1_body_mode: called CC=2 SCAR=7.2
455 163 ▶ die '_http1_body_mode is only available for a parsed HTTP/1 request'
Branch: 1 branch
BranchTrueFalseTotal
unless _is_native($self) 0 163 163
456 if !_is_native($self);
457 163 return $NATIVE_BODY_MODE->($self);
458 }
459  
460 30 ▶sub _http1_keep_alive ($self) {
Subroutine _http1_keep_alive: called CC=2 SCAR=7.2
461 30 ▶ die '_http1_keep_alive is only available for a parsed HTTP/1 request'
Branch: 1 branch
BranchTrueFalseTotal
unless _is_native($self) 0 30 30
462 if !_is_native($self);
463 30 return $NATIVE_KEEP_ALIVE->($self);
464 }
465  
466 248 ▶sub DESTROY ($self) {
Subroutine DESTROY: called CC=2 SCAR=6.9
467 248 ▶ return if !_is_native($self);
Branch: 1 branch
BranchTrueFalseTotal
unless _is_native($self) 110 138 248
468 138 $NATIVE_DESTROY->($self);
469 138 return;
470 }
471  
472 42 1;
473  
474 __END__
« HTTP/Transaction.pm ↑ Summary HTTP/_HTTP2/ClientSelectorConnection.pm »