blib/lib/PAGI/Server/EventValidator.pm

filter: Statementstmt 99.1% 222 / 224 Branchbran 92.9% 238 / 256 Conditioncond 71.7% 117 / 163 MC/DCmcdc 52.1% 49 / 94 Subroutinesub 100% 35 / 35 Podpod 100% 11 / 11 totaltotal 85.8% 672 / 783 CC 190 SCAR 23.0
CC
190
Cov
90%
advance_sse
20.0
advance_websocket
16.1
advance_http
15.0
CRAP 9.9
« blib/lib/PAGI/Server/Protocol/HTTP2.pm ↑ Summary blib/lib/PAGI/Server/AppNormalizer.pm »
1 package PAGI::Server::EventValidator;
2  
3 154 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 154 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 154 our $VERSION = '0.002011';
7  
8 154 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 154 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # --- Primitive shape checks (anchored; undef and refs are always false) ---
12  
13 sub _is_nonneg_int {
14 489 ▶ my ($v) = @_;
Subroutine _is_nonneg_int: called CC=3 SCAR=11.0
15 489 ▶ return defined $v && !ref $v && $v =~ /\A[0-9]+\z/;
Condition100%6/6
defined $v && !ref($v) && $v =~ /\A[0-9]+\z/
!ll&&!rl&&r
315471
defined $v and not ref $v
!ll&&!rl&&r
12486
MC/DC100%3/3
defined $v && !ref($v) && $v =~ /\A[0-9]+\z/
defined $v not ref $v $v =~ /\A[0-9]+\z/
Truth table100%4/4
A and not(B) && C
A= defined $vB= not ref $vC= $v =~ /\A[0-9]+\z/
ABCresult
0XX0
10X0
1100
1111
16 }
17  
18 sub _is_bool01 {
19 406 ▶ my ($v) = @_;
Subroutine _is_bool01: called CC=3 SCAR=12.5
20 406 ▶ return defined $v && !ref $v && $v =~ /\A[01]\z/;
Condition50%3/6
defined $v && !ref($v) && $v =~ /\A[01]\z/
!ll&&!rl&&r
07399
defined $v and not ref $v
!ll&&!rl&&r
00406
MC/DC33%1/3
defined $v && !ref($v) && $v =~ /\A[01]\z/
defined $v not ref $v $v =~ /\A[01]\z/
Truth table50%2/4
A and not(B) && C
A= defined $vB= not ref $vC= $v =~ /\A[01]\z/
ABCresult
0XX0
10X0
1100
1111
21 }
22  
23 sub _is_nonneg_number {
24 48 ▶ my ($v) = @_;
Subroutine _is_nonneg_number: called CC=3 SCAR=12.5
25 48 ▶ return defined $v && !ref $v && $v =~ /\A[0-9]+(?:\.[0-9]+)?\z/;
Condition50%3/6
defined $v && !ref($v) && $v =~ /\A[0-9]+(?:\.[0-9]+)?\z/
!ll&&!rl&&r
0840
defined $v and not ref $v
!ll&&!rl&&r
0048
MC/DC33%1/3
defined $v && !ref($v) && $v =~ /\A[0-9]+(?:\.[0-9]+)?\z/
defined $v not ref $v $v =~ /\A[0-9]+(?:\.[0-9]+)?\z/
Truth table50%2/4
A and not(B) && C
A= defined $vB= not ref $vC= $v =~ /\A[0-9]+(?:\.[0-9]+)?\z/
ABCresult
0XX0
10X0
1100
1111
26 }
27  
28 # --- Shared header validation (byte safety per PAGI Www.pod "Header byte safety") ---
29 # Names: no CR/LF/NUL and no other control characters. Values: no CR/LF/NUL.
30  
31 sub check_header_value {
32 626 ▶ my ($value) = @_;
Subroutine check_header_value: called CC=2 SCAR=6.9
Pod documented
33 626 ▶ die "Invalid header value: contains CR, LF, or null byte\n"
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /[\r\n\0]/ 5 621 626
34 if $value =~ /[\r\n\0]/;
35 621 return $value;
36 }
37  
38 sub check_header_name {
39 627 ▶ my ($name) = @_;
Subroutine check_header_name: called CC=3 SCAR=11.0
Pod documented
40 627 ▶ die "Invalid header name: contains CR, LF, or null byte\n"
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /[\r\n\0]/ 0 627 627
41 if $name =~ /[\r\n\0]/;
42 627 ▶ die "Invalid header name: contains control characters\n"
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /[[:cntrl:]]/ 1 626 627
43 if $name =~ /[[:cntrl:]]/;
44 626 return $name;
45 }
46  
47 sub validate_headers {
48 418 ▶ my ($headers, $event_type) = @_;
Subroutine validate_headers: called CC=9 SCAR=22.0
Pod documented
49 418 ▶ croak "$event_type 'headers' must be an array reference"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $headers eq "ARRAY" 2 416 418
50 unless ref $headers eq 'ARRAY';
51 416 for my $h (@$headers) {
52 459 ▶ croak "$event_type headers: each header must be a 2-element array reference"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $h eq "ARRAY" and @$h == 2 2 457 459
Condition100%3/3
ref $h eq "ARRAY" and @$h == 2
!ll&&!rl&&r
11457
MC/DC100%2/2
ref $h eq "ARRAY" and @$h == 2
ref $h eq "ARRAY" @$h == 2
Truth table100%3/3
A and B
A= ref $h eq "ARRAY"B= @$h == 2
ABresult
0X0
100
111
53 unless ref $h eq 'ARRAY' && @$h == 2;
54 457 ▶ croak "$event_type headers: header name and value must be defined strings"
Branch: 1 branch
BranchTrueFalseTotal
if not defined $h->[0] && defined $h->[1] or ref $h->[0] or ref $h->[1] 1 455 456
Condition77%7/9
not defined $h->[0] && defined $h->[1] or ref $h->[0] or ref $h->[1]
l!l&&r!l&&!r
20455
not defined $h->[0] && defined $h->[1] or ref $h->[0]
l!l&&r!l&&!r
11455
defined $h->[0] && defined $h->[1]
!ll&&!rl&&r
01456
MC/DC50%2/4
not defined $h->[0] && defined $h->[1] or ref $h->[0] or ref $h->[1]
defined $h->[0] defined $h->[1] ref $h->[0] ref $h->[1]
Truth table60%3/5
not(A && B) or C or D
A= defined $h->[0]B= defined $h->[1]C= ref $h->[0]D= ref $h->[1]
ABCDresult
0XXX1
10XX1
111X1
11011
11000
55 if !defined $h->[0] || !defined $h->[1] || ref $h->[0] || ref $h->[1];
56 455 check_header_name($h->[0]);
57 454 check_header_value($h->[1]);
58 }
59 406 return;
60 }
61  
62 # =============================================================================
63 # PAGI::Server::EventValidator - Mandatory outgoing-event validation
64 #
65 # Per main.mkdn: Servers must raise exceptions if events are missing required
66 # fields, event fields are of the wrong type, the type is unrecognized, or
67 # events arrive out of sequence.
68 #
69 # This module is the shared authority for both event shape and send-sequence
70 # validation. Every send path in PAGI::Server::Connection and the lifespan
71 # send path in PAGI::Server call it unconditionally, in every environment;
72 # there is no way to disable it.
73 # =============================================================================
74  
75 # =============================================================================
76 # HTTP Event Validation
77 # =============================================================================
78  
79 sub validate_http_send {
80 820 ▶ my ($event, $opts) = @_;
Subroutine validate_http_send: called CC=9 SCAR=22.0
Pod documented
81 820 ▶ my $ext = ($opts && $opts->{extensions}) || {};
Condition80%4/5
$opts && $opts->{'extensions'} || {}
l!l
77347
$opts and $opts->{"extensions"}
!ll&&!rl&&r
470773
MC/DC50%1/2
$opts && $opts->{'extensions'} || {}
$opts $opts->{"extensions"}
Truth table66%2/3
A and B
A= $optsB= $opts->{"extensions"}
ABresult
111
0X0
100
82 820 ▶ my $type = $event->{type} // '';
Condition100%2/2
$event->{"type"} // ""
l!l
8191
MC/DC100%1/1
$event->{"type"} // ""
$event->{"type"}
Truth table100%2/2
A
A= $event->{"type"}
Aresult
11
00
83  
84 820 ▶ if ($type eq 'http.response.start') {
Branch: 4 branches
BranchTrueFalseTotal
if ($type eq 'http.response.start') { } 347 473 820
elsif ($type eq 'http.response.body') { } 437 36 473
elsif ($type eq 'http.response.trailers') { } 24 12 36
elsif ($type eq 'http.fullflush') { } 7 5 12
85 347 _validate_http_response_start($event);
86 }
87 elsif ($type eq 'http.response.body') {
88 437 _validate_http_response_body($event);
89 }
90 elsif ($type eq 'http.response.trailers') {
91 24 _validate_http_response_trailers($event);
92 }
93 elsif ($type eq 'http.fullflush') {
94 croak "Extension not enabled: fullflush"
95 7 ▶ unless exists $ext->{fullflush};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ext->{"fullflush"} 3 4 7
96 }
97 else {
98 5 croak "Unrecognized event type '$type' for http protocol";
99 }
100 777 return;
101 }
102  
103 sub _validate_http_response_start {
104 347 ▶ my ($event) = @_;
Subroutine _validate_http_response_start: called CC=8 SCAR=20.9
105  
106 # status is required (Int)
107 croak "http.response.start requires 'status' field"
108 347 ▶ unless exists $event->{status};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $event->{"status"} 1 346 347
109 croak "http.response.start 'status' must be a non-negative integer"
110 346 ▶ unless _is_nonneg_int($event->{status});
Branch: 1 branch
BranchTrueFalseTotal
unless _is_nonneg_int($event->{"status"}) 14 332 346
111  
112 # headers must be a valid tuple list if present
113 validate_headers($event->{headers}, 'http.response.start')
114 332 ▶ if exists $event->{headers} && defined $event->{headers};
Branch: 1 branch
BranchTrueFalseTotal
if exists $event->{"headers"} and defined $event->{"headers"} 327 5 332
Condition66%2/3
exists $event->{"headers"} and defined $event->{"headers"}
!ll&&!rl&&r
50327
MC/DC50%1/2
exists $event->{"headers"} and defined $event->{"headers"}
exists $event->{"headers"} defined $event->{"headers"}
Truth table66%2/3
A and B
A= exists $event->{"headers"}B= defined $event->{"headers"}
ABresult
0X0
100
111
115  
116 # trailers must be 0 or 1 if present
117 324 ▶ if (exists $event->{trailers} && defined $event->{trailers}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $event->{"trailers"} and defined $event->{"trailers"}) 24 300 324
Condition66%2/3
exists $event->{"trailers"} and defined $event->{"trailers"}
!ll&&!rl&&r
300024
MC/DC50%1/2
exists $event->{"trailers"} and defined $event->{"trailers"}
exists $event->{"trailers"} defined $event->{"trailers"}
Truth table66%2/3
A and B
A= exists $event->{"trailers"}B= defined $event->{"trailers"}
ABresult
0X0
100
111
118 croak "http.response.start 'trailers' must be 0 or 1"
119 24 ▶ unless _is_bool01($event->{trailers});
Branch: 1 branch
BranchTrueFalseTotal
unless _is_bool01($event->{"trailers"}) 1 23 24
120 }
121 }
122  
123 sub _validate_http_response_body {
124 437 ▶ my ($event) = @_;
Subroutine _validate_http_response_body: called CC=11 SCAR=24.0
125  
126 # Exactly one of body, file, or fh must be present
127 437 my $has_body = exists $event->{body};
128 437 my $has_file = exists $event->{file};
129 437 my $has_fh = exists $event->{fh};
130 437 my $count = $has_body + $has_file + $has_fh;
131  
132 437 ▶ croak "http.response.body requires exactly one of body/file/fh (got $count)"
Branch: 1 branch
BranchTrueFalseTotal
unless $count <= 1 2 435 437
133 unless $count <= 1; # 0 is OK - defaults to empty body
134  
135 # offset must be a non-negative integer if present
136 435 ▶ if (exists $event->{offset} && defined $event->{offset}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $event->{"offset"} and defined $event->{"offset"}) 15 420 435
Condition66%2/3
exists $event->{"offset"} and defined $event->{"offset"}
!ll&&!rl&&r
420015
MC/DC50%1/2
exists $event->{"offset"} and defined $event->{"offset"}
exists $event->{"offset"} defined $event->{"offset"}
Truth table66%2/3
A and B
A= exists $event->{"offset"}B= defined $event->{"offset"}
ABresult
0X0
100
111
137 croak "http.response.body 'offset' must be a non-negative integer"
138 15 ▶ unless _is_nonneg_int($event->{offset});
Branch: 1 branch
BranchTrueFalseTotal
unless _is_nonneg_int($event->{"offset"}) 1 14 15
139 }
140  
141 # length must be a non-negative integer if present
142 434 ▶ if (exists $event->{length} && defined $event->{length}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $event->{"length"} and defined $event->{"length"}) 7 427 434
Condition66%2/3
exists $event->{"length"} and defined $event->{"length"}
!ll&&!rl&&r
42707
MC/DC50%1/2
exists $event->{"length"} and defined $event->{"length"}
exists $event->{"length"} defined $event->{"length"}
Truth table66%2/3
A and B
A= exists $event->{"length"}B= defined $event->{"length"}
ABresult
0X0
100
111
143 croak "http.response.body 'length' must be a non-negative integer"
144 7 ▶ unless _is_nonneg_int($event->{length});
Branch: 1 branch
BranchTrueFalseTotal
unless _is_nonneg_int($event->{"length"}) 1 6 7
145 }
146  
147 # more must be 0 or 1 if present
148 433 ▶ if (exists $event->{more} && defined $event->{more}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $event->{"more"} and defined $event->{"more"}) 349 84 433
Condition66%2/3
exists $event->{"more"} and defined $event->{"more"}
!ll&&!rl&&r
840349
MC/DC50%1/2
exists $event->{"more"} and defined $event->{"more"}
exists $event->{"more"} defined $event->{"more"}
Truth table66%2/3
A and B
A= exists $event->{"more"}B= defined $event->{"more"}
ABresult
0X0
100
111
149 croak "http.response.body 'more' must be 0 or 1"
150 349 ▶ unless _is_bool01($event->{more});
Branch: 1 branch
BranchTrueFalseTotal
unless _is_bool01($event->{"more"}) 6 343 349
151 }
152 }
153  
154 sub _validate_http_response_trailers {
155 24 ▶ my ($event) = @_;
Subroutine _validate_http_response_trailers: called CC=3 SCAR=11.1
156  
157 # headers must be a valid tuple list if present
158 validate_headers($event->{headers}, 'http.response.trailers')
159 24 ▶ if exists $event->{headers} && defined $event->{headers};
Branch: 1 branch
BranchTrueFalseTotal
if exists $event->{"headers"} and defined $event->{"headers"} 21 3 24
Condition66%2/3
exists $event->{"headers"} and defined $event->{"headers"}
!ll&&!rl&&r
3021
MC/DC50%1/2
exists $event->{"headers"} and defined $event->{"headers"}
exists $event->{"headers"} defined $event->{"headers"}
Truth table66%2/3
A and B
A= exists $event->{"headers"}B= defined $event->{"headers"}
ABresult
0X0
100
111
160 }
161  
162 # =============================================================================
163 # WebSocket Event Validation
164 # =============================================================================
165  
166 sub validate_websocket_send {
167 181 ▶ my ($event, $opts) = @_;
Subroutine validate_websocket_send: called CC=12 SCAR=24.9
Pod documented
168 181 ▶ my $ext = ($opts && $opts->{extensions}) || {};
Condition80%4/5
$opts && $opts->{'extensions'} || {}
l!l
16516
$opts and $opts->{"extensions"}
!ll&&!rl&&r
160165
MC/DC50%1/2
$opts && $opts->{'extensions'} || {}
$opts $opts->{"extensions"}
Truth table66%2/3
A and B
A= $optsB= $opts->{"extensions"}
ABresult
111
0X0
100
169 181 ▶ my $type = $event->{type} // '';
Condition50%1/2
$event->{"type"} // ""
l!l
1810
MC/DC0%0/1
$event->{"type"} // ""
$event->{"type"}
Truth table50%1/2
A
A= $event->{"type"}
Aresult
11
00
170  
171 181 ▶ if ($type eq 'websocket.accept') {
Branch: 6 branches
BranchTrueFalseTotal
if ($type eq 'websocket.accept') { } 71 110 181
elsif ($type eq 'websocket.send') { } 49 61 110
elsif ($type eq 'websocket.close') { } 17 44 61
elsif ($type eq 'websocket.keepalive') { } 19 25 44
elsif ($type eq 'websocket.http.response.start') { } 12 13 25
elsif ($type eq 'websocket.http.response.body') { } 12 1 13
172 71 _validate_websocket_accept($event);
173 }
174 elsif ($type eq 'websocket.send') {
175 49 _validate_websocket_send_event($event);
176 }
177 elsif ($type eq 'websocket.close') {
178 17 _validate_websocket_close($event);
179 }
180 elsif ($type eq 'websocket.keepalive') {
181 19 _validate_websocket_keepalive($event);
182 }
183 elsif ($type eq 'websocket.http.response.start') {
184 croak "Extension not enabled: websocket.http.response"
185 12 ▶ unless exists $ext->{'websocket.http.response'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ext->{"websocket.http.response"} 1 11 12
186 11 _validate_ws_denial_start($event);
187 }
188 elsif ($type eq 'websocket.http.response.body') {
189 croak "Extension not enabled: websocket.http.response"
190 12 ▶ unless exists $ext->{'websocket.http.response'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ext->{"websocket.http.response"} 0 12 12
191 12 _validate_ws_denial_body($event);
192 }
193 else {
194 1 croak "Unrecognized event type '$type' for websocket protocol";
195 }
196 169 return;
197 }
198  
199 sub _validate_websocket_accept {
200 71 ▶ my ($event) = @_;
Subroutine _validate_websocket_accept: called CC=3 SCAR=11.1
201  
202 # headers must be a valid tuple list if present
203 validate_headers($event->{headers}, 'websocket.accept')
204 71 ▶ if exists $event->{headers} && defined $event->{headers};
Branch: 1 branch
BranchTrueFalseTotal
if exists $event->{"headers"} and defined $event->{"headers"} 3 68 71
Condition66%2/3
exists $event->{"headers"} and defined $event->{"headers"}
!ll&&!rl&&r
6803
MC/DC50%1/2
exists $event->{"headers"} and defined $event->{"headers"}
exists $event->{"headers"} defined $event->{"headers"}
Truth table66%2/3
A and B
A= exists $event->{"headers"}B= defined $event->{"headers"}
ABresult
0X0
100
111
205 }
206  
207 sub _validate_websocket_send_event {
208 49 ▶ my ($event) = @_;
Subroutine _validate_websocket_send_event: called CC=4 SCAR=13.9
209  
210 # Exactly one of bytes or text must be present and defined
211 49 ▶ my $count = (defined $event->{bytes} ? 1 : 0) + (defined $event->{text} ? 1 : 0);
Branch: 2 branches
BranchTrueFalseTotal
defined $event->{'bytes'} ? : 8 41 49
defined $event->{'text'} ? : 41 8 49
212  
213 49 ▶ croak "websocket.send requires exactly one of bytes/text (got $count)"
Branch: 1 branch
BranchTrueFalseTotal
unless $count == 1 4 45 49
214 unless $count == 1;
215 }
216  
217 sub _validate_websocket_close {
218 17 ▶ my ($event) = @_;
Subroutine _validate_websocket_close: called CC=4 SCAR=13.9
219  
220 # code must be a non-negative integer if present
221 17 ▶ if (exists $event->{code} && defined $event->{code}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $event->{"code"} and defined $event->{"code"}) 8 9 17
Condition66%2/3
exists $event->{"code"} and defined $event->{"code"}
!ll&&!rl&&r
908
MC/DC50%1/2
exists $event->{"code"} and defined $event->{"code"}
exists $event->{"code"} defined $event->{"code"}
Truth table66%2/3
A and B
A= exists $event->{"code"}B= defined $event->{"code"}
ABresult
0X0
100
111
222 croak "websocket.close 'code' must be a non-negative integer"
223 8 ▶ unless _is_nonneg_int($event->{code});
Branch: 1 branch
BranchTrueFalseTotal
unless _is_nonneg_int($event->{"code"}) 1 7 8
224 }
225 }
226  
227 sub _validate_websocket_keepalive {
228 19 ▶ my ($event) = @_;
Subroutine _validate_websocket_keepalive: called CC=6 SCAR=17.9
229  
230 # interval is required (Number)
231 croak "websocket.keepalive requires 'interval' field"
232 19 ▶ unless exists $event->{interval};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $event->{"interval"} 1 18 19
233 croak "websocket.keepalive 'interval' must be a non-negative number"
234 18 ▶ unless _is_nonneg_number($event->{interval});
Branch: 1 branch
BranchTrueFalseTotal
unless _is_nonneg_number($event->{"interval"}) 1 17 18
235  
236 # timeout must be a non-negative number if present
237 17 ▶ if (exists $event->{timeout} && defined $event->{timeout}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $event->{"timeout"} and defined $event->{"timeout"}) 7 10 17
Condition66%2/3
exists $event->{"timeout"} and defined $event->{"timeout"}
!ll&&!rl&&r
1007
MC/DC50%1/2
exists $event->{"timeout"} and defined $event->{"timeout"}
exists $event->{"timeout"} defined $event->{"timeout"}
Truth table66%2/3
A and B
A= exists $event->{"timeout"}B= defined $event->{"timeout"}
ABresult
0X0
100
111
238 croak "websocket.keepalive 'timeout' must be a non-negative number"
239 7 ▶ unless _is_nonneg_number($event->{timeout});
Branch: 1 branch
BranchTrueFalseTotal
unless _is_nonneg_number($event->{"timeout"}) 1 6 7
240 }
241 }
242  
243 sub _validate_ws_denial_start {
244 11 ▶ my ($event) = @_;
Subroutine _validate_ws_denial_start: called CC=5 SCAR=16.7
245  
246 # status is required (Int)
247 croak "websocket.http.response.start requires 'status' field"
248 11 ▶ unless exists $event->{status};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $event->{"status"} 0 11 11
249 croak "websocket.http.response.start 'status' must be a non-negative integer"
250 11 ▶ unless _is_nonneg_int($event->{status});
Branch: 1 branch
BranchTrueFalseTotal
unless _is_nonneg_int($event->{"status"}) 0 11 11
251  
252 # headers must be a valid tuple list if present
253 validate_headers($event->{headers}, 'websocket.http.response.start')
254 11 ▶ if exists $event->{headers} && defined $event->{headers};
Branch: 1 branch
BranchTrueFalseTotal
if exists $event->{"headers"} and defined $event->{"headers"} 10 1 11
Condition66%2/3
exists $event->{"headers"} and defined $event->{"headers"}
!ll&&!rl&&r
1010
MC/DC50%1/2
exists $event->{"headers"} and defined $event->{"headers"}
exists $event->{"headers"} defined $event->{"headers"}
Truth table66%2/3
A and B
A= exists $event->{"headers"}B= defined $event->{"headers"}
ABresult
0X0
100
111
255 }
256  
257 sub _validate_ws_denial_body {
258 12 ▶ my ($event) = @_;
Subroutine _validate_ws_denial_body: called CC=4 SCAR=14.2
259  
260 # more must be 0 or 1 if present
261 12 ▶ if (exists $event->{more} && defined $event->{more}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $event->{"more"} and defined $event->{"more"}) 6 6 12
Condition66%2/3
exists $event->{"more"} and defined $event->{"more"}
!ll&&!rl&&r
606
MC/DC50%1/2
exists $event->{"more"} and defined $event->{"more"}
exists $event->{"more"} defined $event->{"more"}
Truth table66%2/3
A and B
A= exists $event->{"more"}B= defined $event->{"more"}
ABresult
0X0
100
111
262 croak "websocket.http.response.body 'more' must be 0 or 1"
263 6 ▶ unless _is_bool01($event->{more});
Branch: 1 branch
BranchTrueFalseTotal
unless _is_bool01($event->{"more"}) 0 6 6
264 }
265 }
266  
267 # =============================================================================
268 # SSE Event Validation
269 # =============================================================================
270  
271 sub validate_sse_send {
272 287 ▶ my ($event, $opts) = @_;
Subroutine validate_sse_send: called CC=13 SCAR=25.7
Pod documented
273 287 ▶ my $ext = ($opts && $opts->{extensions}) || {};
Condition80%4/5
$opts && $opts->{'extensions'} || {}
l!l
26027
$opts and $opts->{"extensions"}
!ll&&!rl&&r
270260
MC/DC50%1/2
$opts && $opts->{'extensions'} || {}
$opts $opts->{"extensions"}
Truth table66%2/3
A and B
A= $optsB= $opts->{"extensions"}
ABresult
111
0X0
100
274 287 ▶ my $type = $event->{type} // '';
Condition50%1/2
$event->{"type"} // ""
l!l
2870
MC/DC0%0/1
$event->{"type"} // ""
$event->{"type"}
Truth table50%1/2
A
A= $event->{"type"}
Aresult
11
00
275  
276 287 ▶ if ($type eq 'sse.start') {
Branch: 8 branches
BranchTrueFalseTotal
if ($type eq 'sse.start') { } 72 215 287
elsif ($type eq 'sse.send') { } 107 108 215
elsif ($type eq 'sse.comment') { } 8 100 108
elsif ($type eq 'sse.keepalive') { } 24 76 100
elsif ($type eq 'sse.close') { } 16 60 76
elsif ($type eq 'sse.http.response.start') { } 28 32 60
elsif ($type eq 'sse.http.response.body') { } 27 5 32
elsif ($type eq 'http.fullflush') { } 4 1 5
277 72 _validate_sse_start($event);
278 }
279 elsif ($type eq 'sse.send') {
280 107 _validate_sse_send_event($event);
281 }
282 elsif ($type eq 'sse.comment') {
283 8 _validate_sse_comment($event);
284 }
285 elsif ($type eq 'sse.keepalive') {
286 24 _validate_sse_keepalive($event);
287 }
288 elsif ($type eq 'sse.close') {
289 16 _validate_sse_close($event);
290 }
291 elsif ($type eq 'sse.http.response.start') {
292 28 _validate_sse_decline_start($event);
293 }
294 elsif ($type eq 'sse.http.response.body') {
295 27 _validate_sse_decline_body($event);
296 }
297 elsif ($type eq 'http.fullflush') {
298 croak "Extension not enabled: fullflush"
299 4 ▶ unless exists $ext->{fullflush};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ext->{"fullflush"} 1 3 4
300 }
301 else {
302 1 croak "Unrecognized event type '$type' for sse protocol";
303 }
304 265 return;
305 }
306  
307 sub _validate_sse_decline_start {
308 28 ▶ my ($event) = @_;
Subroutine _validate_sse_decline_start: called CC=6 SCAR=22.0
309  
310 croak "sse.http.response.start requires 'status' field"
311 28 ▶ unless exists $event->{status} && defined $event->{status};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $event->{"status"} and defined $event->{"status"} 0 28 28
Condition33%1/3
exists $event->{"status"} and defined $event->{"status"}
!ll&&!rl&&r
0028
MC/DC0%0/2
exists $event->{"status"} and defined $event->{"status"}
exists $event->{"status"} defined $event->{"status"}
Truth table33%1/3
A and B
A= exists $event->{"status"}B= defined $event->{"status"}
ABresult
0X0
100
111
312 croak "sse.http.response.start 'status' must be a non-negative integer"
313 28 ▶ unless _is_nonneg_int($event->{status});
Branch: 1 branch
BranchTrueFalseTotal
unless _is_nonneg_int($event->{"status"}) 0 28 28
314 validate_headers($event->{headers}, 'sse.http.response.start')
315 28 ▶ if exists $event->{headers} && defined $event->{headers};
Branch: 1 branch
BranchTrueFalseTotal
if exists $event->{"headers"} and defined $event->{"headers"} 28 0 28
Condition33%1/3
exists $event->{"headers"} and defined $event->{"headers"}
!ll&&!rl&&r
0028
MC/DC0%0/2
exists $event->{"headers"} and defined $event->{"headers"}
exists $event->{"headers"} defined $event->{"headers"}
Truth table33%1/3
A and B
A= exists $event->{"headers"}B= defined $event->{"headers"}
ABresult
0X0
100
111
316 }
317  
318 sub _validate_sse_decline_body {
319 27 ▶ my ($event) = @_;
Subroutine _validate_sse_decline_body: called CC=4 SCAR=16.1
320  
321 27 ▶ if (exists $event->{more} && defined $event->{more}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $event->{"more"} and defined $event->{"more"}) 27 0 27
Condition33%1/3
exists $event->{"more"} and defined $event->{"more"}
!ll&&!rl&&r
0027
MC/DC0%0/2
exists $event->{"more"} and defined $event->{"more"}
exists $event->{"more"} defined $event->{"more"}
Truth table33%1/3
A and B
A= exists $event->{"more"}B= defined $event->{"more"}
ABresult
0X0
100
111
322 croak "sse.http.response.body 'more' must be 0 or 1"
323 27 ▶ unless _is_bool01($event->{more});
Branch: 1 branch
BranchTrueFalseTotal
unless _is_bool01($event->{"more"}) 0 27 27
324 }
325 }
326  
327 sub _validate_sse_close {
328 16 ▶ my ($event) = @_;
Subroutine _validate_sse_close: called CC=4 SCAR=14.2
329  
330 # reason is optional and server-side only; if present it must be a string
331 16 ▶ if (exists $event->{reason} && defined $event->{reason}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $event->{"reason"} and defined $event->{"reason"}) 2 14 16
Condition66%2/3
exists $event->{"reason"} and defined $event->{"reason"}
!ll&&!rl&&r
1402
MC/DC50%1/2
exists $event->{"reason"} and defined $event->{"reason"}
exists $event->{"reason"} defined $event->{"reason"}
Truth table66%2/3
A and B
A= exists $event->{"reason"}B= defined $event->{"reason"}
ABresult
0X0
100
111
332 croak "sse.close 'reason' must be a string"
333 2 ▶ if ref $event->{reason};
Branch: 1 branch
BranchTrueFalseTotal
if ref $event->{"reason"} 0 2 2
334 }
335 }
336  
337 sub _validate_sse_start {
338 72 ▶ my ($event) = @_;
Subroutine _validate_sse_start: called CC=6 SCAR=18.3
339  
340 # status must be a non-negative integer if present
341 72 ▶ if (exists $event->{status} && defined $event->{status}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $event->{"status"} and defined $event->{"status"}) 70 2 72
Condition66%2/3
exists $event->{"status"} and defined $event->{"status"}
!ll&&!rl&&r
2070
MC/DC50%1/2
exists $event->{"status"} and defined $event->{"status"}
exists $event->{"status"} defined $event->{"status"}
Truth table66%2/3
A and B
A= exists $event->{"status"}B= defined $event->{"status"}
ABresult
0X0
100
111
342 croak "sse.start 'status' must be a non-negative integer"
343 70 ▶ unless _is_nonneg_int($event->{status});
Branch: 1 branch
BranchTrueFalseTotal
unless _is_nonneg_int($event->{"status"}) 0 70 70
344 }
345  
346 # headers must be a valid tuple list if present
347 validate_headers($event->{headers}, 'sse.start')
348 72 ▶ if exists $event->{headers} && defined $event->{headers};
Branch: 1 branch
BranchTrueFalseTotal
if exists $event->{"headers"} and defined $event->{"headers"} 29 43 72
Condition66%2/3
exists $event->{"headers"} and defined $event->{"headers"}
!ll&&!rl&&r
43029
MC/DC50%1/2
exists $event->{"headers"} and defined $event->{"headers"}
exists $event->{"headers"} defined $event->{"headers"}
Truth table66%2/3
A and B
A= exists $event->{"headers"}B= defined $event->{"headers"}
ABresult
0X0
100
111
349 }
350  
351 sub _validate_sse_send_event {
352 107 ▶ my ($event) = @_;
Subroutine _validate_sse_send_event: called CC=12 SCAR=25.1
353  
354 # data is required (String)
355 croak "sse.send requires 'data' field"
356 107 ▶ unless exists $event->{data};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $event->{"data"} 1 106 107
357 croak "sse.send 'data' must be a string"
358 106 ▶ unless defined $event->{data} && !ref $event->{data};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $event->{"data"} and not ref $event->{"data"} 1 105 106
Condition66%2/3
defined $event->{"data"} and not ref $event->{"data"}
!ll&&!rl&&r
01105
MC/DC50%1/2
defined $event->{"data"} and not ref $event->{"data"}
defined $event->{"data"} not ref $event->{"data"}
Truth table66%2/3
A and not(B)
A= defined $event->{"data"}B= not ref $event->{"data"}
ABresult
0X0
100
111
359  
360 105 for my $f (qw(event id)) {
361 207 ▶ next unless exists $event->{$f} && defined $event->{$f};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $event->{$f} and defined $event->{$f} 168 39 207
Condition66%2/3
exists $event->{$f} and defined $event->{$f}
!ll&&!rl&&r
168039
MC/DC50%1/2
exists $event->{$f} and defined $event->{$f}
exists $event->{$f} defined $event->{$f}
Truth table66%2/3
A and B
A= exists $event->{$f}B= defined $event->{$f}
ABresult
0X0
100
111
362 39 ▶ croak "sse.send '$f' must be a string" if ref $event->{$f};
Branch: 1 branch
BranchTrueFalseTotal
if ref $event->{$f} 0 39 39
363 croak "sse.send '$f' must not contain newline characters"
364 39 ▶ if $event->{$f} =~ /[\r\n]/;
Branch: 1 branch
BranchTrueFalseTotal
if $event->{$f} =~ /[\r\n]/ 4 35 39
365 }
366 101 ▶ if (exists $event->{retry} && defined $event->{retry}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $event->{"retry"} and defined $event->{"retry"}) 4 97 101
Condition66%2/3
exists $event->{"retry"} and defined $event->{"retry"}
!ll&&!rl&&r
9704
MC/DC50%1/2
exists $event->{"retry"} and defined $event->{"retry"}
exists $event->{"retry"} defined $event->{"retry"}
Truth table66%2/3
A and B
A= exists $event->{"retry"}B= defined $event->{"retry"}
ABresult
0X0
100
111
367 croak "sse.send 'retry' must be a non-negative integer"
368 4 ▶ unless _is_nonneg_int($event->{retry});
Branch: 1 branch
BranchTrueFalseTotal
unless _is_nonneg_int($event->{"retry"}) 1 3 4
369 }
370 }
371  
372 sub _validate_sse_comment {
373 8 ▶ my ($event) = @_;
Subroutine _validate_sse_comment: called CC=4 SCAR=13.9
374  
375 # comment is required (String)
376 croak "sse.comment requires 'comment' field"
377 8 ▶ unless exists $event->{comment};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $event->{"comment"} 1 7 8
378 croak "sse.comment 'comment' must be a string"
379 7 ▶ unless defined $event->{comment} && !ref $event->{comment};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $event->{"comment"} and not ref $event->{"comment"} 1 6 7
Condition66%2/3
defined $event->{"comment"} and not ref $event->{"comment"}
!ll&&!rl&&r
016
MC/DC50%1/2
defined $event->{"comment"} and not ref $event->{"comment"}
defined $event->{"comment"} not ref $event->{"comment"}
Truth table66%2/3
A and not(B)
A= defined $event->{"comment"}B= not ref $event->{"comment"}
ABresult
0X0
100
111
380 }
381  
382 sub _validate_sse_keepalive {
383 24 ▶ my ($event) = @_;
Subroutine _validate_sse_keepalive: called CC=7 SCAR=19.5
384  
385 # interval is required (Number)
386 croak "sse.keepalive requires 'interval' field"
387 24 ▶ unless exists $event->{interval};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $event->{"interval"} 1 23 24
388 croak "sse.keepalive 'interval' must be a non-negative number"
389 23 ▶ unless _is_nonneg_number($event->{interval});
Branch: 1 branch
BranchTrueFalseTotal
unless _is_nonneg_number($event->{"interval"}) 6 17 23
390  
391 # comment is optional (String); when present it must be encodable as
392 # UTF-8 -- validated here, at arm time, so an unencodable comment fails
393 # THIS send's Future instead of dying later inside the keepalive timer
394 # tick (which would escape uncaught and unwind the event loop).
395 17 ▶ if (exists $event->{comment} && defined $event->{comment}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $event->{"comment"} and defined $event->{"comment"}) 14 3 17
Condition66%2/3
exists $event->{"comment"} and defined $event->{"comment"}
!ll&&!rl&&r
3014
MC/DC50%1/2
exists $event->{"comment"} and defined $event->{"comment"}
exists $event->{"comment"} defined $event->{"comment"}
Truth table66%2/3
A and B
A= exists $event->{"comment"}B= defined $event->{"comment"}
ABresult
0X0
100
111
396 # Copy into a lexical before encoding: Encode::encode consumes its
397 # input string in place, and encoding the caller's own $event->{comment}
398 # directly would leave it mutated (or emptied) out from under the
399 # caller after this validation-only check.
400 14 my $comment = $event->{comment};
401 my $ok = !ref($comment)
402 14 ▶ && eval { Encode::encode('UTF-8', $comment, Encode::FB_CROAK); 1 };
Condition100%3/3
!ref($comment) && eval { do { &Encode::encode('UTF-8', $comment, 1); 1 } }
!ll&&!rl&&r
1211
MC/DC100%2/2
!ref($comment) && eval { do { &Encode::encode('UTF-8', $comment, 1); 1 } }
!ref($comment) eval { do { &Encode::encode('UTF-8', $comment, 1); 1 } }
Truth table100%3/3
not(A) && B
A= !ref($comment)B= eval { do { &Encode::encode('UTF-8', $comment, 1); 1 } }
ABresult
0X0
100
111
403 14 ▶ croak "sse.keepalive 'comment' must be a UTF-8-encodable string"
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 3 11 14
404 unless $ok;
405 }
406 }
407  
408 # =============================================================================
409 # Lifespan Event Validation
410 # =============================================================================
411  
412 sub validate_lifespan_send {
413 389 ▶ my ($event) = @_;
Subroutine validate_lifespan_send: called CC=9 SCAR=22.3
Pod documented
414 389 ▶ my $type = $event->{type} // '';
Condition50%1/2
$event->{"type"} // ""
l!l
3890
MC/DC0%0/1
$event->{"type"} // ""
$event->{"type"}
Truth table50%1/2
A
A= $event->{"type"}
Aresult
11
00
415  
416 389 ▶ if ($type eq 'lifespan.startup.complete' or $type eq 'lifespan.shutdown.complete') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'lifespan.startup.complete' or $type eq 'lifespan.shutdown.complete') { } 343 46 389
elsif ($type eq 'lifespan.startup.failed' or $type eq 'lifespan.shutdown.failed') { } 7 39 46
Condition100%3/3
$type eq "lifespan.startup.complete" or $type eq "lifespan.shutdown.complete"
l!l&&r!l&&!r
17616746
MC/DC100%2/2
$type eq "lifespan.startup.complete" or $type eq "lifespan.shutdown.complete"
$type eq "lifespan.startup.complete" $type eq "lifespan.shutdown.complete"
Truth table100%3/3
A or B
A= $type eq "lifespan.startup.complete"B= $type eq "lifespan.shutdown.complete"
ABresult
1X1
011
000
417 # no fields beyond type
418 }
419 ▶ elsif ($type eq 'lifespan.startup.failed' or $type eq 'lifespan.shutdown.failed') {
Condition100%3/3
$type eq "lifespan.startup.failed" or $type eq "lifespan.shutdown.failed"
l!l&&r!l&&!r
6139
MC/DC100%2/2
$type eq "lifespan.startup.failed" or $type eq "lifespan.shutdown.failed"
$type eq "lifespan.startup.failed" $type eq "lifespan.shutdown.failed"
Truth table100%3/3
A or B
A= $type eq "lifespan.startup.failed"B= $type eq "lifespan.shutdown.failed"
ABresult
1X1
011
000
420 7 ▶ if (exists $event->{message} && defined $event->{message}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $event->{"message"} and defined $event->{"message"}) 7 0 7
Condition33%1/3
exists $event->{"message"} and defined $event->{"message"}
!ll&&!rl&&r
007
MC/DC0%0/2
exists $event->{"message"} and defined $event->{"message"}
exists $event->{"message"} defined $event->{"message"}
Truth table33%1/3
A and B
A= exists $event->{"message"}B= defined $event->{"message"}
ABresult
0X0
100
111
421 7 ▶ croak "$type 'message' must be a string" if ref $event->{message};
Branch: 1 branch
BranchTrueFalseTotal
if ref $event->{"message"} 2 5 7
422 }
423 }
424 else {
425 39 croak "Unrecognized event type '$type' for lifespan protocol";
426 }
427 348 return;
428 }
429  
430 # =============================================================================
431 # Sequence State Machines
432 #
433 # Each advance_* function is a pure transition function: given the current
434 # per-connection sequence state and a (shape-already-validated) event, it
435 # returns the next state or croaks describing the send-order violation.
436 # Dispatchers run shape validation first and call these separately.
437 # =============================================================================
438  
439 sub _http_body_is_terminal {
440 422 ▶ my ($event) = @_;
Subroutine _http_body_is_terminal: called CC=4 SCAR=13.9
441 422 ▶ return 1 if defined $event->{file} || defined $event->{fh};
Branch: 1 branch
BranchTrueFalseTotal
if defined $event->{"file"} or defined $event->{"fh"} 48 374 422
Condition100%3/3
defined $event->{"file"} or defined $event->{"fh"}
l!l&&r!l&&!r
2721374
MC/DC100%2/2
defined $event->{"file"} or defined $event->{"fh"}
defined $event->{"file"} defined $event->{"fh"}
Truth table100%3/3
A or B
A= defined $event->{"file"}B= defined $event->{"fh"}
ABresult
1X1
011
000
442 374 ▶ my $more = $event->{more} // 0;
Condition100%2/2
$event->{"more"} // 0
l!l
34232
MC/DC100%1/1
$event->{"more"} // 0
$event->{"more"}
Truth table100%2/2
A
A= $event->{"more"}
Aresult
11
00
443 374 return !$more;
444 }
445  
446 sub advance_http {
447 785 ▶ my ($state, $event) = @_;
Subroutine advance_http: called CC=15 SCAR=27.1
Pod documented
448 785 ▶ my $type = $event->{type} // '';
Condition50%1/2
$event->{"type"} // ""
l!l
7850
MC/DC0%0/1
$event->{"type"} // ""
$event->{"type"}
Truth table50%1/2
A
A= $event->{"type"}
Aresult
11
00
449  
450 785 ▶ croak "cannot send '$type': response already complete"
Branch: 1 branch
BranchTrueFalseTotal
if $state eq "complete" 5 780 785
451 if $state eq 'complete';
452  
453 780 ▶ if ($state eq 'initial') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state eq "initial") 323 457 780
454 323 ▶ croak "cannot send '$type' before http.response.start"
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "http.response.start" 5 318 323
455 unless $type eq 'http.response.start';
456 318 ▶ return $event->{trailers} ? 'started_t' : 'started';
Branch: 1 branch
BranchTrueFalseTotal
$event->{'trailers'} ? : 24 294 318
457 }
458  
459 457 ▶ croak "cannot send duplicate http.response.start"
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "http.response.start" 4 453 457
460 if $type eq 'http.response.start';
461  
462 453 ▶ if ($type eq 'http.response.trailers') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "http.response.trailers") 24 429 453
463 24 ▶ croak "cannot send http.response.trailers: trailers were not declared or body is not complete"
Branch: 1 branch
BranchTrueFalseTotal
unless $state eq "awaiting_trailers" 4 20 24
464 unless $state eq 'awaiting_trailers';
465 20 return 'complete';
466 }
467  
468 429 ▶ return $state if $type eq 'http.fullflush';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "http.fullflush" 6 423 429
469  
470 423 ▶ if ($type eq 'http.response.body') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "http.response.body") 423 0 423
471 423 ▶ if ($state eq 'started') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state eq "started") 395 28 423
472 395 ▶ return _http_body_is_terminal($event) ? 'complete' : 'started';
Branch: 1 branch
BranchTrueFalseTotal
_http_body_is_terminal($event) ? : 292 103 395
473 }
474 28 ▶ if ($state eq 'started_t') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state eq "started_t") 27 1 28
475 27 ▶ return _http_body_is_terminal($event) ? 'awaiting_trailers' : 'started_t';
Branch: 1 branch
BranchTrueFalseTotal
_http_body_is_terminal($event) ? : 24 3 27
476 }
477 }
478  
479 # awaiting_trailers state only accepts trailers/fullflush (handled above);
480 # anything else here means a body chunk arrived after completion was
481 # already declared but before the required trailers were sent.
482 1 croak "cannot send '$type' during http response phase '$state'";
483 }
484  
485 sub advance_websocket {
486 180 ▶ my ($state, $event) = @_;
Subroutine advance_websocket: called CC=16 SCAR=27.8
Pod documented
487 180 ▶ my $type = $event->{type} // '';
Condition50%1/2
$event->{"type"} // ""
l!l
1800
MC/DC0%0/1
$event->{"type"} // ""
$event->{"type"}
Truth table50%1/2
A
A= $event->{"type"}
Aresult
11
00
488  
489 180 ▶ croak "cannot send '$type' after websocket.close"
Branch: 1 branch
BranchTrueFalseTotal
if $state eq "closed" 4 176 180
490 if $state eq 'closed';
491 176 ▶ croak "cannot send '$type': denial response already complete"
Branch: 1 branch
BranchTrueFalseTotal
if $state eq "denial_complete" 3 173 176
492 if $state eq 'denial_complete';
493  
494 173 ▶ if ($state eq 'connecting') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state eq "connecting") 89 84 173
495 89 ▶ return 'accepted' if $type eq 'websocket.accept';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "websocket.accept" 71 18 89
496 18 ▶ return 'closed' if $type eq 'websocket.close';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "websocket.close" 5 13 18
497 13 ▶ return 'denial' if $type eq 'websocket.http.response.start';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "websocket.http.response.start" 10 3 13
498 3 croak "cannot send '$type' before websocket.accept";
499 }
500  
501 84 ▶ if ($state eq 'accepted') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state eq "accepted") 69 15 84
502 69 ▶ return 'accepted' if $type eq 'websocket.send' || $type eq 'websocket.keepalive';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "websocket.send" or $type eq "websocket.keepalive" 55 14 69
Condition100%3/3
$type eq "websocket.send" or $type eq "websocket.keepalive"
l!l&&r!l&&!r
421314
MC/DC100%2/2
$type eq "websocket.send" or $type eq "websocket.keepalive"
$type eq "websocket.send" $type eq "websocket.keepalive"
Truth table100%3/3
A or B
A= $type eq "websocket.send"B= $type eq "websocket.keepalive"
ABresult
1X1
011
000
503 14 ▶ return 'closed' if $type eq 'websocket.close';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "websocket.close" 11 3 14
504 3 croak "cannot send '$type' after websocket.accept";
505 }
506  
507 15 ▶ if ($state eq 'denial') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state eq "denial") 15 0 15
508 15 ▶ if ($type eq 'websocket.http.response.body') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "websocket.http.response.body") 12 3 15
509 12 ▶ my $more = $event->{more} // 0;
Condition100%2/2
$event->{"more"} // 0
l!l
57
MC/DC100%1/1
$event->{"more"} // 0
$event->{"more"}
Truth table100%2/2
A
A= $event->{"more"}
Aresult
11
00
510 12 ▶ return $more ? 'denial' : 'denial_complete';
Branch: 1 branch
BranchTrueFalseTotal
$more ? : 2 10 12
511 }
512 3 croak "cannot send '$type' after websocket.http.response.start";
513 }
514  
515 0 croak "cannot send '$type' in websocket state '$state'";
516 }
517  
518 sub advance_sse {
519 274 ▶ my ($state, $event) = @_;
Subroutine advance_sse: called CC=20 SCAR=30.0
Pod documented
520 274 ▶ my $type = $event->{type} // '';
Condition50%1/2
$event->{"type"} // ""
l!l
2740
MC/DC0%0/1
$event->{"type"} // ""
$event->{"type"}
Truth table50%1/2
A
A= $event->{"type"}
Aresult
11
00
521  
522 274 ▶ if ($state eq 'closed') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state eq "closed") 7 267 274
523 7 ▶ return 'closed' if $type eq 'sse.close';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "sse.close" 1 6 7
524 6 croak "cannot send '$type' after sse.close";
525 }
526 267 ▶ croak "cannot send '$type': decline response already complete"
Branch: 1 branch
BranchTrueFalseTotal
if $state eq "decline_complete" 3 264 267
527 if $state eq 'decline_complete';
528  
529 264 ▶ if ($state eq 'initial') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state eq "initial") 102 162 264
530 102 ▶ return 'streaming' if $type eq 'sse.start';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "sse.start" 73 29 102
531 29 ▶ return 'declining' if $type eq 'sse.http.response.start';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "sse.http.response.start" 26 3 29
532 3 croak "cannot send '$type' before sse.start";
533 }
534  
535 162 ▶ if ($state eq 'streaming') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state eq "streaming") 132 30 162
536 132 ▶ return 'streaming' if $type eq 'sse.send' || $type eq 'sse.comment' || $type eq 'sse.keepalive' || $type eq 'http.fullflush';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "sse.send" or $type eq "sse.comment" or $type eq "sse.keepalive" or $type eq "http.fullflush" 14 22 36
Condition100%9/9
$type eq "sse.send" or $type eq "sse.comment" or $type eq "sse.keepalive" or $type eq "http.fullflush"
l!l&&r!l&&!r
107322
$type eq "sse.send" or $type eq "sse.comment" or $type eq "sse.keepalive"
l!l&&r!l&&!r
961125
$type eq "sse.send" or $type eq "sse.comment"
l!l&&r!l&&!r
90636
MC/DC100%4/4
$type eq "sse.send" or $type eq "sse.comment" or $type eq "sse.keepalive" or $type eq "http.fullflush"
$type eq "sse.send" $type eq "sse.comment" $type eq "sse.keepalive" $type eq "http.fullflush"
Truth table100%5/5
A or B or C or D
A= $type eq "sse.send"B= $type eq "sse.comment"C= $type eq "sse.keepalive"D= $type eq "http.fullflush"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
537 22 ▶ return 'closed' if $type eq 'sse.close';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "sse.close" 17 5 22
538 5 ▶ croak "cannot decline with sse.http.response.start after sse.start"
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "sse.http.response.start" 3 2 5
539 if $type eq 'sse.http.response.start';
540 2 ▶ croak "cannot send duplicate sse.start"
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "sse.start" 1 1 2
541 if $type eq 'sse.start';
542 1 croak "cannot send '$type' after sse.start";
543 }
544  
545 30 ▶ if ($state eq 'declining') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state eq "declining") 30 0 30
546 30 ▶ if ($type eq 'sse.http.response.body') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "sse.http.response.body") 27 3 30
547 27 ▶ my $more = $event->{more} // 0;
Condition100%2/2
$event->{"more"} // 0
l!l
261
MC/DC100%1/1
$event->{"more"} // 0
$event->{"more"}
Truth table100%2/2
A
A= $event->{"more"}
Aresult
11
00
548 27 ▶ return $more ? 'declining' : 'decline_complete';
Branch: 1 branch
BranchTrueFalseTotal
$more ? : 2 25 27
549 }
550 3 croak "cannot send '$type' after sse.http.response.start";
551 }
552  
553 0 croak "cannot send '$type' in sse state '$state'";
554 }
555  
556 sub advance_lifespan {
557 353 ▶ my ($state, $event) = @_;
Subroutine advance_lifespan: called CC=8 SCAR=21.0
Pod documented
558 353 ▶ my $type = $event->{type} // '';
Condition50%1/2
$event->{"type"} // ""
l!l
3530
MC/DC0%0/1
$event->{"type"} // ""
$event->{"type"}
Truth table50%1/2
A
A= $event->{"type"}
Aresult
11
00
559  
560 353 ▶ if ($state eq 'startup_pending') {
Branch: 2 branches
BranchTrueFalseTotal
if ($state eq 'startup_pending') { } 182 171 353
elsif ($state eq 'shutdown_pending') { } 168 3 171
561 182 ▶ return 'running' if $type eq 'lifespan.startup.complete';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "lifespan.startup.complete" 175 7 182
562 7 ▶ return 'finished' if $type eq 'lifespan.startup.failed';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "lifespan.startup.failed" 5 2 7
563 }
564 elsif ($state eq 'shutdown_pending') {
565 168 ▶ return 'finished' if $type eq 'lifespan.shutdown.complete' || $type eq 'lifespan.shutdown.failed';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "lifespan.shutdown.complete" or $type eq "lifespan.shutdown.failed" 168 0 168
Condition66%2/3
$type eq "lifespan.shutdown.complete" or $type eq "lifespan.shutdown.failed"
l!l&&r!l&&!r
16710
MC/DC0%0/2
$type eq "lifespan.shutdown.complete" or $type eq "lifespan.shutdown.failed"
$type eq "lifespan.shutdown.complete" $type eq "lifespan.shutdown.failed"
Truth table66%2/3
A or B
A= $type eq "lifespan.shutdown.complete"B= $type eq "lifespan.shutdown.failed"
ABresult
1X1
011
000
566 }
567  
568 5 croak "cannot send '$type' during lifespan phase '$state'";
569 }
570  
571 154 1;
572  
573 __END__
« blib/lib/PAGI/Server/Protocol/HTTP2.pm ↑ Summary blib/lib/PAGI/Server/AppNormalizer.pm »