| 1 | package Unblock::HTTP::_Session; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Unblock::HTTP::_EngineFactory; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 1 | my %ENGINE = ( | |||||||||||||||||||||||||||||||
| 9 | 'http/1.1' => 'Unblock::HTTP1', | ||||||||||||||||||||||||||||||||
| 10 | 'h2' => 'Unblock::HTTP2', | ||||||||||||||||||||||||||||||||
| 11 | 'h3' => 'Unblock::HTTP3', | ||||||||||||||||||||||||||||||||
| 12 | ); | ||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | sub _new { | ||||||||||||||||||||||||||||||
|
Subroutine
_new: called CC=15 SCAR=28.0
| |||||||||||||||||||||||||||||||||
| 15 | 6 | my ($class, $role, %option) = @_; | |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 6 | my $protocol = delete $option{protocol}; | |||||||||||||||||||||||||||||||
| 18 | 6 | my $alpn = delete $option{alpn}; | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 6 | ▶ | croak 'new(): specify either protocol or alpn, not both' | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $protocol and defined $alpn
MC/DC100%2/2
defined $protocol and defined $alpn
defined $protocol
defined $alpn
Truth table100%3/3
A and B
A= defined $protocolB= defined $alpn
| |||||||||||||||||||||||||||||||||
| 21 | if defined($protocol) && defined($alpn); | ||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 5 | my $has_quic = defined $option{quic}; | |||||||||||||||||||||||||||||||
| 24 | 5 | my $has_transport = defined $option{transport}; | |||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 5 | ▶ | croak 'new(): cannot supply both quic and transport' | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$has_quic and $has_transport
MC/DC100%2/2
$has_quic and $has_transport
$has_quic
$has_transport
Truth table100%3/3
A and B
A= $has_quicB= $has_transport
| |||||||||||||||||||||||||||||||||
| 27 | if $has_quic && $has_transport; | ||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 4 | ▶ | if (!defined $protocol) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | $protocol = defined($alpn) && length($alpn) | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
defined $alpn and length $alpn
MC/DC0%0/2
defined $alpn and length $alpn
defined $alpn
length $alpn
Truth table33%1/3
A and B
A= defined $alpnB= length $alpn
| |||||||||||||||||||||||||||||||||
| 31 | ? $alpn : $has_quic ? 'h3' : 'http/1.1'; | ||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | 4 | ▶ | croak 'new(): protocol must be a scalar' if ref $protocol; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 35 | croak "new(): unsupported HTTP protocol '$protocol'" | ||||||||||||||||||||||||||||||||
| 36 | 4 | ▶ | unless exists $ENGINE{$protocol}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 3 | ▶ | if ($protocol eq 'h3') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | croak 'new(): HTTP/3 requires quic, not a byte transport' | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$has_quic and not $has_transport
MC/DC0%0/2
$has_quic and not $has_transport
$has_quic
not $has_transport
Truth table33%1/3
A and not(B)
A= $has_quicB= not $has_transport
| |||||||||||||||||||||||||||||||||
| 40 | unless $has_quic && !$has_transport; | ||||||||||||||||||||||||||||||||
| 41 | } else { | ||||||||||||||||||||||||||||||||
| 42 | 2 | ▶ | croak "new(): $protocol requires a byte transport, not quic" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 43 | if $has_quic; | ||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 1 | my $backend = Unblock::HTTP::_EngineFactory->create( | |||||||||||||||||||||||||||||||
| 47 | $role, $protocol, %option, | ||||||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 1 | return bless { | |||||||||||||||||||||||||||||||
| 51 | protocol => $protocol, | ||||||||||||||||||||||||||||||||
| 52 | backend => $backend, | ||||||||||||||||||||||||||||||||
| 53 | }, $class; | ||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub protocol { return $_[0]{protocol} } | ||||||||||||||||||||||||||||||
|
Subroutine
protocol: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 57 | 3 | ▶ | sub backend { return $_[0]{backend} } | ||||||||||||||||||||||||||||||
|
Subroutine
backend: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub _stream_backend { | ||||||||||||||||||||||||||||||
|
Subroutine
_stream_backend: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 60 | 0 | my ($self, $method) = @_; | |||||||||||||||||||||||||||||||
| 61 | croak "$method(): HTTP/3 uses QUIC streams, not TCP byte input/output" | ||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if $self->{protocol} eq 'h3'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 63 | 0 | return $self->{backend}; | |||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub input { | ||||||||||||||||||||||||||||||
|
Subroutine
input: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 67 | 0 | my ($self, @arg) = @_; | |||||||||||||||||||||||||||||||
| 68 | 0 | return $self->_stream_backend('input')->input(@arg); | |||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub input_eof { | ||||||||||||||||||||||||||||||
|
Subroutine
input_eof: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 72 | 0 | my ($self, @arg) = @_; | |||||||||||||||||||||||||||||||
| 73 | 0 | return $self->_stream_backend('input_eof')->input_eof(@arg); | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub transport_error { | ||||||||||||||||||||||||||||||
|
Subroutine
transport_error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 77 | 0 | my ($self, @arg) = @_; | |||||||||||||||||||||||||||||||
| 78 | 0 | return $self->_stream_backend('transport_error')->transport_error(@arg); | |||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub resume_output { | ||||||||||||||||||||||||||||||
|
Subroutine
resume_output: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 82 | 0 | my ($self, @arg) = @_; | |||||||||||||||||||||||||||||||
| 83 | 0 | return $self->_stream_backend('resume_output')->resume_output(@arg); | |||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub want_read { | ||||||||||||||||||||||||||||||
|
Subroutine
want_read: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 87 | 0 | my ($self, @arg) = @_; | |||||||||||||||||||||||||||||||
| 88 | 0 | return $self->_stream_backend('want_read')->want_read(@arg); | |||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub want_write { | ||||||||||||||||||||||||||||||
|
Subroutine
want_write: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 92 | 0 | my ($self, @arg) = @_; | |||||||||||||||||||||||||||||||
| 93 | 0 | return $self->_stream_backend('want_write')->want_write(@arg); | |||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub output { | ||||||||||||||||||||||||||||||
|
Subroutine
output: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 97 | 0 | my ($self, @arg) = @_; | |||||||||||||||||||||||||||||||
| 98 | 0 | return $self->_stream_backend('output')->output(@arg); | |||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub close { | ||||||||||||||||||||||||||||||
|
Subroutine
close: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 102 | 0 | my ($self, @arg) = @_; | |||||||||||||||||||||||||||||||
| 103 | 0 | return $self->_stream_backend('close')->close(@arg); | |||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub start { | ||||||||||||||||||||||||||||||
|
Subroutine
start: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 107 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | $self->{backend}->start if $self->{protocol} eq 'h3'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 109 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub started { | ||||||||||||||||||||||||||||||
|
Subroutine
started: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 113 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 114 | return $self->{protocol} eq 'h3' | ||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | ? $self->{backend}->started : 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 1 | 1; | |||||||||||||||||||||||||||||||