| 1 | package PAGI::Server::EventValidator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 156 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 156 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 156 | our $VERSION = '0.002013'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 156 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 156 | ▶ | use Encode (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # --- Primitive shape checks (anchored; undef and refs are always false) --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 488 | ▶ | sub _is_nonneg_int { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_nonneg_int: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 488 | my ($v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 488 | ▶ | return defined $v && !ref $v && $v =~ /\A[0-9]+\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
defined $v && !ref($v) && $v =~ /\A[0-9]+\z/
defined $v and not ref $v
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 408 | ▶ | sub _is_bool01 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_bool01: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 408 | my ($v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 408 | ▶ | return defined $v && !ref $v && $v =~ /\A[01]\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
defined $v && !ref($v) && $v =~ /\A[01]\z/
defined $v and not ref $v
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 48 | ▶ | sub _is_nonneg_number { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_nonneg_number: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 48 | my ($v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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/
defined $v and not ref $v
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 626 | ▶ | sub check_header_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_header_value: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 626 | my ($value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 626 | ▶ | die "Invalid header value: contains CR, LF, or null byte\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | if $value =~ /[\r\n\0]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 621 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 627 | ▶ | sub check_header_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_header_name: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 627 | my ($name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 627 | ▶ | die "Invalid header name: contains CR, LF, or null byte\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | if $name =~ /[\r\n\0]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 627 | ▶ | die "Invalid header name: contains control characters\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | if $name =~ /[[:cntrl:]]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 626 | return $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 418 | ▶ | sub validate_headers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_headers: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 418 | my ($headers, $event_type) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 418 | ▶ | croak "$event_type 'headers' must be an array reference" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
ref $h eq "ARRAY" and @$h == 2
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition77%7/9
not defined $h->[0] && defined $h->[1] or ref $h->[0] or ref $h->[1]
not defined $h->[0] && defined $h->[1] or ref $h->[0]
defined $h->[0] && defined $h->[1]
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 823 | ▶ | sub validate_http_send { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_http_send: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 823 | my ($event, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 823 | ▶ | my $ext = ($opts && $opts->{extensions}) || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition80%4/5
$opts && $opts->{'extensions'} || {}
$opts and $opts->{"extensions"}
MC/DC50%1/2
$opts && $opts->{'extensions'} || {}
$opts
$opts->{"extensions"}
Truth table66%2/3
A and B
A= $optsB= $opts->{"extensions"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 823 | ▶ | my $type = $event->{type} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$event->{"type"} // ""
MC/DC100%1/1
$event->{"type"} // ""
$event->{"type"}
Truth table100%2/2
A
A= $event->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 823 | ▶ | if ($type eq 'http.response.start') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 347 | _validate_http_response_start($event); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | elsif ($type eq 'http.response.body') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 440 | _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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 5 | croak "Unrecognized event type '$type' for http protocol"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 780 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 347 | ▶ | sub _validate_http_response_start { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_http_response_start: called CC=8 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 347 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # status is required (Int) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | croak "http.response.start requires 'status' field" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 347 | ▶ | unless exists $event->{status}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | croak "http.response.start 'status' must be a non-negative integer" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 346 | ▶ | unless _is_nonneg_int($event->{status}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $event->{"headers"} and defined $event->{"headers"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # trailers must be 0 or 1 if present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 324 | ▶ | if (exists $event->{trailers} && defined $event->{trailers}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $event->{"trailers"} and defined $event->{"trailers"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | croak "http.response.start 'trailers' must be 0 or 1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 24 | ▶ | unless _is_bool01($event->{trailers}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 440 | ▶ | sub _validate_http_response_body { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_http_response_body: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 440 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # Exactly one of body, file, or fh must be present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 440 | my $has_body = exists $event->{body}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 440 | my $has_file = exists $event->{file}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 440 | my $has_fh = exists $event->{fh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 440 | my $count = $has_body + $has_file + $has_fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 440 | ▶ | croak "http.response.body requires exactly one of body/file/fh (got $count)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | unless $count <= 1; # 0 is OK - defaults to empty body | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # offset must be a non-negative integer if present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 438 | ▶ | if (exists $event->{offset} && defined $event->{offset}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $event->{"offset"} and defined $event->{"offset"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | croak "http.response.body 'offset' must be a non-negative integer" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 15 | ▶ | unless _is_nonneg_int($event->{offset}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # length must be a non-negative integer if present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 437 | ▶ | if (exists $event->{length} && defined $event->{length}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $event->{"length"} and defined $event->{"length"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | croak "http.response.body 'length' must be a non-negative integer" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 7 | ▶ | unless _is_nonneg_int($event->{length}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # more must be 0 or 1 if present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 436 | ▶ | if (exists $event->{more} && defined $event->{more}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $event->{"more"} and defined $event->{"more"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | croak "http.response.body 'more' must be 0 or 1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 351 | ▶ | unless _is_bool01($event->{more}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 24 | ▶ | sub _validate_http_response_trailers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_http_response_trailers: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 24 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $event->{"headers"} and defined $event->{"headers"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # ============================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # WebSocket Event Validation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # ============================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 174 | ▶ | sub validate_websocket_send { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_websocket_send: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 174 | my ($event, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 174 | ▶ | my $ext = ($opts && $opts->{extensions}) || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition80%4/5
$opts && $opts->{'extensions'} || {}
$opts and $opts->{"extensions"}
MC/DC50%1/2
$opts && $opts->{'extensions'} || {}
$opts
$opts->{"extensions"}
Truth table66%2/3
A and B
A= $optsB= $opts->{"extensions"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 174 | ▶ | my $type = $event->{type} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$event->{"type"} // ""
MC/DC0%0/1
$event->{"type"} // ""
$event->{"type"}
Truth table50%1/2
A
A= $event->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 174 | ▶ | if ($type eq 'websocket.accept') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 71 | _validate_websocket_accept($event); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | elsif ($type eq 'websocket.send') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 43 | _validate_websocket_send_event($event); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | elsif ($type eq 'websocket.close') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 16 | _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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 12 | _validate_ws_denial_body($event); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 1 | croak "Unrecognized event type '$type' for websocket protocol"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 162 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 71 | ▶ | sub _validate_websocket_accept { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_websocket_accept: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 71 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $event->{"headers"} and defined $event->{"headers"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 43 | ▶ | sub _validate_websocket_send_event { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_websocket_send_event: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 43 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # Exactly one of bytes or text must be present and defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 43 | ▶ | my $count = (defined $event->{bytes} ? 1 : 0) + (defined $event->{text} ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 43 | ▶ | croak "websocket.send requires exactly one of bytes/text (got $count)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | unless $count == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 16 | ▶ | sub _validate_websocket_close { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_websocket_close: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 16 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # code must be a non-negative integer if present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 16 | ▶ | if (exists $event->{code} && defined $event->{code}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $event->{"code"} and defined $event->{"code"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | croak "websocket.close 'code' must be a non-negative integer" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 7 | ▶ | unless _is_nonneg_int($event->{code}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 19 | ▶ | sub _validate_websocket_keepalive { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_websocket_keepalive: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 19 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # interval is required (Number) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | croak "websocket.keepalive requires 'interval' field" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 19 | ▶ | unless exists $event->{interval}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | croak "websocket.keepalive 'interval' must be a non-negative number" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 18 | ▶ | unless _is_nonneg_number($event->{interval}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # timeout must be a non-negative number if present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 17 | ▶ | if (exists $event->{timeout} && defined $event->{timeout}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $event->{"timeout"} and defined $event->{"timeout"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | croak "websocket.keepalive 'timeout' must be a non-negative number" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 7 | ▶ | unless _is_nonneg_number($event->{timeout}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 11 | ▶ | sub _validate_ws_denial_start { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_ws_denial_start: called CC=5 SCAR=16.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 11 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # status is required (Int) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | croak "websocket.http.response.start requires 'status' field" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 11 | ▶ | unless exists $event->{status}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | croak "websocket.http.response.start 'status' must be a non-negative integer" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 11 | ▶ | unless _is_nonneg_int($event->{status}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $event->{"headers"} and defined $event->{"headers"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 12 | ▶ | sub _validate_ws_denial_body { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_ws_denial_body: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 12 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # more must be 0 or 1 if present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 12 | ▶ | if (exists $event->{more} && defined $event->{more}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $event->{"more"} and defined $event->{"more"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | croak "websocket.http.response.body 'more' must be 0 or 1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 6 | ▶ | unless _is_bool01($event->{more}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # ============================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # SSE Event Validation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # ============================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 286 | ▶ | sub validate_sse_send { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_sse_send: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 286 | my ($event, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 286 | ▶ | my $ext = ($opts && $opts->{extensions}) || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition80%4/5
$opts && $opts->{'extensions'} || {}
$opts and $opts->{"extensions"}
MC/DC50%1/2
$opts && $opts->{'extensions'} || {}
$opts
$opts->{"extensions"}
Truth table66%2/3
A and B
A= $optsB= $opts->{"extensions"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 286 | ▶ | my $type = $event->{type} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$event->{"type"} // ""
MC/DC0%0/1
$event->{"type"} // ""
$event->{"type"}
Truth table50%1/2
A
A= $event->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 286 | ▶ | if ($type eq 'sse.start') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 72 | _validate_sse_start($event); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | elsif ($type eq 'sse.send') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 106 | _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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | croak "Unrecognized event type '$type' for sse protocol"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 264 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 28 | ▶ | sub _validate_sse_decline_start { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_sse_decline_start: called CC=6 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 28 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | croak "sse.http.response.start requires 'status' field" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 28 | ▶ | unless exists $event->{status} && defined $event->{status}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $event->{"status"} and defined $event->{"status"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | croak "sse.http.response.start 'status' must be a non-negative integer" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 28 | ▶ | unless _is_nonneg_int($event->{status}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | validate_headers($event->{headers}, 'sse.http.response.start') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 28 | ▶ | if exists $event->{headers} && defined $event->{headers}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $event->{"headers"} and defined $event->{"headers"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 27 | ▶ | sub _validate_sse_decline_body { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_sse_decline_body: called CC=4 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 27 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 27 | ▶ | if (exists $event->{more} && defined $event->{more}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $event->{"more"} and defined $event->{"more"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | croak "sse.http.response.body 'more' must be 0 or 1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 27 | ▶ | unless _is_bool01($event->{more}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 16 | ▶ | sub _validate_sse_close { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_sse_close: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 16 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $event->{"reason"} and defined $event->{"reason"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | croak "sse.close 'reason' must be a string" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 2 | ▶ | if ref $event->{reason}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 72 | ▶ | sub _validate_sse_start { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_sse_start: called CC=6 SCAR=18.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 72 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # status must be a non-negative integer if present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 72 | ▶ | if (exists $event->{status} && defined $event->{status}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $event->{"status"} and defined $event->{"status"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | croak "sse.start 'status' must be a non-negative integer" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 70 | ▶ | unless _is_nonneg_int($event->{status}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $event->{"headers"} and defined $event->{"headers"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 106 | ▶ | sub _validate_sse_send_event { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_sse_send_event: called CC=12 SCAR=25.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 106 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | # data is required (String) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | croak "sse.send requires 'data' field" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 106 | ▶ | unless exists $event->{data}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | croak "sse.send 'data' must be a string" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 105 | ▶ | unless defined $event->{data} && !ref $event->{data}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $event->{"data"} and not ref $event->{"data"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 104 | for my $f (qw(event id)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 205 | ▶ | next unless exists $event->{$f} && defined $event->{$f}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $event->{$f} and defined $event->{$f}
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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 39 | ▶ | croak "sse.send '$f' must be a string" if ref $event->{$f}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | croak "sse.send '$f' must not contain newline characters" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 39 | ▶ | if $event->{$f} =~ /[\r\n]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 100 | ▶ | if (exists $event->{retry} && defined $event->{retry}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $event->{"retry"} and defined $event->{"retry"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | croak "sse.send 'retry' must be a non-negative integer" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 4 | ▶ | unless _is_nonneg_int($event->{retry}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 8 | ▶ | sub _validate_sse_comment { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_sse_comment: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 8 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | # comment is required (String) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | croak "sse.comment requires 'comment' field" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 8 | ▶ | unless exists $event->{comment}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | croak "sse.comment 'comment' must be a string" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 7 | ▶ | unless defined $event->{comment} && !ref $event->{comment}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $event->{"comment"} and not ref $event->{"comment"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 24 | ▶ | sub _validate_sse_keepalive { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_sse_keepalive: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 24 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | # interval is required (Number) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | croak "sse.keepalive requires 'interval' field" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 24 | ▶ | unless exists $event->{interval}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | croak "sse.keepalive 'interval' must be a non-negative number" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 23 | ▶ | unless _is_nonneg_number($event->{interval}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $event->{"comment"} and defined $event->{"comment"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
}
}
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
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 14 | ▶ | croak "sse.keepalive 'comment' must be a UTF-8-encodable string" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | unless $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | # ============================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # Lifespan Event Validation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # ============================================================================= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 387 | ▶ | sub validate_lifespan_send { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_lifespan_send: called CC=9 SCAR=22.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 387 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 387 | ▶ | my $type = $event->{type} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$event->{"type"} // ""
MC/DC0%0/1
$event->{"type"} // ""
$event->{"type"}
Truth table50%1/2
A
A= $event->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 387 | ▶ | if ($type eq 'lifespan.startup.complete' or $type eq 'lifespan.shutdown.complete') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$type eq "lifespan.startup.complete" or $type eq "lifespan.shutdown.complete"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 7 | ▶ | if (exists $event->{message} && defined $event->{message}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $event->{"message"} and defined $event->{"message"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 7 | ▶ | croak "$type 'message' must be a string" if ref $event->{message}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 39 | croak "Unrecognized event type '$type' for lifespan protocol"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 346 | 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 | 864 | ▶ | sub _http_body_is_opaque { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_http_body_is_opaque: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 864 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 864 | ▶ | return defined $event->{file} || defined $event->{fh}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $event->{'file'} || defined $event->{'fh'}
MC/DC100%2/2
defined $event->{'file'} || defined $event->{'fh'}
defined $event->{'file'}
defined $event->{'fh'}
Truth table100%3/3
A || B
A= defined $event->{'file'}B= defined $event->{'fh'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 429 | ▶ | sub _http_body_is_terminal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_http_body_is_terminal: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 429 | my ($event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 429 | ▶ | return 1 if _http_body_is_opaque($event); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 381 | ▶ | my $more = $event->{more} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$event->{"more"} // 0
MC/DC100%1/1
$event->{"more"} // 0
$event->{"more"}
Truth table100%2/2
A
A= $event->{"more"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 381 | return !$more; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 798 | ▶ | sub advance_http { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
advance_http: called CC=17 SCAR=28.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 798 | my ($state, $event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 798 | ▶ | my $type = $event->{type} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$event->{"type"} // ""
MC/DC0%0/1
$event->{"type"} // ""
$event->{"type"}
Truth table50%1/2
A
A= $event->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 798 | ▶ | croak "cannot send '$type': response already complete" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | if $state eq 'complete'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 793 | ▶ | if ($state eq 'initial') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 323 | ▶ | croak "cannot send '$type' before http.response.start" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | unless $type eq 'http.response.start'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 318 | ▶ | return $event->{trailers} ? 'started_t' : 'started'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 470 | ▶ | croak "cannot send duplicate http.response.start" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | if $type eq 'http.response.start'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 466 | ▶ | if ($type eq 'http.response.trailers') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 24 | ▶ | croak "cannot send http.response.trailers: trailers were not declared or body is not complete" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | unless $state eq 'awaiting_trailers'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 20 | return 'complete'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 442 | ▶ | return $state if $type eq 'http.fullflush'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 435 | ▶ | if ($type eq 'http.response.body') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | # A response's body is either a sequence of inline events or a single | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | # file/fh event, never both (PAGI::Spec::Www, "Payload kinds do not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | # mix within a response"). The '_i' suffix records that inline bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | # were delivered; once set, a delegated payload can no longer join | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | # them. An intermediary that transforms body bytes commits to an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | # encoding before it could know a file event was coming, and cannot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | # apply it to bytes the server streams on the application's behalf. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 435 | ▶ | croak "cannot send a file/fh body after inline body bytes" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
_http_body_is_opaque($event) and $state =~ /_i\z/
MC/DC100%2/2
_http_body_is_opaque($event) and $state =~ /_i\z/
_http_body_is_opaque($event)
$state =~ /_i\z/
Truth table100%3/3
A and B
A= _http_body_is_opaque($event)B= $state =~ /_i\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | if _http_body_is_opaque($event) && $state =~ /_i\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 430 | ▶ | if ($state =~ /\Astarted(_t)?(?:_i)?\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 429 | ▶ | my $trailers_declared = $1 ? '_t' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 429 | ▶ | return _http_body_is_terminal($event) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | ? ($trailers_declared ? 'awaiting_trailers' : 'complete') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | : "started${trailers_declared}_i"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # awaiting_trailers state only accepts trailers/fullflush (handled above); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | # anything else here means a body chunk arrived after completion was | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | # already declared but before the required trailers were sent. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 1 | croak "cannot send '$type' during http response phase '$state'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 173 | ▶ | sub advance_websocket { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
advance_websocket: called CC=16 SCAR=27.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 173 | my ($state, $event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 173 | ▶ | my $type = $event->{type} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$event->{"type"} // ""
MC/DC0%0/1
$event->{"type"} // ""
$event->{"type"}
Truth table50%1/2
A
A= $event->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 173 | ▶ | croak "cannot send '$type' after websocket.close" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | if $state eq 'closed'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 169 | ▶ | croak "cannot send '$type': denial response already complete" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | if $state eq 'denial_complete'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 166 | ▶ | if ($state eq 'connecting') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 89 | ▶ | return 'accepted' if $type eq 'websocket.accept'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 18 | ▶ | return 'closed' if $type eq 'websocket.close'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 13 | ▶ | return 'denial' if $type eq 'websocket.http.response.start'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 3 | croak "cannot send '$type' before websocket.accept"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 77 | ▶ | if ($state eq 'accepted') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 62 | ▶ | return 'accepted' if $type eq 'websocket.send' || $type eq 'websocket.keepalive'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$type eq "websocket.send" or $type eq "websocket.keepalive"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 13 | ▶ | return 'closed' if $type eq 'websocket.close'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 3 | croak "cannot send '$type' after websocket.accept"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 15 | ▶ | if ($state eq 'denial') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 15 | ▶ | if ($type eq 'websocket.http.response.body') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 12 | ▶ | my $more = $event->{more} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$event->{"more"} // 0
MC/DC100%1/1
$event->{"more"} // 0
$event->{"more"}
Truth table100%2/2
A
A= $event->{"more"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 12 | ▶ | return $more ? 'denial' : 'denial_complete'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 3 | croak "cannot send '$type' after websocket.http.response.start"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | croak "cannot send '$type' in websocket state '$state'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 273 | ▶ | sub advance_sse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
advance_sse: called CC=20 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 273 | my ($state, $event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 273 | ▶ | my $type = $event->{type} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$event->{"type"} // ""
MC/DC0%0/1
$event->{"type"} // ""
$event->{"type"}
Truth table50%1/2
A
A= $event->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 273 | ▶ | if ($state eq 'closed') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 7 | ▶ | return 'closed' if $type eq 'sse.close'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 6 | croak "cannot send '$type' after sse.close"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 266 | ▶ | croak "cannot send '$type': decline response already complete" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | if $state eq 'decline_complete'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 263 | ▶ | if ($state eq 'initial') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 102 | ▶ | return 'streaming' if $type eq 'sse.start'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 29 | ▶ | return 'declining' if $type eq 'sse.http.response.start'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 3 | croak "cannot send '$type' before sse.start"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 161 | ▶ | if ($state eq 'streaming') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 131 | ▶ | return 'streaming' if $type eq 'sse.send' || $type eq 'sse.comment' || $type eq 'sse.keepalive' || $type eq 'http.fullflush'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$type eq "sse.send" or $type eq "sse.comment" or $type eq "sse.keepalive" or $type eq "http.fullflush"
$type eq "sse.send" or $type eq "sse.comment" or $type eq "sse.keepalive"
$type eq "sse.send" or $type eq "sse.comment"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 22 | ▶ | return 'closed' if $type eq 'sse.close'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 5 | ▶ | croak "cannot decline with sse.http.response.start after sse.start" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | if $type eq 'sse.http.response.start'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 2 | ▶ | croak "cannot send duplicate sse.start" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | if $type eq 'sse.start'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 1 | croak "cannot send '$type' after sse.start"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 30 | ▶ | if ($state eq 'declining') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 30 | ▶ | if ($type eq 'sse.http.response.body') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 27 | ▶ | my $more = $event->{more} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$event->{"more"} // 0
MC/DC100%1/1
$event->{"more"} // 0
$event->{"more"}
Truth table100%2/2
A
A= $event->{"more"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 27 | ▶ | return $more ? 'declining' : 'decline_complete'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 3 | croak "cannot send '$type' after sse.http.response.start"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | croak "cannot send '$type' in sse state '$state'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 351 | ▶ | sub advance_lifespan { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
advance_lifespan: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 351 | my ($state, $event) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 351 | ▶ | my $type = $event->{type} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$event->{"type"} // ""
MC/DC0%0/1
$event->{"type"} // ""
$event->{"type"}
Truth table50%1/2
A
A= $event->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 351 | ▶ | if ($state eq 'startup_pending') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 181 | ▶ | return 'running' if $type eq 'lifespan.startup.complete'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 7 | ▶ | return 'finished' if $type eq 'lifespan.startup.failed'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | elsif ($state eq 'shutdown_pending') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 167 | ▶ | return 'finished' if $type eq 'lifespan.shutdown.complete' || $type eq 'lifespan.shutdown.failed'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type eq "lifespan.shutdown.complete" or $type eq "lifespan.shutdown.failed"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 5 | croak "cannot send '$type' during lifespan phase '$state'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 156 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||