HTTP/Server/Connection.pm

filter: Statementstmt 72.1% 489 / 678 Branchbran 50.8% 288 / 566 Conditioncond 44.1% 127 / 288 MC/DCmcdc 14.3% 25 / 174 Subroutinesub 80.9% 51 / 63 Podpod 0.0% 0 / 3 totaltotal 55.3% 980 / 1772 CC 394 SCAR 51.1
CC
394
Cov
59%
_drive_http1
1074.0
_consume_request_body
870.0
_http_native_fallback_input
90.0
CRAP 165.7
↑ Summary HTTP/_HTTP2/Client.pm »
1 package Linux::Event::HTTP::Server::Connection;
2 25 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 25 ▶use parent 'Linux::Event::IO::Sock::Stream';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 25 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 25 ▶use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 25 ▶use utf8 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 25 ▶use Linux::Event::Framer ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 25 ▶use Linux::Event::HTTP::_HTTP1 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 25 ▶use Linux::Event::HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 25 ▶use Linux::Event::HTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 25 ▶use Linux::Event::HTTP::Transaction;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 25 our $VERSION = '0.003';
19  
20 25 Linux::Event::Framer->declare_native_consumer(
21 __PACKAGE__,
22 Linux::Event::HTTP::_HTTP1->_raw_consumer_definition,
23 );
24  
25 25 my $PARSER = 'Linux::Event::HTTP::_HTTP1';
26 25 my $CHUNKED = 'Linux::Event::HTTP::_HTTP1::Chunked';
27 25 my $MAX_REQUEST_HEAD = 65_536;
28 25 my $MAX_HEADERS = 100;
29 25 my %CLASS_HANDLER;
30  
31 374 ▶sub _class_handler ($class, $name) {
Subroutine _class_handler: called CC=2 SCAR=6.9
32 374 my $key = "$class\0$name";
33 374 ▶ return $CLASS_HANDLER{$key} if exists $CLASS_HANDLER{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $CLASS_HANDLER{$key} 194 180 374
34 180 return $CLASS_HANDLER{$key} = $class->can($name);
35 }
36  
37 440 ▶sub _take_http_handler ($class, $name, $option) {
Subroutine _take_http_handler: called CC=3 SCAR=11.0
38 440 ▶ if (exists $option->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option->{$name}) 66 374 440
39 66 my $handler = delete $option->{$name};
40 66 ▶ croak "new(): $name must be a coderef" if ref($handler) ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $handler ne "CODE" 0 66 66
41 66 return $handler;
42 }
43 374 return _class_handler($class, $name);
44 }
45  
46 89 ▶sub new ($class, %option) {
Subroutine new: called CC=10 SCAR=23.2
Pod undocumented
47 89 my $server_state = $option{data};
48 89 ▶ if (ref($server_state)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $server_state eq "Linux::Event::HTTP::Server::_ConnectionState") 76 13 89
49 eq 'Linux::Event::HTTP::Server::_ConnectionState') {
50 76 $option{data} = $server_state->{data};
51 76 my $callbacks = $server_state->{callbacks};
52 76 for my $name (qw(on_request on_body on_request_end)) {
53 $option{$name} = $callbacks->{$name}
54 228 ▶ if exists $callbacks->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $callbacks->{$name} 66 162 228
55 }
56 }
57  
58 croak 'new(): Connection owns on_data; use on_request for HTTP requests'
59 89 ▶ if exists $option{on_data};
Branch: 1 branch
BranchTrueFalseTotal
if exists $option{"on_data"} 0 89 89
60 croak 'new(): Connection cannot use message framing callbacks'
61 89 ▶ if exists($option{on_message}) || exists($option{on_messages});
Branch: 1 branch
BranchTrueFalseTotal
if exists $option{"on_message"} or exists $option{"on_messages"} 0 89 89
Condition33%1/3
exists $option{"on_message"} or exists $option{"on_messages"}
l!l&&r!l&&!r
0089
MC/DC0%0/2
exists $option{"on_message"} or exists $option{"on_messages"}
exists $option{"on_message"} exists $option{"on_messages"}
Truth table33%1/3
A or B
A= exists $option{"on_message"}B= exists $option{"on_messages"}
ABresult
1X1
011
000
62 croak 'new(): on_request_final was removed; use on_request and Response->body or Transaction->response_body'
63 89 ▶ if exists $option{on_request_final};
Branch: 1 branch
BranchTrueFalseTotal
if exists $option{"on_request_final"} 1 88 89
64  
65 88 my $loop = delete $option{loop};
66 88 my $on_request = _take_http_handler($class, 'on_request', \%option);
67 88 my $on_body = _take_http_handler($class, 'on_body', \%option);
68 88 my $on_request_end = _take_http_handler($class, 'on_request_end', \%option);
69 88 my $user_on_drain = _take_http_handler($class, 'on_drain', \%option);
70 88 my $user_on_close = _take_http_handler($class, 'on_close', \%option);
71  
72 88 ▶ croak 'new(): HTTP Connection requires on_request callback or method'
Branch: 1 branch
BranchTrueFalseTotal
unless $on_request 0 88 88
73 if !$on_request;
74  
75 88 $option{on_drain} = \&_http_transport_drain;
76 88 $option{on_close} = \&_http_transport_close;
77  
78 88 my $self = $class->SUPER::new(%option);
79 87 $self->{_http_on_request} = $on_request;
80 87 $self->{_http_on_body} = $on_body;
81 87 $self->{_http_on_request_end} = $on_request_end;
82 87 $self->{_http_user_on_drain} = $user_on_drain;
83 87 $self->{_http_user_on_close} = $user_on_close;
84 87 $self->{_http_input} = '';
85 87 $self->{_http_active_transaction} = undef;
86 87 $self->{_http_active_request} = undef;
87 87 $self->{_http_active_response} = undef;
88 87 $self->{_http_request_state} = undef;
89 87 $self->{_http_response_state} = undef;
90 87 $self->{_http_response_output_started} = 0;
91 87 $self->{_http_response_output_complete} = 0;
92 87 $self->{_http_driving} = 0;
93 87 $self->{_http_dispatching} = 0;
94 87 $self->{_http_closing} = 0;
95  
96 87 ▶ $self->_attach_to_loop($loop) if $loop;
Branch: 1 branch
BranchTrueFalseTotal
if $loop 0 87 87
97 87 return $self;
98 }
99  
100 0 ▶sub connect ($class, %option) {
Subroutine connect: not called CC=1 SCAR=6.9
Pod undocumented
101 0 croak 'connect(): HTTP client support is not implemented by Linux::Event::HTTP::Server::Connection';
102 }
103  
104 37 ▶sub transaction ($self) {
Subroutine transaction: called CC=6 SCAR=18.0
Pod undocumented
105 37 my $transaction = $self->{_http_active_transaction};
106 37 ▶ return $transaction if $transaction;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction 6 31 37
107  
108 31 ▶ my $request = $self->{_http_active_request} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $request = $self->{"_http_active_request"} or return 31 0 31
109 31 ▶ my $response = $self->{_http_active_response} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $response = $self->{"_http_active_response"} or return 31 0 31
110  
111 31 $transaction = Linux::Event::HTTP::Transaction
112 ->_new_server_active($request, $response, $self);
113 $transaction->{response_output_started} = 1
114 31 ▶ if $self->{_http_response_output_started};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_response_output_started"} 1 30 31
115 $transaction->{response_output_complete} = 1
116 31 ▶ if $self->{_http_response_output_complete};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_response_output_complete"} 1 30 31
117 31 $self->{_http_active_transaction} = $transaction;
118 31 return $transaction;
119 }
120  
121 0 ▶sub _http_native_protocol_400 ($self) {
Subroutine _http_native_protocol_400: not called CC=1 SCAR=6.9
122 0 $self->_protocol_error(400);
123 0 return 0;
124 }
125  
126 0 ▶sub _http_native_protocol_431 ($self) {
Subroutine _http_native_protocol_431: not called CC=1 SCAR=6.9
127 0 $self->_protocol_error(431);
128 0 return 0;
129 }
130  
131 0 ▶sub _http_native_protocol_501 ($self) {
Subroutine _http_native_protocol_501: not called CC=1 SCAR=6.9
132 0 $self->_protocol_error(501);
133 0 return 0;
134 }
135  
136 0 ▶sub _http_native_fallback_input ($self, $bytes) {
Subroutine _http_native_fallback_input: not called CC=9 SCAR=45.0
137 0 ▶ return 0 if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 0 0
Condition0%0/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table0%0/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
138  
139 0 $self->{_http_input} .= $bytes;
140 0 $self->_drive_http1;
141  
142 0 ▶ return 0 if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 0 0
Condition0%0/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table0%0/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
143 0 ▶ return 1 if length($self->{_http_input});
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"_http_input"} 0 0 0
144  
145 0 my $state = $self->{_http_request_state};
146 return 1 if $self->{_http_active_request}
147 0 ▶ && $state && !$state->{body_done};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_active_request"} and $state and not $state->{"body_done"} 0 0 0
Condition0%0/6
$self->{"_http_active_request"} and $state and not $state->{"body_done"}
!ll&&!rl&&r
000
$self->{"_http_active_request"} and $state
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"_http_active_request"} and $state and not $state->{"body_done"}
$self->{"_http_active_request"} $state not $state->{"body_done"}
Truth table0%0/4
A and B and not(C)
A= $self->{"_http_active_request"}B= $stateC= not $state->{"body_done"}
ABCresult
0XX0
10X0
1100
1111
148  
149 0 return 0;
150 }
151  
152 122 ▶sub _http_native_request ($self, $request) {
Subroutine _http_native_request: called CC=9 SCAR=23.4
153 122 ▶ return 0 if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 122 122
Condition33%1/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
00122
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table33%1/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
154 croak 'raw HTTP input delivered a new Request while another Request is active'
155 122 ▶ if $self->{_http_active_request};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_active_request"} 0 122 122
156  
157 122 my $consumed = $request->_consumed;
158 122 ▶ if ($consumed > $MAX_REQUEST_HEAD) {
Branch: 1 branch
BranchTrueFalseTotal
if ($consumed > $MAX_REQUEST_HEAD) 0 122 122
159 0 $self->_protocol_error(431, $request->version);
160 0 return 0;
161 }
162  
163 122 my $action = $self->_activate_native_http_request($request);
164 122 ▶ return 0 if $action != 2;
Branch: 1 branch
BranchTrueFalseTotal
if $action != 2 94 28 122
165  
166 28 ▶ return $self->{_http_on_body} ? 5 : 4
Branch: 2 branches
BranchTrueFalseTotal
if $request->_http1_body_mode eq "chunked" 10 18 28
$self->{'_http_on_body'} ? : 8 2 10
167 if $request->_http1_body_mode eq 'chunked';
168 18 ▶ return $self->{_http_on_body} ? 3 : 2;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_http_on_body'} ? : 16 2 18
169 }
170  
171 15 ▶sub _http_native_chunked_body ($self, $bytes, $done) {
Subroutine _http_native_chunked_body: called CC=14 SCAR=30.3
172 15 ▶ return 0 if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 15 15
Condition33%1/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
0015
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table33%1/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
173  
174 15 ▶ my $request = $self->{_http_active_request} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $request = $self->{"_http_active_request"} or return 0 15 0 15
175 15 ▶ my $response = $self->{_http_active_response} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $response = $self->{"_http_active_response"} or return 0 15 0 15
176 15 ▶ my $state = $self->{_http_request_state} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $state = $self->{"_http_request_state"} or return 0 15 0 15
177  
178 croak 'raw chunked body delivery has wrong request state'
179 15 ▶ if $state->{body_done} || $state->{mode} ne 'chunked';
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"body_done"} or $state->{"mode"} ne "chunked" 0 15 15
Condition33%1/3
$state->{"body_done"} or $state->{"mode"} ne "chunked"
l!l&&r!l&&!r
0015
MC/DC0%0/2
$state->{"body_done"} or $state->{"mode"} ne "chunked"
$state->{"body_done"} $state->{"mode"} ne "chunked"
Truth table33%1/3
A or B
A= $state->{"body_done"}B= $state->{"mode"} ne "chunked"
ABresult
1X1
011
000
180  
181 15 ▶ if (length($bytes) && !$self->_invoke_http_callback(
Branch: 1 branch
BranchTrueFalseTotal
if (length $bytes and not $self->_invoke_http_callback($self->{"_http_on_body"}, $request, $response, $bytes)) 0 15 15
Condition66%2/3
length $bytes and not $self->_invoke_http_callback($self->{"_http_on_body"}, $request, $response, $bytes)
!ll&&!rl&&r
5100
MC/DC0%0/2
length $bytes and not $self->_invoke_http_callback($self->{"_http_on_body"}, $request, $response, $bytes)
length $bytes not $self->_invoke_http_callback($self->{"_http_on_body"}, $request, $response, $bytes)
Truth table66%2/3
A and not(B)
A= length $bytesB= not $self->_invoke_http_callback($self->{"_http_on_body"}, $request, $response, $bytes)
ABresult
0X0
100
111
182 $self->{_http_on_body}, $request, $response, $bytes,
183 )) {
184 0 return 0;
185 }
186 15 ▶ return 0 if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 1 14 15
Condition66%2/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
0114
MC/DC50%1/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table66%2/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
187 14 ▶ return 0 if !$self->{_http_active_request};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_http_active_request"} 0 14 14
188  
189 14 ▶ if ($done) {
Branch: 1 branch
BranchTrueFalseTotal
if ($done) 5 9 14
190 5 $self->_finish_request_body;
191 5 return 0;
192 }
193  
194 9 return 1;
195 }
196  
197 1 ▶sub _http_native_chunked_complete ($self) {
Subroutine _http_native_chunked_complete: called CC=7 SCAR=23.2
198 1 ▶ return 0 if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 1 1
Condition33%1/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table33%1/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
199  
200 1 ▶ my $state = $self->{_http_request_state} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $state = $self->{"_http_request_state"} or return 0 1 0 1
201 croak 'raw chunked drain has wrong request state'
202 1 ▶ if $state->{body_done} || $state->{mode} ne 'chunked';
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"body_done"} or $state->{"mode"} ne "chunked" 0 1 1
Condition33%1/3
$state->{"body_done"} or $state->{"mode"} ne "chunked"
l!l&&r!l&&!r
001
MC/DC0%0/2
$state->{"body_done"} or $state->{"mode"} ne "chunked"
$state->{"body_done"} $state->{"mode"} ne "chunked"
Truth table33%1/3
A or B
A= $state->{"body_done"}B= $state->{"mode"} ne "chunked"
ABresult
1X1
011
000
203 croak 'raw chunked drain cannot bypass an on_body callback'
204 1 ▶ if $self->{_http_on_body};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_on_body"} 0 1 1
205  
206 1 $self->_finish_request_body;
207 1 return 0;
208 }
209  
210 2 ▶sub _http_native_chunked_error ($self) {
Subroutine _http_native_chunked_error: called CC=5 SCAR=18.1
211 2 ▶ return 0 if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 2 2
Condition33%1/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
002
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table33%1/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
212  
213 2 ▶ my $request = $self->{_http_active_request} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $request = $self->{"_http_active_request"} or return 0 2 0 2
214 2 ▶ my $response = $self->{_http_active_response} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $response = $self->{"_http_active_response"} or return 0 2 0 2
215 2 $self->_fail_active_transaction(400, $request, $response);
216 2 return 0;
217 }
218  
219 17 ▶sub _http_native_content_length_body ($self, $bytes, $done) {
Subroutine _http_native_content_length_body: called CC=18 SCAR=34.0
220 17 ▶ return 0 if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 17 17
Condition33%1/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
0017
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table33%1/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
221  
222 17 ▶ my $request = $self->{_http_active_request} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $request = $self->{"_http_active_request"} or return 0 17 0 17
223 17 ▶ my $response = $self->{_http_active_response} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $response = $self->{"_http_active_response"} or return 0 17 0 17
224 17 ▶ my $state = $self->{_http_request_state} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $state = $self->{"_http_request_state"} or return 0 17 0 17
225  
226 croak 'raw Content-Length body delivery has wrong request state'
227 17 ▶ if $state->{body_done} || $state->{mode} ne 'content-length';
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"body_done"} or $state->{"mode"} ne "content-length" 0 17 17
Condition33%1/3
$state->{"body_done"} or $state->{"mode"} ne "content-length"
l!l&&r!l&&!r
0017
MC/DC0%0/2
$state->{"body_done"} or $state->{"mode"} ne "content-length"
$state->{"body_done"} $state->{"mode"} ne "content-length"
Truth table33%1/3
A or B
A= $state->{"body_done"}B= $state->{"mode"} ne "content-length"
ABresult
1X1
011
000
228  
229 17 my $length = length($bytes);
230 17 ▶ my $remaining = $state->{remaining} // 0;
Condition50%1/2
$state->{"remaining"} // 0
l!l
170
MC/DC0%0/1
$state->{"remaining"} // 0
$state->{"remaining"}
Truth table50%1/2
A
A= $state->{"remaining"}
Aresult
11
00
231 17 ▶ croak 'raw Content-Length body delivery exceeds remaining body'
Branch: 1 branch
BranchTrueFalseTotal
if $length > $remaining 0 17 17
232 if $length > $remaining;
233  
234 17 $state->{remaining} = $remaining - $length;
235  
236 17 ▶ if ($length && !$self->_invoke_http_callback(
Branch: 1 branch
BranchTrueFalseTotal
if ($length and not $self->_invoke_http_callback($self->{"_http_on_body"}, $request, $response, $bytes)) 0 17 17
Condition33%1/3
$length and not $self->_invoke_http_callback($self->{"_http_on_body"}, $request, $response, $bytes)
!ll&&!rl&&r
0170
MC/DC0%0/2
$length and not $self->_invoke_http_callback($self->{"_http_on_body"}, $request, $response, $bytes)
$length not $self->_invoke_http_callback($self->{"_http_on_body"}, $request, $response, $bytes)
Truth table33%1/3
A and not(B)
A= $lengthB= not $self->_invoke_http_callback($self->{"_http_on_body"}, $request, $response, $bytes)
ABresult
0X0
100
111
237 $self->{_http_on_body}, $request, $response, $bytes,
238 )) {
239 0 return 0;
240 }
241 17 ▶ return 0 if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 1 16 17
Condition66%2/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
0116
MC/DC50%1/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table66%2/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
242 16 ▶ return 0 if !$self->{_http_active_request};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_http_active_request"} 0 16 16
243  
244 16 ▶ if ($done) {
Branch: 1 branch
BranchTrueFalseTotal
if ($done) 15 1 16
245 croak 'raw Content-Length body completed before declared length'
246 15 ▶ if $state->{remaining} != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"remaining"} != 0 0 15 15
247 15 $self->_finish_request_body;
248 15 return 0;
249 }
250  
251 croak 'raw Content-Length body reached zero without completion'
252 1 ▶ if $state->{remaining} == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"remaining"} == 0 0 1 1
253 1 return 1;
254 }
255  
256 2 ▶sub _http_native_content_length_complete ($self) {
Subroutine _http_native_content_length_complete: called CC=7 SCAR=22.7
257 2 ▶ return 0 if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 2 2
Condition33%1/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
002
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table33%1/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
258  
259 2 ▶ my $state = $self->{_http_request_state} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $state = $self->{"_http_request_state"} or return 0 2 0 2
260 croak 'raw Content-Length drain has wrong request state'
261 2 ▶ if $state->{body_done} || $state->{mode} ne 'content-length';
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"body_done"} or $state->{"mode"} ne "content-length" 0 2 2
Condition33%1/3
$state->{"body_done"} or $state->{"mode"} ne "content-length"
l!l&&r!l&&!r
002
MC/DC0%0/2
$state->{"body_done"} or $state->{"mode"} ne "content-length"
$state->{"body_done"} $state->{"mode"} ne "content-length"
Truth table33%1/3
A or B
A= $state->{"body_done"}B= $state->{"mode"} ne "content-length"
ABresult
1X1
011
000
262 croak 'raw Content-Length drain cannot bypass an on_body callback'
263 2 ▶ if $self->{_http_on_body};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_on_body"} 0 2 2
264  
265 2 $state->{remaining} = 0;
266 2 $self->_finish_request_body;
267 2 return 0;
268 }
269  
270 0 ▶sub _http_transport_drain ($self) {
Subroutine _http_transport_drain: not called CC=5 SCAR=34.0
271 0 ▶ if (my $executor = $self->{_http2_executor}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $executor = $self->{'_http2_executor'}) { } 0 0 0
elsif (my $transaction = $self->{'_http_active_transaction'}) { } 0 0 0
272 0 $executor->transport_drain;
273 } elsif (my $transaction = $self->{_http_active_transaction}) {
274 0 ▶ if (my $body = $transaction->_response_body_object) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $transaction->_response_body_object) 0 0 0
275 0 $body->_drain;
276 }
277 }
278 0 ▶ if (my $callback = $self->{_http_user_on_drain}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $callback = $self->{"_http_user_on_drain"}) 0 0 0
279 0 $callback->($self);
280 }
281 0 return;
282 }
283  
284 5 ▶sub _http_transport_close ($self) {
Subroutine _http_transport_close: called CC=5 SCAR=16.4
285 5 ▶ if (my $executor = delete $self->{_http2_executor}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $executor = delete $self->{'_http2_executor'}) { } 0 5 5
286 0 $executor->close;
287 } else {
288 5 ▶ if (my $transaction = $self->{_http_active_transaction}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $transaction = $self->{"_http_active_transaction"}) 1 4 5
289 1 ▶ $transaction->_mark_cancelled if !$transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->is_terminal 1 0 1
290 }
291 5 Linux::Event::HTTP::Server::Connection::_clear_transaction($self);
292 }
293  
294 5 my $callback = delete $self->{_http_user_on_close};
295 5 delete $self->{_http_user_on_drain};
296 5 ▶ $callback->($self) if $callback;
Branch: 1 branch
BranchTrueFalseTotal
if $callback 1 4 5
297 5 return;
298 }
299  
300 20 ▶sub _new_request_state ($request, $mode = $request->_http1_body_mode) {
Subroutine _new_request_state: called CC=5 SCAR=19.2
301 20 my $state = {
302 mode => $mode,
303 body_done => 0,
304 };
305  
306 20 ▶ if ($mode eq 'content-length') {
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq 'content-length') { } 20 0 20
elsif ($mode eq 'chunked') { } 0 0 0
307 20 ▶ $state->{remaining} = $request->content_length // 0;
Condition50%1/2
$request->content_length // 0
l!l
200
MC/DC0%0/1
$request->content_length // 0
$request->content_length
Truth table50%1/2
A
A= $request->content_length
Aresult
11
00
308 } elsif ($mode eq 'chunked') {
309 0 $state->{decoder} = $CHUNKED->new;
310 }
311  
312 20 return $state;
313 }
314  
315 29 ▶sub _body_pending ($state) {
Subroutine _body_pending: called CC=4 SCAR=14.2
316 29 ▶ return 0 if $state->{body_done};
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"body_done"} 0 29 29
317 29 ▶ return 0 if $state->{mode} eq 'none';
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"mode"} eq "none" 0 29 29
318 29 ▶ return $state->{remaining} > 0 if $state->{mode} eq 'content-length';
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"mode"} eq "content-length" 19 10 29
319 10 return 1;
320 }
321  
322 0 ▶sub _expect_continue ($request) {
Subroutine _expect_continue: not called CC=8 SCAR=42.8
323 0 my @values = $request->_header_values_list('Expect');
324 0 ▶ return 0 if !@values;
Branch: 1 branch
BranchTrueFalseTotal
unless @values 0 0 0
325 0 ▶ return -1 if $request->version ne '1.1';
Branch: 1 branch
BranchTrueFalseTotal
if $request->version ne "1.1" 0 0 0
326  
327 0 my $count = 0;
328 0 for my $value (@values) {
329 0 for my $member (split /,/, $value, -1) {
330 0 $member =~ s/\A[ \t]+//;
331 0 $member =~ s/[ \t]+\z//;
332 0 ▶ return -1 if $member eq '' || lc($member) ne '100-continue';
Branch: 1 branch
BranchTrueFalseTotal
if $member eq "" or lc $member ne "100-continue" 0 0 0
Condition0%0/3
$member eq "" or lc $member ne "100-continue"
l!l&&r!l&&!r
000
MC/DC0%0/2
$member eq "" or lc $member ne "100-continue"
$member eq "" lc $member ne "100-continue"
Truth table0%0/3
A or B
A= $member eq ""B= lc $member ne "100-continue"
ABresult
1X1
011
000
333 0 ++$count;
334 }
335 }
336  
337 0 ▶ return $count ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$count ? : 0 0 0
338 }
339  
340 202 ▶sub _invoke_http_callback ($self, $handler, $request, $response, @extra) {
Subroutine _invoke_http_callback: called CC=3 SCAR=11.0
341 202 ▶ return 1 if !$handler;
Branch: 1 branch
BranchTrueFalseTotal
unless $handler 4 198 202
342  
343 198 my $ok = eval {
344 {
345 198 local $self->{_http_dispatching} = 1;
346 198 $handler->($self, $request, $response, @extra);
347 }
348 183 $self->_response_body_ready($response);
349 182 1;
350 };
351  
352 198 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 16 182 198
353 16 $self->_fail_active_transaction(500, $request, $response);
354 16 return 0;
355 }
356  
357 182 return 1;
358 }
359  
360 183 ▶sub _response_body_ready ($self, $response) {
Subroutine _response_body_ready: called CC=14 SCAR=26.5
361 183 ▶ return if !$response;
Branch: 1 branch
BranchTrueFalseTotal
unless $response 0 183 183
362 183 ▶ return if $self->{_http_dispatching};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_dispatching"} 0 183 183
363  
364 183 ▶ my $active_response = $self->{_http_active_response} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $active_response = $self->{"_http_active_response"} or return 174 9 183
365 174 ▶ return if refaddr($active_response) != refaddr($response);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::refaddr($active_response) != builtin::refaddr($response) 0 174 174
366  
367 174 ▶ return if $self->{_http_response_output_complete};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_response_output_complete"} 36 138 174
368  
369 138 my $transaction = $self->{_http_active_transaction};
370 138 ▶ if ((($response->{_server_flags} // 0) & 1)
Branch: 1 branch
BranchTrueFalseTotal
if (($response->{"_server_flags"} // 0) & 1 and ($response->{"body_kind"} // "") eq "scalar") 36 102 138
Condition85%6/7
($response->{"_server_flags"} // 0) & 1 and ($response->{"body_kind"} // "") eq "scalar"
!ll&&!rl&&r
683436
$response->{"_server_flags"} // 0
l!l
1380
$response->{"body_kind"} // ""
l!l
3634
MC/DC50%1/2
($response->{"_server_flags"} // 0) & 1 and ($response->{"body_kind"} // "") eq "scalar"
$response->{"_server_flags"} $response->{"body_kind"}
Truth table66%2/3
A and B
A= $response->{"_server_flags"}B= $response->{"body_kind"}
ABresult
0X0
100
111
371 && ($response->{body_kind} // '') eq 'scalar') {
372 return if $self->_try_native_default_final(
373 $transaction, $response->{body},
374 36 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_try_native_default_final($transaction, $response->{"body"}) 29 7 36
375 }
376  
377 109 ▶ return if ($response->{body_kind} // '') ne 'scalar';
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{"body_kind"} // "") ne "scalar" 53 56 109
Condition100%2/2
$response->{"body_kind"} // ""
l!l
5752
MC/DC100%1/1
$response->{"body_kind"} // ""
$response->{"body_kind"}
Truth table100%2/2
A
A= $response->{"body_kind"}
Aresult
11
00
378 56 my $body = $response->{body};
379 56 ▶ return if $self->_try_simple_scalar_final($response, $body);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_try_simple_scalar_final($response, $body) 38 18 56
380 18 $self->_write_response(
381 $response, $body, 1, 'send_response',
382 );
383 17 return;
384 }
385  
386  
387 58 ▶sub _try_simple_scalar_final ($self, $response, $body) {
Subroutine _try_simple_scalar_final: called CC=13 SCAR=29.2
388 58 ▶ my $request = $self->{_http_active_request} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $request = $self->{"_http_active_request"} or return 0 58 0 58
389 58 ▶ return 0 if $self->{_http_response_state};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_response_state"} 0 58 58
390  
391 58 my $wire = Linux::Event::HTTP::_HTTP1
392 ->build_simple_scalar_final($request, $response, $body);
393 58 ▶ return 0 if !defined $wire;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $wire 20 38 58
394  
395 38 my $request_state = $self->{_http_request_state};
396  
397 # The ordinary synchronous bodyless response has no materialized
398 # Transaction and no later request-body phase that needs output state.
399 # Keep only the started bit across write() for exception safety, then
400 # retire the three live exchange references directly.
401 38 ▶ if ($request_state && $request_state->{body_done}
Branch: 1 branch
BranchTrueFalseTotal
if ($request_state and $request_state->{"body_done"} and not $self->{"_http_active_transaction"}) 21 17 38
Condition66%4/6
$request_state and $request_state->{"body_done"} and not $self->{"_http_active_transaction"}
!ll&&!rl&&r
17021
$request_state and $request_state->{"body_done"}
!ll&&!rl&&r
01721
MC/DC33%1/3
$request_state and $request_state->{"body_done"} and not $self->{"_http_active_transaction"}
$request_state $request_state->{"body_done"} not $self->{"_http_active_transaction"}
Truth table50%2/4
A and B and not(C)
A= $request_stateB= $request_state->{"body_done"}C= not $self->{"_http_active_transaction"}
ABCresult
0XX0
10X0
1100
1111
402 && !$self->{_http_active_transaction}) {
403 21 $self->{_http_response_output_started} = 1;
404 21 $self->write($wire);
405 21 $self->{_http_active_request} = undef;
406 21 $self->{_http_active_response} = undef;
407 21 $self->{_http_request_state} = undef;
408 21 $self->{_http_response_output_started} = 0;
409 21 ▶ $self->resume_read if $self->is_read_paused;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_read_paused 0 21 21
410 21 return 1;
411 }
412  
413 17 $self->{_http_response_output_started} = 1;
414 17 $self->{_http_response_output_complete} = 1;
415 17 ▶ if (my $transaction = $self->{_http_active_transaction}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $transaction = $self->{"_http_active_transaction"}) 0 17 17
416 0 $transaction->{response_output_started} = 1;
417 0 $transaction->{response_output_complete} = 1;
418 }
419  
420 17 $self->write($wire);
421  
422 17 ▶ if ($request_state && $request_state->{body_done}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request_state and $request_state->{"body_done"}) 0 17 17
Condition33%1/3
$request_state and $request_state->{"body_done"}
!ll&&!rl&&r
0170
MC/DC0%0/2
$request_state and $request_state->{"body_done"}
$request_state $request_state->{"body_done"}
Truth table33%1/3
A and B
A= $request_stateB= $request_state->{"body_done"}
ABresult
0X0
100
111
423 0 ▶ if (my $transaction = $self->{_http_active_transaction}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $transaction = $self->{"_http_active_transaction"}) 0 0 0
424 0 $transaction->{state} = 'complete';
425 }
426 0 $self->_clear_transaction;
427 }
428  
429 17 ▶ $self->resume_read if $self->is_read_paused;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_read_paused 0 17 17
430 17 return 1;
431 }
432  
433 2 ▶sub _send_http_response ($self, $transaction) {
Subroutine _send_http_response: called CC=11 SCAR=28.2
434 croak 'send_response(): connection is closing or closed'
435 2 ▶ if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 2 2
Condition33%1/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
002
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table33%1/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
436  
437 2 my $active = $self->{_http_active_transaction};
438 2 ▶ croak 'send_response(): Transaction is not active on this HTTP connection'
Branch: 1 branch
BranchTrueFalseTotal
if not $active or builtin::refaddr($active) != builtin::refaddr($transaction) 0 2 2
Condition33%1/3
not $active or builtin::refaddr($active) != builtin::refaddr($transaction)
l!l&&r!l&&!r
002
MC/DC0%0/2
not $active or builtin::refaddr($active) != builtin::refaddr($transaction)
not $active builtin::refaddr($active) != builtin::refaddr($transaction)
Truth table33%1/3
not(A) or B
A= not $activeB= builtin::refaddr($active) != builtin::refaddr($transaction)
ABresult
1X1
011
000
439 if !$active || refaddr($active) != refaddr($transaction);
440 2 ▶ croak 'send_response(): response output has already started'
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_response_started 0 2 2
441 if $transaction->is_response_started;
442  
443 2 ▶ my $response = $transaction->response
Branch: 1 branch
BranchTrueFalseTotal
my $response = $transaction->response or croak("send_response(): Transaction has no Response") 2 0 2
444 or croak 'send_response(): Transaction has no Response';
445 croak 'send_response(): Response does not have a complete scalar body'
446 2 ▶ if ($response->{body_kind} // '') ne 'scalar';
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{"body_kind"} // "") ne "scalar" 0 2 2
Condition50%1/2
$response->{"body_kind"} // ""
l!l
20
MC/DC0%0/1
$response->{"body_kind"} // ""
$response->{"body_kind"}
Truth table50%1/2
A
A= $response->{"body_kind"}
Aresult
11
00
447  
448 2 my $body = $response->{body};
449 2 ▶ return 1 if $self->_try_native_default_final($transaction, $body);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_try_native_default_final($transaction, $body) 0 2 2
450 2 ▶ return 1 if $self->_try_simple_scalar_final($response, $body);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_try_simple_scalar_final($response, $body) 0 2 2
451  
452 2 $self->_write_response($response, $body, 1, 'send_response');
453 2 return 1;
454 }
455  
456 38 ▶sub _try_native_default_final ($self, $transaction, $body) {
Subroutine _try_native_default_final: called CC=21 SCAR=34.1
457 my $response = $transaction
458 ? $transaction->{response}
459 38 ▶ : $self->{_http_active_response};
Branch: 1 branch
BranchTrueFalseTotal
$transaction ? : 3 35 38
460 38 ▶ return 0 if !$response;
Branch: 1 branch
BranchTrueFalseTotal
unless $response 0 38 38
461 38 ▶ return 0 if !(($response->{_server_flags} // 0) & 1);
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->{"_server_flags"} // 0) & 1 1 37 38
Condition50%1/2
$response->{"_server_flags"} // 0
l!l
380
MC/DC0%0/1
$response->{"_server_flags"} // 0
$response->{"_server_flags"}
Truth table50%1/2
A
A= $response->{"_server_flags"}
Aresult
11
00
462 37 ▶ return 0 if (($response->{status} // 200) != 200);
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{"status"} // 200) != 200 0 37 37
Condition50%1/2
$response->{"status"} // 200
l!l
037
MC/DC0%0/1
$response->{"status"} // 200
$response->{"status"}
Truth table50%1/2
A
A= $response->{"status"}
Aresult
11
00
463 37 ▶ return 0 if defined $response->{reason};
Branch: 1 branch
BranchTrueFalseTotal
if defined $response->{"reason"} 0 37 37
464 37 my $headers = $response->{headers};
465 37 ▶ return 0 if defined($headers)
Branch: 1 branch
BranchTrueFalseTotal
if defined $headers and ref $headers ne "ARRAY" || @$headers 0 37 37
Condition16%1/6
defined $headers and ref $headers ne "ARRAY" || @$headers
!ll&&!rl&&r
3700
ref $headers ne "ARRAY" or @$headers
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $headers and ref $headers ne "ARRAY" || @$headers
defined $headers ref $headers ne "ARRAY" @$headers
Truth table25%1/4
A and B or C
A= defined $headersB= ref $headers ne "ARRAY"C= @$headers
ABCresult
0XX0
1000
11X1
1011
466 && (ref($headers) ne 'ARRAY' || @$headers);
467 37 ▶ return 0 if $self->{_http_response_state};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_response_state"} 0 37 37
468  
469 37 ▶ my $request_state = $self->{_http_request_state} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $request_state = $self->{"_http_request_state"} or return 0 37 0 37
470 37 ▶ my $body_done = $request_state->{body_done} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$request_state->{'body_done'} ? : 27 10 37
471  
472 my $request = $transaction
473 ? $transaction->{request}
474 37 ▶ : $self->{_http_active_request};
Branch: 1 branch
BranchTrueFalseTotal
$transaction ? : 2 35 37
475 37 ▶ return 0 if !$request;
Branch: 1 branch
BranchTrueFalseTotal
unless $request 0 37 37
476 37 my $wire = Linux::Event::HTTP::_HTTP1
477 ->build_default_final($request, $body);
478 37 ▶ return 0 if !defined $wire;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $wire 8 29 37
479  
480 29 $response->{committed} = 1;
481 29 $self->{_http_response_output_started} = 1;
482 29 $self->{_http_response_output_complete} = 1;
483 29 ▶ if ($transaction) {
Branch: 1 branch
BranchTrueFalseTotal
if ($transaction) 0 29 29
484 0 $transaction->{response_output_started} = 1;
485 0 $transaction->{response_output_complete} = 1;
486 }
487 29 $self->{_http_response_state} = undef;
488  
489 29 $self->write($wire);
490  
491 29 ▶ if ($body_done) {
Branch: 1 branch
BranchTrueFalseTotal
if ($body_done) 22 7 29
492 22 ▶ $transaction->{state} = 'complete' if $transaction;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction 0 22 22
493 22 $self->_clear_transaction;
494 }
495  
496 29 ▶ $self->resume_read if $self->is_read_paused;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_read_paused 0 29 29
497 29 return 1;
498 }
499  
500 4 ▶sub _upgrade_http_transaction ($self, $transaction, $target_class) {
Subroutine _upgrade_http_transaction: called CC=1 SCAR=0.0
501 4 require Linux::Event::HTTP::_Upgrade;
502 4 Linux::Event::HTTP::_Upgrade->schedule(
503 $self, $transaction, $target_class,
504 );
505 2 return $transaction;
506 }
507  
508 13 ▶sub _tunnel_http_transaction ($self, $transaction, $target_class) {
Subroutine _tunnel_http_transaction: called CC=1 SCAR=0.0
509 13 require Linux::Event::HTTP::_ServerConnect;
510 13 Linux::Event::HTTP::_ServerConnect->schedule(
511 $self, $transaction, $target_class,
512 );
513 2 return $transaction;
514 }
515  
516 54 ▶sub _complete_active_transaction_state ($self) {
Subroutine _complete_active_transaction_state: called CC=7 SCAR=21.0
517 54 ▶ my $transaction = $self->{_http_active_transaction} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $transaction = $self->{"_http_active_transaction"} or return 17 37 54
518 17 ▶ return if $transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal 0 17 17
519  
520 17 ▶ croak 'cannot complete server Transaction before Request body completion'
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->request->is_complete 0 17 17
521 if !$transaction->request->is_complete;
522 17 my $response = $transaction->response;
523 17 ▶ croak 'cannot complete server Transaction before Response body completion'
Branch: 1 branch
BranchTrueFalseTotal
unless $response and $response->is_complete 0 17 17
Condition33%1/3
$response and $response->is_complete
!ll&&!rl&&r
0017
MC/DC0%0/2
$response and $response->is_complete
$response $response->is_complete
Truth table33%1/3
A and B
A= $responseB= $response->is_complete
ABresult
0X0
100
111
524 if !$response || !$response->is_complete;
525 17 ▶ croak 'cannot complete server Transaction before Response output completion'
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->_is_response_output_complete 0 17 17
526 if !$transaction->_is_response_output_complete;
527  
528 17 $transaction->_mark_complete;
529 17 return;
530 }
531  
532 38 ▶sub _fail_active_transaction_state ($self, $error) {
Subroutine _fail_active_transaction_state: called CC=3 SCAR=11.0
533 38 ▶ my $transaction = $self->{_http_active_transaction} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $transaction = $self->{"_http_active_transaction"} or return 26 12 38
534 26 ▶ return if $transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal 13 13 26
535 13 $transaction->_fail($error);
536 13 return;
537 }
538  
539 101 ▶sub _clear_transaction ($self) {
Subroutine _clear_transaction: called CC=1 SCAR=0.0
540 101 $self->{_http_active_transaction} = undef;
541 101 $self->{_http_active_request} = undef;
542 101 $self->{_http_active_response} = undef;
543 101 $self->{_http_request_state} = undef;
544 101 $self->{_http_response_state} = undef;
545 101 $self->{_http_response_output_started} = 0;
546 101 $self->{_http_response_output_complete} = 0;
547 101 delete $self->{_http_pending_upgrade};
548 101 delete $self->{_http_pending_tunnel};
549 101 return;
550 }
551  
552 0 ▶sub _cancel_http_transaction ($self, $transaction) {
Subroutine _cancel_http_transaction: not called CC=5 SCAR=34.0
553 0 ▶ return if $transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction->is_terminal 0 0 0
554  
555 0 my $active = $self->{_http_active_transaction};
556 0 ▶ croak 'cancel(): Transaction is not active on this HTTP connection'
Branch: 1 branch
BranchTrueFalseTotal
if not $active or builtin::refaddr($active) != builtin::refaddr($transaction) 0 0 0
Condition0%0/3
not $active or builtin::refaddr($active) != builtin::refaddr($transaction)
l!l&&r!l&&!r
000
MC/DC0%0/2
not $active or builtin::refaddr($active) != builtin::refaddr($transaction)
not $active builtin::refaddr($active) != builtin::refaddr($transaction)
Truth table0%0/3
not(A) or B
A= not $activeB= builtin::refaddr($active) != builtin::refaddr($transaction)
ABresult
1X1
011
000
557 if !$active || refaddr($active) != refaddr($transaction);
558  
559 0 $transaction->_mark_cancelled;
560 0 $self->_clear_transaction;
561 0 $self->{_http_input} = '';
562 0 $self->{_http_closing} = 1;
563 0 ▶ $self->pause_read if !$self->is_read_paused;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_read_paused 0 0 0
564 0 $self->end;
565 0 return;
566 }
567  
568 0 ▶sub _abort_started_response ($self) {
Subroutine _abort_started_response: not called CC=4 SCAR=30.0
569 0 ▶ return if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 0 0
Condition0%0/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table0%0/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
570  
571 0 $self->_clear_transaction;
572 0 $self->{_http_input} = '';
573 0 $self->{_http_closing} = 1;
574 0 ▶ $self->pause_read if !$self->is_read_paused;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_read_paused 0 0 0
575 0 $self->end;
576 0 return;
577 }
578  
579 18 ▶sub _fail_active_transaction ($self, $status, $request, $response) {
Subroutine _fail_active_transaction: called CC=5 SCAR=18.1
580 18 ▶ return if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 18 18
Condition33%1/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
0018
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table33%1/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
581  
582 18 my $transaction = $self->{_http_active_transaction};
583 18 ▶ my $started = $self->{_http_response_output_started} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_http_response_output_started'} ? : 0 18 18
584 18 $self->_fail_active_transaction_state("HTTP server transaction failed ($status)");
585  
586 18 ▶ if ($started) {
Branch: 1 branch
BranchTrueFalseTotal
if ($started) { } 0 18 18
587 0 $self->_abort_started_response;
588 } else {
589 18 $self->_protocol_error($status, $request->version);
590 }
591 18 return;
592 }
593  
594 23 ▶sub _finish_request_body ($self) {
Subroutine _finish_request_body: called CC=11 SCAR=26.1
595 23 ▶ my $request = $self->{_http_active_request} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $request = $self->{"_http_active_request"} or return 23 0 23
596 23 ▶ my $response = $self->{_http_active_response} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $response = $self->{"_http_active_response"} or return 23 0 23
597 23 ▶ my $state = $self->{_http_request_state} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $state = $self->{"_http_request_state"} or return 23 0 23
598 23 ▶ return if $state->{body_done};
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"body_done"} 0 23 23
599  
600 23 $state->{body_done} = 1;
601 23 $request->_mark_complete;
602 23 delete $state->{decoder};
603 23 delete $state->{remaining};
604  
605 return if !$self->_invoke_http_callback(
606 23 ▶ $self->{_http_on_request_end}, $request, $response,
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_invoke_http_callback($self->{"_http_on_request_end"}, $request, $response) 0 23 23
607 );
608 23 ▶ return if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 3 20 23
Condition66%2/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
3020
MC/DC50%1/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table66%2/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
609 20 ▶ return if !$self->{_http_active_request};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_http_active_request"} 14 6 20
610  
611 6 ▶ if ($self->{_http_response_output_complete}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_http_response_output_complete'}) { } 6 0 6
612 6 $self->_finalize_transaction;
613 } else {
614 0 ▶ $self->pause_read if !$self->is_read_paused;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_read_paused 0 0 0
615 }
616 6 return;
617 }
618  
619 0 ▶sub _consume_request_body ($self) {
Subroutine _consume_request_body: not called CC=29 SCAR=67.7
620 0 ▶ my $request = $self->{_http_active_request} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $request = $self->{"_http_active_request"} or return 0 0 0 0
621 0 ▶ my $response = $self->{_http_active_response} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $response = $self->{"_http_active_response"} or return 0 0 0 0
622 0 ▶ my $state = $self->{_http_request_state} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $state = $self->{"_http_request_state"} or return 0 0 0 0
623 0 ▶ return 0 if $state->{body_done};
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"body_done"} 0 0 0
624  
625 0 ▶ if ($state->{mode} eq 'content-length') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"mode"} eq "content-length") 0 0 0
626 0 ▶ if (($state->{remaining} // 0) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (($state->{"remaining"} // 0) == 0) 0 0 0
Condition0%0/2
$state->{"remaining"} // 0
l!l
00
MC/DC0%0/1
$state->{"remaining"} // 0
$state->{"remaining"}
Truth table0%0/2
A
A= $state->{"remaining"}
Aresult
11
00
627 0 $self->_finish_request_body;
628 0 return 1;
629 }
630 0 ▶ return 0 if !length($self->{_http_input});
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"_http_input"} 0 0 0
631  
632 0 my $available = length($self->{_http_input});
633 my $take = $available < $state->{remaining}
634 0 ▶ ? $available : $state->{remaining};
Branch: 1 branch
BranchTrueFalseTotal
$available < $state->{'remaining'} ? : 0 0 0
635  
636 0 my $chunk;
637 0 ▶ if ($self->{_http_on_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_http_on_body'}) { } 0 0 0
638 0 $chunk = substr($self->{_http_input}, 0, $take, '');
639 } else {
640 0 substr($self->{_http_input}, 0, $take, '');
641 }
642 0 $state->{remaining} -= $take;
643  
644 0 ▶ if (defined($chunk) && length($chunk)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $chunk and length $chunk) 0 0 0
Condition0%0/3
defined $chunk and length $chunk
!ll&&!rl&&r
000
MC/DC0%0/2
defined $chunk and length $chunk
defined $chunk length $chunk
Truth table0%0/3
A and B
A= defined $chunkB= length $chunk
ABresult
0X0
100
111
645 return 1 if !$self->_invoke_http_callback(
646 0 ▶ $self->{_http_on_body}, $request, $response, $chunk,
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_invoke_http_callback($self->{"_http_on_body"}, $request, $response, $chunk) 0 0 0
647 );
648 0 ▶ return 1 if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 0 0
Condition0%0/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table0%0/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
649 0 ▶ return 1 if !$self->{_http_active_request};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_http_active_request"} 0 0 0
650 }
651  
652 0 ▶ $self->_finish_request_body if $state->{remaining} == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"remaining"} == 0 0 0 0
653 0 return 1;
654 }
655  
656 0 ▶ if ($state->{mode} eq 'chunked') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"mode"} eq "chunked") 0 0 0
657 0 ▶ return 0 if !length($self->{_http_input});
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"_http_input"} 0 0 0
658  
659 0 my ($done, $decoded);
660 0 my $ok = eval {
661 ($done, $decoded) = $state->{decoder}->feed(
662 0 ▶ $self->{_http_input}, $self->{_http_on_body} ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_http_on_body'} ? : 0 0 0
663 );
664 0 1;
665 };
666 0 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
667 0 $self->_fail_active_transaction(400, $request, $response);
668 0 return 1;
669 }
670  
671 0 ▶ if (defined($decoded) && length($decoded)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $decoded and length $decoded) 0 0 0
Condition0%0/3
defined $decoded and length $decoded
!ll&&!rl&&r
000
MC/DC0%0/2
defined $decoded and length $decoded
defined $decoded length $decoded
Truth table0%0/3
A and B
A= defined $decodedB= length $decoded
ABresult
0X0
100
111
672 return 1 if !$self->_invoke_http_callback(
673 0 ▶ $self->{_http_on_body}, $request, $response, $decoded,
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_invoke_http_callback($self->{"_http_on_body"}, $request, $response, $decoded) 0 0 0
674 );
675 0 ▶ return 1 if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 0 0
Condition0%0/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table0%0/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
676 0 ▶ return 1 if !$self->{_http_active_request};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_http_active_request"} 0 0 0
677 }
678  
679 0 ▶ $self->_finish_request_body if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 0 0 0
680 0 return 1;
681 }
682  
683 0 $self->_finish_request_body;
684 0 return 1;
685 }
686  
687 38 ▶sub _finalize_transaction ($self) {
Subroutine _finalize_transaction: called CC=10 SCAR=23.8
688 38 ▶ return if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 38 38
Condition33%1/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
0038
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table33%1/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
689  
690 38 my $request_state = $self->{_http_request_state};
691 my $close_after = $request_state
692 38 ▶ && $request_state->{close_after_response} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$request_state && $request_state->{'close_after_response'} ? : 5 33 38
Condition66%2/3
$request_state and $request_state->{"close_after_response"}
!ll&&!rl&&r
0335
MC/DC50%1/2
$request_state and $request_state->{"close_after_response"}
$request_state $request_state->{"close_after_response"}
Truth table66%2/3
A and B
A= $request_stateB= $request_state->{"close_after_response"}
ABresult
0X0
100
111
693  
694 38 $self->_complete_active_transaction_state;
695 38 $self->_clear_transaction;
696  
697 38 ▶ if ($close_after) {
Branch: 1 branch
BranchTrueFalseTotal
if ($close_after) 5 33 38
698 5 $self->{_http_input} = '';
699 5 $self->{_http_closing} = 1;
700 5 ▶ $self->pause_read if !$self->is_read_paused;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_read_paused 5 0 5
701 5 $self->end;
702 5 return;
703 }
704  
705 33 ▶ $self->resume_read if $self->is_read_paused;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_read_paused 0 33 33
706 $self->_drive_http1
707 33 ▶ if !$self->{_http_driving} && !$self->{_http_dispatching};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_http_driving"} or $self->{"_http_dispatching"} 29 4 33
Condition66%2/3
$self->{"_http_driving"} or $self->{"_http_dispatching"}
l!l&&r!l&&!r
0429
MC/DC50%1/2
$self->{"_http_driving"} or $self->{"_http_dispatching"}
$self->{"_http_driving"} $self->{"_http_dispatching"}
Truth table66%2/3
A or B
A= $self->{"_http_driving"}B= $self->{"_http_dispatching"}
ABresult
1X1
011
000
708 33 return;
709 }
710  
711 122 ▶sub _activate_native_http_request ($self, $request) {
Subroutine _activate_native_http_request: called CC=30 SCAR=36.0
712 122 ▶ return 0 if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 122 122
Condition33%1/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
00122
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table33%1/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
713 croak 'cannot activate a new HTTP Request while another Request is active'
714 122 ▶ if $self->{_http_active_request};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_active_request"} 0 122 122
715  
716 122 my $expect = $request->_expect_continue;
717 122 ▶ if ($expect < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expect < 0) 2 120 122
718 2 $self->_protocol_error(417, $request->version);
719 2 return 0;
720 }
721  
722 120 my $body_mode = $request->_http1_body_mode;
723 120 my $bodyless = $body_mode eq 'none';
724  
725 120 my $response = Linux::Event::HTTP::Response
726 ->_new_server_default($request);
727  
728 120 my $request_state;
729 120 ▶ if ($bodyless) {
Branch: 2 branches
BranchTrueFalseTotal
if ($bodyless) { } 89 31 120
elsif ($body_mode eq 'chunked') { } 11 20 31
730 89 $request_state = $self->{_http_bodyless_state};
731 89 ▶ if (!$request_state) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $request_state) { } 64 25 89
elsif ($self->{'_http_on_request_end'}) { } 7 18 25
732 $request_state = $self->{_http_bodyless_state} = {
733 mode => 'none',
734 64 ▶ body_done => $self->{_http_on_request_end} ? 0 : 1,
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_http_on_request_end'} ? : 28 36 64
735 };
736 } elsif ($self->{_http_on_request_end}) {
737 7 $request_state->{body_done} = 0;
738 }
739 } elsif ($body_mode eq 'chunked') {
740 11 $request_state = {
741 mode => 'chunked',
742 body_done => 0,
743 };
744 } else {
745 20 $request_state = _new_request_state($request, $body_mode);
746 }
747  
748 120 $self->{_http_active_request} = $request;
749 120 $self->{_http_active_response} = $response;
750 120 $self->{_http_request_state} = $request_state;
751  
752 120 ▶ if ($expect && _body_pending($request_state)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expect and _body_pending($request_state)) 1 119 120
Condition66%2/3
$expect and _body_pending($request_state)
!ll&&!rl&&r
11901
MC/DC50%1/2
$expect and _body_pending($request_state)
$expect _body_pending($request_state)
Truth table66%2/3
A and B
A= $expectB= _body_pending($request_state)
ABresult
0X0
100
111
753 1 $self->write("HTTP/1.1 100 Continue\r\n\r\n");
754 }
755  
756 120 ▶ if (!$self->_invoke_http_callback(
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_invoke_http_callback($self->{"_http_on_request"}, $request, $response)) 16 104 120
757 $self->{_http_on_request}, $request, $response,
758 )) {
759 16 return 0;
760 }
761 104 ▶ return 0 if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 7 97 104
Condition100%3/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
6197
MC/DC100%2/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table100%3/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
762 97 ▶ return 1 if !$self->{_http_active_request};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_http_active_request"} 34 63 97
763  
764 63 ▶ if ($bodyless) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bodyless) 35 28 63
765 35 ▶ if ($self->{_http_on_request_end}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_http_on_request_end"}) 32 3 35
766 32 $request_state->{body_done} = 1;
767 return 0 if !$self->_invoke_http_callback(
768 32 ▶ $self->{_http_on_request_end}, $request, $response,
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_invoke_http_callback($self->{"_http_on_request_end"}, $request, $response) 0 32 32
769 );
770 32 ▶ return 0 if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 1 31 32
Condition66%2/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
1031
MC/DC50%1/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table66%2/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
771 31 ▶ return 1 if !$self->{_http_active_request};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_http_active_request"} 2 29 31
772 }
773  
774 32 ▶ if ($self->{_http_response_output_complete}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_http_response_output_complete"}) 25 7 32
775 25 $self->_finalize_transaction;
776 25 ▶ return 0 if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 5 20 25
Condition66%2/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
5020
MC/DC50%1/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table66%2/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
777 20 return 1;
778 }
779  
780 7 ▶ $self->pause_read if !$self->is_read_paused;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_read_paused 7 0 7
781 7 return 0;
782 }
783  
784 28 ▶ if (!_body_pending($request_state)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_body_pending($request_state)) 0 28 28
785 0 $self->_finish_request_body;
786 0 ▶ return 0 if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 0 0
Condition0%0/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table0%0/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
787 0 ▶ return 1 if !$self->{_http_active_request};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_http_active_request"} 0 0 0
788 0 return 0;
789 }
790  
791 28 return 2;
792 }
793  
794 29 ▶sub _drive_http1 ($self) {
Subroutine _drive_http1: called CC=37 SCAR=69.8
795 return if $self->{_http_driving} || $self->{_http_closing}
796 29 ▶ || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_driving"} or $self->{"_http_closing"} or $self->is_closed 0 29 29
Condition33%2/6
$self->{"_http_driving"} or $self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
0029
$self->{"_http_driving"} or $self->{"_http_closing"}
l!l&&r!l&&!r
0029
MC/DC0%0/3
$self->{"_http_driving"} or $self->{"_http_closing"} or $self->is_closed
$self->{"_http_driving"} $self->{"_http_closing"} $self->is_closed
Truth table25%1/4
A or B or C
A= $self->{"_http_driving"}B= $self->{"_http_closing"}C= $self->is_closed
ABCresult
1XX1
01X1
0011
0000
797  
798 29 local $self->{_http_driving} = 1;
799  
800 29 ▶ while (!$self->{_http_closing} && !$self->is_closed) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_http_closing"} or $self->is_closed) 29 0 29
Condition33%1/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
0029
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table33%1/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
801 29 ▶ if (my $request = $self->{_http_active_request}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $request = $self->{"_http_active_request"}) 0 29 29
802 0 my $response = $self->{_http_active_response};
803 0 my $state = $self->{_http_request_state};
804 0 my $transaction = $self->{_http_active_transaction};
805  
806 0 ▶ if (!$state->{body_done}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($state->{"body_done"}) 0 0 0
807 0 ▶ if (!_body_pending($state)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_body_pending($state)) 0 0 0
808 0 $self->_finish_request_body;
809 0 next;
810 }
811  
812 0 ▶ last if !length($self->{_http_input});
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"_http_input"} 0 0 0
813 0 $self->_consume_request_body;
814 0 next;
815 }
816  
817 0 ▶ if ($self->{_http_response_output_complete}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_http_response_output_complete"}) 0 0 0
818 0 $self->_finalize_transaction;
819 0 next;
820 }
821  
822 0 ▶ $self->pause_read if $response && !$self->is_read_paused;
Branch: 1 branch
BranchTrueFalseTotal
if $response and not $self->is_read_paused 0 0 0
Condition0%0/3
$response and not $self->is_read_paused
!ll&&!rl&&r
000
MC/DC0%0/2
$response and not $self->is_read_paused
$response not $self->is_read_paused
Truth table0%0/3
A and not(B)
A= $responseB= not $self->is_read_paused
ABresult
0X0
100
111
823 0 last;
824 }
825  
826 29 ▶ last if !length($self->{_http_input});
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"_http_input"} 29 0 29
827  
828 my $request = $PARSER->_parse_server_request(
829 0 $self->{_http_input}, $MAX_REQUEST_HEAD, $MAX_HEADERS,
830 );
831  
832 0 ▶ if (!defined $request) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $request) 0 0 0
833 0 last;
834 }
835 0 ▶ if (!ref $request) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $request) 0 0 0
836 0 $self->_protocol_error(0 + $request);
837 0 last;
838 }
839  
840 0 my $consumed = $request->_consumed;
841 0 ▶ if ($consumed > $MAX_REQUEST_HEAD) {
Branch: 1 branch
BranchTrueFalseTotal
if ($consumed > $MAX_REQUEST_HEAD) 0 0 0
842 0 $self->_protocol_error(431, $request->version);
843 0 last;
844 }
845 0 substr($self->{_http_input}, 0, $consumed, '');
846  
847 0 my $expect = $request->_expect_continue;
848 0 ▶ if ($expect < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expect < 0) 0 0 0
849 0 $self->_protocol_error(417, $request->version);
850 0 last;
851 }
852  
853 0 my $body_mode = $request->_http1_body_mode;
854 0 my $bodyless = $body_mode eq 'none';
855  
856 0 my $response = Linux::Event::HTTP::Response
857 ->_new_server_default($request);
858  
859 0 my $request_state;
860 0 ▶ if ($bodyless) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bodyless) { } 0 0 0
861 0 $request_state = $self->{_http_bodyless_state};
862 0 ▶ if (!$request_state) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $request_state) { } 0 0 0
elsif ($self->{'_http_on_request_end'}) { } 0 0 0
863 $request_state = $self->{_http_bodyless_state} = {
864 mode => 'none',
865 0 ▶ body_done => $self->{_http_on_request_end} ? 0 : 1,
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_http_on_request_end'} ? : 0 0 0
866 };
867 } elsif ($self->{_http_on_request_end}) {
868 0 $request_state->{body_done} = 0;
869 }
870  
871 # Native bodyless Requests are intrinsically complete: Request
872 # derives this from the parser's body mode. Do not create a
873 # fieldhash completion override for every ordinary request.
874 } else {
875 0 $request_state = _new_request_state($request, $body_mode);
876 }
877  
878 # A new request is reached only after the previous exchange was
879 # cleared (or on a freshly initialized Connection), so transaction,
880 # response-state, and output-progress fields are already neutral.
881 0 $self->{_http_active_request} = $request;
882 0 $self->{_http_active_response} = $response;
883 0 $self->{_http_request_state} = $request_state;
884  
885 0 ▶ if ($expect && _body_pending($request_state)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expect and _body_pending($request_state)) 0 0 0
Condition0%0/3
$expect and _body_pending($request_state)
!ll&&!rl&&r
000
MC/DC0%0/2
$expect and _body_pending($request_state)
$expect _body_pending($request_state)
Truth table0%0/3
A and B
A= $expectB= _body_pending($request_state)
ABresult
0X0
100
111
886 0 $self->write("HTTP/1.1 100 Continue\r\n\r\n");
887 }
888  
889 0 ▶ if (!$self->_invoke_http_callback(
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_invoke_http_callback($self->{"_http_on_request"}, $request, $response)) 0 0 0
890 $self->{_http_on_request}, $request, $response,
891 )) {
892 0 last;
893 }
894 0 ▶ last if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 0 0
Condition0%0/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table0%0/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
895 0 ▶ next if !$self->{_http_active_request};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_http_active_request"} 0 0 0
896  
897 0 ▶ if ($bodyless) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bodyless) 0 0 0
898 0 ▶ if ($self->{_http_on_request_end}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_http_on_request_end"}) 0 0 0
899 0 $request_state->{body_done} = 1;
900 last if !$self->_invoke_http_callback(
901 0 ▶ $self->{_http_on_request_end}, $request, $response,
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_invoke_http_callback($self->{"_http_on_request_end"}, $request, $response) 0 0 0
902 );
903 0 ▶ last if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 0 0
Condition0%0/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table0%0/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
904 0 ▶ next if !$self->{_http_active_request};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_http_active_request"} 0 0 0
905 }
906  
907 0 ▶ if ($self->{_http_response_output_complete}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_http_response_output_complete"}) 0 0 0
908 0 $self->_finalize_transaction;
909 0 next;
910 }
911  
912 0 ▶ $self->pause_read if !$self->is_read_paused;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_read_paused 0 0 0
913 0 last;
914 }
915  
916 0 ▶ if (!_body_pending($request_state)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_body_pending($request_state)) 0 0 0
917 0 $self->_finish_request_body;
918 }
919 }
920  
921 29 return;
922 }
923  
924 38 ▶sub _body_bytes ($operation, $body) {
Subroutine _body_bytes: called CC=5 SCAR=20.1
925 38 ▶ croak "$operation(): body must be a scalar byte string" if ref($body);
Branch: 1 branch
BranchTrueFalseTotal
if ref $body 0 38 38
926  
927 38 ▶ my $bytes = defined($body) ? "$body" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $body ? : 38 0 38
928 38 ▶ if (utf8::is_utf8($bytes)) {
Branch: 1 branch
BranchTrueFalseTotal
if (utf8::is_utf8($bytes)) 0 38 38
929 0 ▶ croak "$operation(): body contains wide characters; encode it to bytes first"
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::downgrade($bytes, 1) 0 0 0
930 if !utf8::downgrade($bytes, 1);
931 }
932 38 return $bytes;
933 }
934  
935 21 ▶sub _canonical_decimal ($value) {
Subroutine _canonical_decimal: called CC=3 SCAR=12.0
936 21 ▶ return undef if !defined($value) || $value !~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and $value =~ /\A\d+\z/u 0 21 21
Condition33%1/3
defined $value and $value =~ /\A\d+\z/u
!ll&&!rl&&r
0021
MC/DC0%0/2
defined $value and $value =~ /\A\d+\z/u
defined $value $value =~ /\A\d+\z/u
Truth table33%1/3
A and B
A= defined $valueB= $value =~ /\A\d+\z/u
ABresult
0X0
100
111
937 21 my $decimal = "$value";
938 21 $decimal =~ s/\A0+(?=\d)//;
939 21 return $decimal;
940 }
941  
942 23 ▶sub _compare_count ($count, $decimal) {
Subroutine _compare_count: called CC=2 SCAR=6.9
943 23 my $actual = "$count";
944 23 ▶ return length($actual) <=> length($decimal)
Condition100%3/3
length $actual <=> length $decimal || $actual cmp $decimal
l!l&&r!l&&!r
1121
MC/DC100%2/2
length $actual <=> length $decimal || $actual cmp $decimal
length $actual <=> length $decimal $actual cmp $decimal
Truth table100%3/3
A || B
A= length $actual <=> length $decimalB= $actual cmp $decimal
ABresult
1X1
011
000
945 || $actual cmp $decimal;
946 }
947  
948 12 ▶sub _chunk_wire ($bytes) {
Subroutine _chunk_wire: called CC=2 SCAR=6.9
949 12 ▶ return '' if !length($bytes);
Branch: 1 branch
BranchTrueFalseTotal
unless length $bytes 1 11 12
950 11 return sprintf('%x', length($bytes)) . "\r\n" . $bytes . "\r\n";
951 }
952  
953 28 ▶sub _chunked_transfer_encoding ($operation, $version, $values) {
Subroutine _chunked_transfer_encoding: called CC=9 SCAR=42.8
954 28 ▶ return 0 if !@$values;
Branch: 1 branch
BranchTrueFalseTotal
unless @$values 28 0 28
955  
956 0 ▶ croak "$operation(): Transfer-Encoding is not valid for HTTP/1.0 responses"
Branch: 1 branch
BranchTrueFalseTotal
if $version ne "1.1" 0 0 0
957 if $version ne '1.1';
958  
959 0 my @coding;
960 0 for my $value (@$values) {
961 0 for my $member (split /,/, $value, -1) {
962 0 $member =~ s/\A[ \t]+//;
963 0 $member =~ s/[ \t]+\z//;
964 0 ▶ croak "$operation(): invalid Transfer-Encoding response value"
Branch: 1 branch
BranchTrueFalseTotal
if $member eq "" or $member =~ /;/u 0 0 0
Condition0%0/3
$member eq "" or $member =~ /;/u
l!l&&r!l&&!r
000
MC/DC0%0/2
$member eq "" or $member =~ /;/u
$member eq "" $member =~ /;/u
Truth table0%0/3
A or B
A= $member eq ""B= $member =~ /;/u
ABresult
1X1
011
000
965 if $member eq '' || $member =~ /;/;
966 0 push @coding, lc $member;
967 }
968 }
969  
970 0 ▶ croak "$operation(): only chunked response Transfer-Encoding is supported"
Branch: 1 branch
BranchTrueFalseTotal
if @coding != 1 or $coding[0] ne "chunked" 0 0 0
Condition0%0/3
@coding != 1 or $coding[0] ne "chunked"
l!l&&r!l&&!r
000
MC/DC0%0/2
@coding != 1 or $coding[0] ne "chunked"
@coding != 1 $coding[0] ne "chunked"
Truth table0%0/3
A or B
A= @coding != 1B= $coding[0] ne "chunked"
ABresult
1X1
011
000
971 if @coding != 1 || $coding[0] ne 'chunked';
972  
973 0 return 1;
974 }
975  
976 28 ▶sub _response_start ($self, $response, $bytes, $final, $operation = undef) {
Subroutine _response_start: called CC=44 SCAR=42.6
977 28 my $transaction = $self->{_http_active_transaction};
978 my $request = $self->{_http_active_request}
979 28 ▶ or croak 'response output requires an active HTTP Request';
Branch: 1 branch
BranchTrueFalseTotal
my $request = $self->{"_http_active_request"} or croak("response output requires an active HTTP Request") 28 0 28
980 28 my $version = $request->version;
981 28 my $method = $request->method;
982 28 my $status = $response->status;
983 28 ▶ $operation //= $final ? 'complete' : 'write';
Branch: 1 branch
BranchTrueFalseTotal
$final ? : 0 0 0
Condition33%1/3
$operation //= $final ? "complete" : "write"
l!l&&r!l&&!r
2800
MC/DC0%0/2
$operation //= $final ? "complete" : "write"
$operation $final ? "complete" : "write"
Truth table33%1/3
A //= B
A= $operationB= $final ? "complete" : "write"
ABresult
1X1
011
000
984  
985 28 ▶ croak "$operation(): informational responses require a future interim-response API"
Branch: 1 branch
BranchTrueFalseTotal
if $status >= 100 and $status < 200 0 28 28
Condition33%1/3
$status >= 100 and $status < 200
!ll&&!rl&&r
0280
MC/DC0%0/2
$status >= 100 and $status < 200
$status >= 100 $status < 200
Truth table33%1/3
A and B
A= $status >= 100B= $status < 200
ABresult
0X0
100
111
986 if $status >= 100 && $status < 200;
987  
988 28 ▶ my $body_forbidden = $status == 204 || $status == 304;
Condition33%1/3
$status == 204 || $status == 304
l!l&&r!l&&!r
0028
MC/DC0%0/2
$status == 204 || $status == 304
$status == 204 $status == 304
Truth table33%1/3
A || B
A= $status == 204B= $status == 304
ABresult
1X1
011
000
989 28 ▶ croak "$operation(): this response status cannot carry a message body"
Branch: 1 branch
BranchTrueFalseTotal
if $body_forbidden and length $bytes 0 28 28
Condition33%1/3
$body_forbidden and length $bytes
!ll&&!rl&&r
2800
MC/DC0%0/2
$body_forbidden and length $bytes
$body_forbidden length $bytes
Truth table33%1/3
A and B
A= $body_forbiddenB= length $bytes
ABresult
0X0
100
111
990 if $body_forbidden && length($bytes);
991  
992 28 my @transfer_encoding = $response->_header_values_list('Transfer-Encoding');
993 28 my @content_length = $response->_header_values_list('Content-Length');
994 28 my $head_request = $method eq 'HEAD';
995  
996 28 ▶ croak "$operation(): response cannot contain both Transfer-Encoding and Content-Length"
Branch: 1 branch
BranchTrueFalseTotal
if @transfer_encoding and @content_length 0 28 28
Condition33%1/3
@transfer_encoding and @content_length
!ll&&!rl&&r
2800
MC/DC0%0/2
@transfer_encoding and @content_length
@transfer_encoding @content_length
Truth table33%1/3
A and B
A= @transfer_encodingB= @content_length
ABresult
0X0
100
111
997 if @transfer_encoding && @content_length;
998  
999 28 ▶ croak "$operation(): HEAD responses cannot use a streaming body"
Branch: 1 branch
BranchTrueFalseTotal
if not $final and $head_request 0 28 28
Condition66%2/3
not $final and $head_request
!ll&&!rl&&r
2080
MC/DC0%0/2
not $final and $head_request
not $final $head_request
Truth table66%2/3
not(A) and B
A= not $finalB= $head_request
ABresult
0X0
100
111
1000 if !$final && $head_request;
1001 28 ▶ croak "$operation(): this response status cannot use body streaming"
Branch: 1 branch
BranchTrueFalseTotal
if not $final and $body_forbidden 0 28 28
Condition66%2/3
not $final and $body_forbidden
!ll&&!rl&&r
2080
MC/DC0%0/2
not $final and $body_forbidden
not $final $body_forbidden
Truth table66%2/3
not(A) and B
A= not $finalB= $body_forbidden
ABresult
0X0
100
111
1002 if !$final && $body_forbidden;
1003  
1004 28 my $chunked = _chunked_transfer_encoding(
1005 $operation, $version, \@transfer_encoding,
1006 );
1007 28 my $close_delimited = 0;
1008  
1009 28 ▶ if (!@content_length && !$body_forbidden && !$chunked) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@content_length or $body_forbidden or $chunked) 26 2 28
Condition66%4/6
@content_length or $body_forbidden or $chunked
l!l&&r!l&&!r
2026
@content_length or $body_forbidden
l!l&&r!l&&!r
2026
MC/DC33%1/3
@content_length or $body_forbidden or $chunked
@content_length $body_forbidden $chunked
Truth table50%2/4
A or B or C
A= @content_lengthB= $body_forbiddenC= $chunked
ABCresult
1XX1
01X1
0011
0000
1010 26 ▶ if ($final) {
Branch: 2 branches
BranchTrueFalseTotal
if ($final) { } 19 7 26
elsif ($version eq '1.1') { } 5 2 7
1011 19 $response->header('Content-Length', length($bytes));
1012 19 @content_length = $response->_header_values_list('Content-Length');
1013 } elsif ($version eq '1.1') {
1014 5 $response->header('Transfer-Encoding', 'chunked');
1015 5 $chunked = 1;
1016 } else {
1017 2 $close_delimited = 1;
1018 }
1019 }
1020  
1021 28 my $expected;
1022 28 ▶ if (@content_length == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@content_length == 1) 21 7 28
1023 21 $expected = _canonical_decimal($content_length[0]);
1024 21 ▶ croak "$operation(): Content-Length must be a decimal number"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expected 0 21 21
1025 if !defined $expected;
1026 }
1027  
1028 28 ▶ if ($final && !$head_request && !$body_forbidden && defined $expected) {
Branch: 1 branch
BranchTrueFalseTotal
if ($final and not $head_request and not $body_forbidden and defined $expected) 20 8 28
Condition66%6/9
$final and not $head_request and not $body_forbidden and defined $expected
!ll&&!rl&&r
8020
$final and not $head_request and not $body_forbidden
!ll&&!rl&&r
8020
$final and not $head_request
!ll&&!rl&&r
8020
MC/DC25%1/4
$final and not $head_request and not $body_forbidden and defined $expected
$final not $head_request not $body_forbidden defined $expected
Truth table40%2/5
A and not(B) and not(C) and D
A= $finalB= not $head_requestC= not $body_forbiddenD= defined $expected
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1029 20 ▶ croak "$operation(): Content-Length does not match scalar body length"
Branch: 1 branch
BranchTrueFalseTotal
if _compare_count(length $bytes, $expected) != 0 1 19 20
1030 if _compare_count(length($bytes), $expected) != 0;
1031 }
1032  
1033 27 ▶ if (!$final && defined $expected
Branch: 1 branch
BranchTrueFalseTotal
if (not $final and defined $expected and _compare_count(length $bytes, $expected) > 0) 0 27 27
Condition83%5/6
not $final and defined $expected and _compare_count(length $bytes, $expected) > 0
!ll&&!rl&&r
2610
not $final and defined $expected
!ll&&!rl&&r
1971
MC/DC0%0/3
not $final and defined $expected and _compare_count(length $bytes, $expected) > 0
not $final defined $expected _compare_count(length $bytes, $expected) > 0
Truth table75%3/4
not(A) and B and C
A= not $finalB= defined $expectedC= _compare_count(length $bytes, $expected) > 0
ABCresult
0XX0
10X0
1100
1111
1034 && _compare_count(length($bytes), $expected) > 0) {
1035 0 croak "$operation(): response body exceeds Content-Length";
1036 }
1037  
1038 27 my @connection = $response->_header_values_list('Connection');
1039 27 my $keep_alive = $request->_http1_keep_alive;
1040 27 ▶ my $close_after = !$keep_alive
Condition100%6/6
!$keep_alive || _has_connection_token(\@connection, 'close') || $close_delimited
l!l&&r!l&&!r
16110
not $keep_alive or _has_connection_token(\@connection, "close")
l!l&&r!l&&!r
14211
MC/DC100%3/3
!$keep_alive || _has_connection_token(\@connection, 'close') || $close_delimited
not $keep_alive _has_connection_token(\@connection, "close") $close_delimited
Truth table100%4/4
not(A) or B || C
A= not $keep_aliveB= _has_connection_token(\@connection, "close")C= $close_delimited
ABCresult
1XX1
01X1
0011
0000
1041 || _has_connection_token(\@connection, 'close')
1042 || $close_delimited;
1043  
1044 27 ▶ if (!$keep_alive && $version eq '1.1') {
Branch: 2 branches
BranchTrueFalseTotal
if (not $keep_alive and $version eq '1.1') { } 12 15 27
elsif ($keep_alive and $version eq '1.0' and not @connection and not $close_after) { } 0 29 29
Condition100%3/3
not $keep_alive and $version eq "1.1"
!ll&&!rl&&r
13212
MC/DC100%2/2
not $keep_alive and $version eq "1.1"
not $keep_alive $version eq "1.1"
Truth table100%3/3
not(A) and B
A= not $keep_aliveB= $version eq "1.1"
ABresult
0X0
100
111
1045 12 $response->header('Connection', 'close');
1046 12 $close_after = 1;
1047 ▶ } elsif ($keep_alive && $version eq '1.0'
Condition77%7/9
$keep_alive and $version eq "1.0" and not @connection and not $close_after
!ll&&!rl&&r
1410
$keep_alive and $version eq "1.0" and not @connection
!ll&&!rl&&r
1401
$keep_alive and $version eq "1.0"
!ll&&!rl&&r
2121
MC/DC0%0/4
$keep_alive and $version eq "1.0" and not @connection and not $close_after
$keep_alive $version eq "1.0" not @connection not $close_after
Truth table60%3/5
A and B and not(C) and not(D)
A= $keep_aliveB= $version eq "1.0"C= not @connectionD= not $close_after
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1048 && !@connection && !$close_after) {
1049 0 $response->header('Connection', 'keep-alive');
1050 }
1051  
1052 27 my $head = $response->_serialize_head($version);
1053 27 $response->_commit;
1054 27 $self->{_http_response_output_started} = 1;
1055 27 ▶ $transaction->_mark_response_started if $transaction;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction 12 15 27
1056  
1057 return (
1058 {
1059 27 ▶ expected => $expected,
Branch: 3 branches
BranchTrueFalseTotal
$head_request || $body_forbidden ? : 0 27 27
$close_after ? : 17 10 27
$chunked ? : 5 22 27
Condition33%1/3
$head_request or $body_forbidden
l!l&&r!l&&!r
0027
MC/DC0%0/2
$head_request or $body_forbidden
$head_request $body_forbidden
Truth table33%1/3
A or B
A= $head_requestB= $body_forbidden
ABresult
1X1
011
000
1060 sent => 0,
1061 suppress_body => $head_request || $body_forbidden ? 1 : 0,
1062 close_after => $close_after ? 1 : 0,
1063 chunked => $chunked ? 1 : 0,
1064 },
1065 $head,
1066 );
1067 }
1068  
1069 18 ▶sub _write_http_response_body ($self, $transaction, $body, $final, $operation) {
Subroutine _write_http_response_body: called CC=4 SCAR=15.6
1070 18 my $active = $self->{_http_active_transaction};
1071 18 ▶ croak "$operation(): Transaction is not active on this HTTP connection"
Branch: 1 branch
BranchTrueFalseTotal
if not $active or builtin::refaddr($active) != builtin::refaddr($transaction) 0 18 18
Condition33%1/3
not $active or builtin::refaddr($active) != builtin::refaddr($transaction)
l!l&&r!l&&!r
0018
MC/DC0%0/2
not $active or builtin::refaddr($active) != builtin::refaddr($transaction)
not $active builtin::refaddr($active) != builtin::refaddr($transaction)
Truth table33%1/3
not(A) or B
A= not $activeB= builtin::refaddr($active) != builtin::refaddr($transaction)
ABresult
1X1
011
000
1072 if !$active || refaddr($active) != refaddr($transaction);
1073  
1074 18 ▶ my $response = $transaction->response
Branch: 1 branch
BranchTrueFalseTotal
my $response = $transaction->response or croak("$operation(): Transaction has no Response") 18 0 18
1075 or croak "$operation(): Transaction has no Response";
1076 18 return $self->_write_response(
1077 $response, $body, $final, $operation,
1078 );
1079 }
1080  
1081 38 ▶sub _write_response ($self, $response, $body, $final, $operation = undef) {
Subroutine _write_response: called CC=22 SCAR=34.0
1082 38 ▶ $operation //= $final ? 'complete' : 'write';
Branch: 1 branch
BranchTrueFalseTotal
$final ? : 0 0 0
Condition33%1/3
$operation //= $final ? "complete" : "write"
l!l&&r!l&&!r
3800
MC/DC0%0/2
$operation //= $final ? "complete" : "write"
$operation $final ? "complete" : "write"
Truth table33%1/3
A //= B
A= $operationB= $final ? "complete" : "write"
ABresult
1X1
011
000
1083  
1084 croak "$operation(): connection is closing or closed"
1085 38 ▶ if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 38 38
Condition33%1/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
0038
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table33%1/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
1086  
1087 38 my $active = $self->{_http_active_response};
1088 38 ▶ croak "$operation(): this Response is not the active HTTP transaction"
Branch: 1 branch
BranchTrueFalseTotal
if not $active or builtin::refaddr($active) != builtin::refaddr($response) 0 38 38
Condition33%1/3
not $active or builtin::refaddr($active) != builtin::refaddr($response)
l!l&&r!l&&!r
0038
MC/DC0%0/2
not $active or builtin::refaddr($active) != builtin::refaddr($response)
not $active builtin::refaddr($active) != builtin::refaddr($response)
Truth table33%1/3
not(A) or B
A= not $activeB= builtin::refaddr($active) != builtin::refaddr($response)
ABresult
1X1
011
000
1089 if !$active || refaddr($active) != refaddr($response);
1090  
1091 38 my $bytes = _body_bytes($operation, $body);
1092 38 my $state = $self->{_http_response_state};
1093  
1094 38 ▶ if (!$state) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($state) 28 10 38
1095 28 my ($created, $head) = $self->_response_start(
1096 $response, $bytes, $final, $operation,
1097 );
1098 27 $state = $self->{_http_response_state} = $created;
1099  
1100 27 ▶ if ($final) {
Branch: 1 branch
BranchTrueFalseTotal
if ($final) 19 8 27
1101 19 my $wire_body = '';
1102 19 ▶ if (!$state->{suppress_body}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($state->{"suppress_body"}) 19 0 19
1103 $wire_body = $state->{chunked}
1104 19 ▶ ? _chunk_wire($bytes) . "0\r\n\r\n"
Branch: 1 branch
BranchTrueFalseTotal
$state->{'chunked'} ? : 0 19 19
1105 : $bytes;
1106 }
1107 return $self->_complete_response(
1108 $response, $head . $wire_body, $state->{close_after},
1109 19 );
1110 }
1111  
1112 8 $state->{sent} = length($bytes);
1113 8 ▶ my $wire_body = $state->{chunked} ? _chunk_wire($bytes) : $bytes;
Branch: 1 branch
BranchTrueFalseTotal
$state->{'chunked'} ? : 5 3 8
1114 8 return $self->write($head . $wire_body);
1115 }
1116  
1117 10 my $new_sent = $state->{sent} + length($bytes);
1118 10 ▶ if (defined($state->{expected})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $state->{"expected"} and _compare_count($new_sent, $state->{"expected"}) > 0) 0 10 10
Condition66%2/3
defined $state->{"expected"} and _compare_count($new_sent, $state->{"expected"}) > 0
!ll&&!rl&&r
910
MC/DC0%0/2
defined $state->{"expected"} and _compare_count($new_sent, $state->{"expected"}) > 0
defined $state->{"expected"} _compare_count($new_sent, $state->{"expected"}) > 0
Truth table66%2/3
A and B
A= defined $state->{"expected"}B= _compare_count($new_sent, $state->{"expected"}) > 0
ABresult
0X0
100
111
1119 && _compare_count($new_sent, $state->{expected}) > 0) {
1120 0 croak "$operation(): response body exceeds Content-Length";
1121 }
1122 10 ▶ if ($final && defined($state->{expected})
Branch: 1 branch
BranchTrueFalseTotal
if ($final and defined $state->{"expected"} and _compare_count($new_sent, $state->{"expected"}) != 0) 0 10 10
Condition83%5/6
$final and defined $state->{"expected"} and _compare_count($new_sent, $state->{"expected"}) != 0
!ll&&!rl&&r
910
$final and defined $state->{"expected"}
!ll&&!rl&&r
271
MC/DC0%0/3
$final and defined $state->{"expected"} and _compare_count($new_sent, $state->{"expected"}) != 0
$final defined $state->{"expected"} _compare_count($new_sent, $state->{"expected"}) != 0
Truth table75%3/4
A and B and C
A= $finalB= defined $state->{"expected"}C= _compare_count($new_sent, $state->{"expected"}) != 0
ABCresult
0XX0
10X0
1100
1111
1123 && _compare_count($new_sent, $state->{expected}) != 0) {
1124 0 croak "$operation(): response body length does not match Content-Length";
1125 }
1126  
1127 10 $state->{sent} = $new_sent;
1128  
1129 10 ▶ if ($final) {
Branch: 1 branch
BranchTrueFalseTotal
if ($final) 8 2 10
1130 my $wire = $state->{chunked}
1131 8 ▶ ? _chunk_wire($bytes) . "0\r\n\r\n"
Branch: 1 branch
BranchTrueFalseTotal
$state->{'chunked'} ? : 5 3 8
1132 : $bytes;
1133 return $self->_complete_response(
1134 $response, $wire, $state->{close_after},
1135 8 );
1136 }
1137  
1138 2 ▶ my $wire = $state->{chunked} ? _chunk_wire($bytes) : $bytes;
Branch: 1 branch
BranchTrueFalseTotal
$state->{'chunked'} ? : 2 0 2
1139 2 ▶ return length($wire) ? $self->write($wire) : 1;
Branch: 1 branch
BranchTrueFalseTotal
length $wire ? : 1 1 2
1140 }
1141  
1142 27 ▶sub _complete_response ($self, $response, $wire, $close_after) {
Subroutine _complete_response: called CC=13 SCAR=25.9
1143 27 my $transaction = $self->{_http_active_transaction};
1144 27 $self->{_http_response_output_started} = 1;
1145 27 $self->{_http_response_output_complete} = 1;
1146 27 ▶ $transaction->_mark_response_output_complete if $transaction;
Branch: 1 branch
BranchTrueFalseTotal
if $transaction 12 15 27
1147 27 $self->{_http_response_state} = undef;
1148  
1149 27 my $request_state = $self->{_http_request_state};
1150 27 ▶ if ($close_after && $request_state && !$request_state->{body_done}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($close_after and $request_state and not $request_state->{"body_done"}) 5 22 27
Condition83%5/6
$close_after and $request_state and not $request_state->{"body_done"}
!ll&&!rl&&r
10125
$close_after and $request_state
!ll&&!rl&&r
10017
MC/DC66%2/3
$close_after and $request_state and not $request_state->{"body_done"}
$close_after $request_state not $request_state->{"body_done"}
Truth table75%3/4
A and B and not(C)
A= $close_afterB= $request_stateC= not $request_state->{"body_done"}
ABCresult
0XX0
10X0
1100
1111
1151 5 $request_state->{close_after_response} = 1;
1152 5 ▶ my $accepted = length($wire) ? $self->write($wire) : 1;
Branch: 1 branch
BranchTrueFalseTotal
length $wire ? : 5 0 5
1153 5 ▶ $self->resume_read if $self->is_read_paused;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_read_paused 0 5 5
1154 5 return $accepted;
1155 }
1156  
1157 22 ▶ if ($close_after) {
Branch: 1 branch
BranchTrueFalseTotal
if ($close_after) 12 10 22
1158 12 $self->_complete_active_transaction_state;
1159 12 $self->_clear_transaction;
1160 12 $self->{_http_closing} = 1;
1161 12 $self->{_http_input} = '';
1162 12 ▶ $self->pause_read if !$self->is_read_paused;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_read_paused 10 2 12
1163 12 $self->end($wire);
1164 12 return 1;
1165 }
1166  
1167 10 ▶ my $accepted = length($wire) ? $self->write($wire) : 1;
Branch: 1 branch
BranchTrueFalseTotal
length $wire ? : 10 0 10
1168 10 ▶ if ($request_state && $request_state->{body_done}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request_state and $request_state->{'body_done'}) { } 7 3 10
Condition66%2/3
$request_state and $request_state->{"body_done"}
!ll&&!rl&&r
037
MC/DC50%1/2
$request_state and $request_state->{"body_done"}
$request_state $request_state->{"body_done"}
Truth table66%2/3
A and B
A= $request_stateB= $request_state->{"body_done"}
ABresult
0X0
100
111
1169 7 $self->_finalize_transaction;
1170 } else {
1171 3 ▶ $self->resume_read if $self->is_read_paused;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_read_paused 0 3 3
1172 }
1173 10 return $accepted;
1174 }
1175  
1176 13 ▶sub _has_connection_token ($values, $wanted) {
Subroutine _has_connection_token: called CC=4 SCAR=13.9
1177 13 for my $value (@$values) {
1178 2 for my $token (split /,/, $value) {
1179 2 $token =~ s/\A[ \t]+//;
1180 2 $token =~ s/[ \t]+\z//;
1181 2 ▶ return 1 if lc($token) eq $wanted;
Branch: 1 branch
BranchTrueFalseTotal
if lc $token eq $wanted 2 0 2
1182 }
1183 }
1184 11 return 0;
1185 }
1186  
1187 20 ▶sub _protocol_error ($self, $status, $version = '1.1') {
Subroutine _protocol_error: called CC=7 SCAR=20.5
1188 20 ▶ return if $self->{_http_closing} || $self->is_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_http_closing"} or $self->is_closed 0 20 20
Condition33%1/3
$self->{"_http_closing"} or $self->is_closed
l!l&&r!l&&!r
0020
MC/DC0%0/2
$self->{"_http_closing"} or $self->is_closed
$self->{"_http_closing"} $self->is_closed
Truth table33%1/3
A or B
A= $self->{"_http_closing"}B= $self->is_closed
ABresult
1X1
011
000
1189  
1190 20 ▶ $version = '1.1' if $version ne '1.0' && $version ne '1.1';
Branch: 1 branch
BranchTrueFalseTotal
if $version ne "1.0" and $version ne "1.1" 0 20 20
Condition66%2/3
$version ne "1.0" and $version ne "1.1"
!ll&&!rl&&r
1190
MC/DC0%0/2
$version ne "1.0" and $version ne "1.1"
$version ne "1.0" $version ne "1.1"
Truth table66%2/3
A and B
A= $version ne "1.0"B= $version ne "1.1"
ABresult
0X0
100
111
1191  
1192 20 my $response = Linux::Event::HTTP::Response->_new(
1193 status => $status,
1194 headers => [
1195 [ 'Content-Length', '0' ],
1196 [ 'Connection', 'close' ],
1197 ],
1198 );
1199  
1200 20 my $head = $response->_serialize_head($version);
1201 20 $self->_fail_active_transaction_state("HTTP protocol error ($status)");
1202 20 $self->_clear_transaction;
1203 20 $self->{_http_input} = '';
1204 20 $self->{_http_closing} = 1;
1205 20 ▶ $self->pause_read if !$self->is_read_paused;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_read_paused 20 0 20
1206 20 $self->end($head);
1207 20 return;
1208 }
1209  
1210 0 ▶sub CLONE ($class) {
Subroutine CLONE: not called CC=1 SCAR=6.9
1211 0 %CLASS_HANDLER = ();
1212 0 Linux::Event::_Socket::Stream::CLONE($class);
1213 0 return;
1214 }
1215  
1216 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
1217  
1218 25 1;
1219  
1220 __END__
↑ Summary HTTP/_HTTP2/Client.pm »