| 1 | package Unblock::HTTP3::Capsule::Stream; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Scalar::Util qw(blessed weaken); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Unblock::HTTP3 (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Unblock::HTTP3::Capsule (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Unblock::HTTP3::Capsule::Parser (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | our $VERSION = '0.14'; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | ▶ | sub _new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new: called CC=23 SCAR=40.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | my ($class, $transaction, %option) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | ▶ | croak 'Capsule stream requires a Unblock::HTTP3::Transaction' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction")
MC/DC0%0/2
builtin::blessed($transaction) and $transaction->isa("Unblock::HTTP3::Transaction")
builtin::blessed($transaction)
$transaction->isa("Unblock::HTTP3::Transaction")
Truth table33%1/3
A and B
A= builtin::blessed($transaction)B= $transaction->isa("Unblock::HTTP3::Transaction")
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | unless blessed($transaction) | ||||||||||||||||||||||||||||||||||||||||||
| 20 | && $transaction->isa('Unblock::HTTP3::Transaction'); | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | ▶ | croak 'Capsule Protocol requires Extended CONNECT' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | unless $transaction->is_extended_connect; | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | my $on_capsule = delete $option{on_capsule}; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | my $handlers_supplied = exists $option{handlers}; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | my $handlers = delete $option{handlers}; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | my $on_end = delete $option{on_end}; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | my $on_cancel = delete $option{on_cancel}; | |||||||||||||||||||||||||||||||||||||||||
| 29 | my $max_capsule_size = exists($option{max_capsule_size}) | ||||||||||||||||||||||||||||||||||||||||||
| 30 | ? delete($option{max_capsule_size}) | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | ▶ | : 4 * 1024 * 1024; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | ▶ | croak 'on_capsule must be a code reference' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $on_capsule and ref $on_capsule ne "CODE"
MC/DC0%0/2
defined $on_capsule and ref $on_capsule ne "CODE"
defined $on_capsule
ref $on_capsule ne "CODE"
Truth table66%2/3
A and B
A= defined $on_capsuleB= ref $on_capsule ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | if defined($on_capsule) && ref($on_capsule) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | ▶ | croak 'handlers must be a hash reference' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $handlers and ref $handlers ne "HASH"
MC/DC0%0/2
defined $handlers and ref $handlers ne "HASH"
defined $handlers
ref $handlers ne "HASH"
Truth table66%2/3
A and B
A= defined $handlersB= ref $handlers ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | if defined($handlers) && ref($handlers) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 4 | ▶ | croak 'on_end must be a code reference' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $on_end and ref $on_end ne "CODE"
MC/DC0%0/2
defined $on_end and ref $on_end ne "CODE"
defined $on_end
ref $on_end ne "CODE"
Truth table33%1/3
A and B
A= defined $on_endB= ref $on_end ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | if defined($on_end) && ref($on_end) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 4 | ▶ | croak 'on_cancel must be a code reference' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $on_cancel and ref $on_cancel ne "CODE"
MC/DC0%0/2
defined $on_cancel and ref $on_cancel ne "CODE"
defined $on_cancel
ref $on_cancel ne "CODE"
Truth table33%1/3
A and B
A= defined $on_cancelB= ref $on_cancel ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | if defined($on_cancel) && ref($on_cancel) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 4 | ▶ | croak 'unknown Capsule stream option: ' . join(', ', sort keys %option) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | if %option; | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 4 | ▶ | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$handlers_supplied || defined $on_capsule
MC/DC100%2/2
$handlers_supplied || defined $on_capsule
$handlers_supplied
defined $on_capsule
Truth table100%3/3
A || B
A= $handlers_suppliedB= defined $on_capsule
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | transaction => $transaction, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | parser => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | writer => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | reader => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | on_end => $on_end, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | on_cancel => $on_cancel, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | polling => (!$handlers_supplied && !defined($on_capsule)) ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | callback_error => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | ended => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | cancelled => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 4 | weaken($self->{transaction}); | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | my $weak_self = $self; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 4 | weaken($weak_self); | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 4 | my %parser_option = ( | |||||||||||||||||||||||||||||||||||||||||
| 63 | max_capsule_size => $max_capsule_size, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 4 | ▶ | if (defined $handlers) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | my %wrapped; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | for my $type (keys %$handlers) { | |||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | my $callback = $handlers->{$type}; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | croak "Capsule handler for type $type must be a code reference" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | unless ref($callback) eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | $wrapped{$type} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=16.8
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | my ($parser, $capsule) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | ▶ | my $stream = $weak_self or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | $callback->($stream, $capsule); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 82 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | my $error = $@ || 'Capsule handler failed'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ || 'Capsule handler failed'
MC/DC0%0/1
$@ || 'Capsule handler failed'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $stream->{callback_error} = $error; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | die $error; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | $parser_option{handlers} = \%wrapped; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | ▶ | if (defined $on_capsule) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | $parser_option{on_capsule} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my ($parser, $capsule) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | my $stream = $weak_self or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $on_capsule->($stream, $capsule); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 105 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | my $error = $@ || 'Capsule callback failed'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ || 'Capsule callback failed'
MC/DC0%0/1
$@ || 'Capsule callback failed'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $stream->{callback_error} = $error; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | die $error; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | $self->{parser} = | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 4 | Unblock::HTTP3::Capsule::Parser->new(%parser_option); | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | my $connection = $transaction->{connection} | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 4 | ▶ | or croak 'Capsule stream lost its HTTP/3 connection'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 4 | $self->_assert_protocol_ready; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 3 | ▶ | if ($connection->role eq 'client') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | $self->{writer} = $transaction->request_body; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | $self->{reader} = $transaction->response_body; | |||||||||||||||||||||||||||||||||||||||||
| 128 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | $self->{writer} = $transaction->response_body; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 2 | $self->{reader} = $transaction->request_body; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | my %reader_option = ( | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 3 | ▶ | on_end => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.9
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 3 | ▶ | my $stream = $weak_self or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 3 | ▶ | return if $stream->{cancelled}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 3 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||
| 139 | 3 | $stream->_assert_protocol_ready; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 3 | $stream->{parser}->finish; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 142 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 3 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | ▶ | my $error = $@ || 'Capsule Protocol truncated stream'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$@ || 'Capsule Protocol truncated stream'
MC/DC0%0/1
$@ || 'Capsule Protocol truncated stream'
$@
Truth table50%1/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | my $tx = $stream->{transaction}; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | ▶ | $tx->_capsule_protocol_error($error) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | if defined $tx; | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 2 | $stream->{ended} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | my $callback = $stream->{on_end}; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 2 | ▶ | $callback->($stream) if defined $callback; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 158 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | on_cancel => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | my $stream = $weak_self or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | return if $stream->{cancelled}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $stream->{cancelled} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | my $callback = $stream->{on_cancel}; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | $callback->($stream) if defined $callback; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 169 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 3 | ▶ | if (!$self->{polling}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 3 | ▶ | $reader_option{on_data} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=27.3
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 3 | my ($reader, $bytes) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 3 | ▶ | my $stream = $weak_self or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 3 | ▶ | return if $stream->{cancelled}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 3 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||
| 180 | 3 | $stream->_assert_protocol_ready; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 3 | $stream->{parser}->feed($bytes); | |||||||||||||||||||||||||||||||||||||||||
| 182 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 183 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 3 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | my $error = $@ || 'Capsule Protocol parse error'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ || 'Capsule Protocol parse error'
MC/DC0%0/1
$@ || 'Capsule Protocol parse error'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | if (defined $stream->{callback_error}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | my $callback_error = delete $stream->{callback_error}; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | die $callback_error; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my $tx = $stream->{transaction}; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | $tx->_capsule_protocol_error($error) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | if defined $tx; | ||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 3 | $self->{reader}->_configure(%reader_option); | |||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 33 | ▶ | sub _has_forbidden_field { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_has_forbidden_field: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 33 | my ($message) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 33 | for my $name (qw(content-length content-type transfer-encoding)) { | |||||||||||||||||||||||||||||||||||||||||
| 211 | 99 | my $values = $message->header_values($name); | |||||||||||||||||||||||||||||||||||||||||
| 212 | 99 | ▶ | return $name if @$values; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 33 | return; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 17 | ▶ | sub _assert_protocol_ready { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assert_protocol_ready: called CC=11 SCAR=29.0
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 17 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | my $transaction = $self->{transaction} | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 17 | ▶ | or croak 'Capsule Protocol Transaction is no longer available'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 17 | my $request = $transaction->request; | |||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 17 | ▶ | croak 'Capsule Protocol requires Extended CONNECT' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | unless $transaction->is_extended_connect; | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 17 | ▶ | if (my $field = _has_forbidden_field($request)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | croak "Capsule Protocol request must not contain $field"; | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 17 | ▶ | my $response = $transaction->response | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | or croak 'Capsule Protocol requires a final response'; | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 16 | my $status = $response->status; | |||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 16 | ▶ | croak 'Capsule Protocol requires a successful response' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$status >= 200 and $status < 300
MC/DC0%0/2
$status >= 200 and $status < 300
$status >= 200
$status < 300
Truth table33%1/3
A and B
A= $status >= 200B= $status < 300
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | unless $status >= 200 && $status < 300; | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 16 | ▶ | croak "Capsule Protocol cannot use HTTP status $status" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$status == 204 or $status == 205 or $status == 206
$status == 204 or $status == 205
MC/DC0%0/3
$status == 204 or $status == 205 or $status == 206
$status == 204
$status == 205
$status == 206
Truth table25%1/4
A or B or C
A= $status == 204B= $status == 205C= $status == 206
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | if $status == 204 || $status == 205 || $status == 206; | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 16 | ▶ | if (my $field = _has_forbidden_field($response)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | croak "Capsule Protocol response must not contain $field"; | |||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 16 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 5 | ▶ | sub send { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 5 | my ($self, $type, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | croak 'send() cannot be used after Capsule stream cancellation' | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 5 | ▶ | if $self->{cancelled}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 5 | $self->_assert_protocol_ready; | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 5 | ▶ | my $capsule = Unblock::HTTP3::Capsule->new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | type => $type, | ||||||||||||||||||||||||||||||||||||||||||
| 260 | value => defined($value) ? $value : '', | ||||||||||||||||||||||||||||||||||||||||||
| 261 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 5 | return $self->{writer}->write($capsule->encode); | |||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 5 | ▶ | sub next_capsule { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_capsule: called CC=8 SCAR=22.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 5 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 5 | ▶ | croak 'next_capsule() does not accept arguments' if @args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | croak 'next_capsule() is only available in polling mode' | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 5 | ▶ | unless $self->{polling}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 5 | ▶ | return if $self->{cancelled}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 5 | my $capsule = $self->{parser}->next_capsule; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 5 | ▶ | return $capsule if defined $capsule; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | 5 | ▶ | while (defined(my $bytes = $self->{reader}->next_chunk)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 2 | $self->{parser}->feed($bytes); | |||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 2 | $capsule = $self->{parser}->next_capsule; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 2 | ▶ | return $capsule if defined $capsule; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | return if $self->{cancelled}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 3 | return $self->{parser}->next_capsule; | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 2 | ▶ | sub complete { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
complete: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 2 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 291 | 2 | ▶ | croak 'complete() does not accept arguments' if @args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | croak 'Capsule stream was cancelled' | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 2 | ▶ | if $self->{cancelled}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 2 | $self->_assert_protocol_ready; | |||||||||||||||||||||||||||||||||||||||||
| 296 | $self->{writer}->complete | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 2 | ▶ | unless $self->{writer}->is_complete; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 4 | ▶ | sub is_receive_complete { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_receive_complete: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 4 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 4 | ▶ | croak 'is_receive_complete() does not accept arguments' if @args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 4 | ▶ | return $self->{ended} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | sub is_cancelled { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_cancelled: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | croak 'is_cancelled() does not accept arguments' if @args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | return $self->{cancelled} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | __END__ | ||||||||||||||||||||||||||||||||||||||||||