| 1 | package Unblock::HTTP::Server; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use Scalar::Util qw(blessed refaddr weaken); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Unblock::HTTP::_Policy; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Unblock::HTTP::_EngineFactory; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 26 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=23 SCAR=34.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 26 | my ($class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 26 | ▶ | croak 'new(): expected named arguments' if @args % 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 26 | my %options = @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 26 | my (%protocols, %callbacks); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 26 | for my $name (qw(http1 http2 http3)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 78 | ▶ | $protocols{$name} = delete $options{$name} if exists $options{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 26 | for my $name (qw(on_headers on_request on_error on_websocket on_handoff)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 127 | ▶ | next unless exists $options{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 26 | my $callback = delete $options{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 26 | ▶ | croak "new(): $name must be a coderef" unless ref($callback) eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 25 | $callbacks{$name} = $callback; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 25 | my $defer = delete $options{defer}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 25 | ▶ | croak 'new(): defer must be a coderef' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $defer and ref $defer ne "CODE"
MC/DC0%0/2
defined $defer and ref $defer ne "CODE"
defined $defer
ref $defer ne "CODE"
Truth table33%1/3
A and B
A= defined $deferB= ref $defer ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | if defined($defer) && ref($defer) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 25 | ▶ | croak 'new(): unknown option: ' . join(', ', sort keys %options) if %options; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 22 | ▶ | croak 'new(): on_request callback is required' unless $callbacks{on_request}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 22 | my $policy = Unblock::HTTP::_Policy->new(%protocols, _websocket_role => 'server'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 11 | ▶ | my $websocket_enabled = $policy->websocket_enabled('http/1.1') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$policy->websocket_enabled('http/1.1') || $policy->websocket_enabled('h2') || $policy->websocket_enabled('h3')
$policy->websocket_enabled("http/1.1") or $policy->websocket_enabled("h2")
MC/DC100%3/3
$policy->websocket_enabled('http/1.1') || $policy->websocket_enabled('h2') || $policy->websocket_enabled('h3')
$policy->websocket_enabled("http/1.1")
$policy->websocket_enabled("h2")
$policy->websocket_enabled('h3')
Truth table100%4/4
A or B || C
A= $policy->websocket_enabled("http/1.1")B= $policy->websocket_enabled("h2")C= $policy->websocket_enabled('h3')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | || $policy->websocket_enabled('h2') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | || $policy->websocket_enabled('h3'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | croak 'new(): on_websocket callback is required for enabled WebSocket support' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 11 | ▶ | if $websocket_enabled && !$callbacks{on_websocket}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$websocket_enabled and not $callbacks{"on_websocket"}
MC/DC50%1/2
$websocket_enabled and not $callbacks{"on_websocket"}
$websocket_enabled
not $callbacks{"on_websocket"}
Truth table66%2/3
A and not(B)
A= $websocket_enabledB= not $callbacks{"on_websocket"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | croak 'new(): on_websocket requires an enabled websocket protocol' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 8 | ▶ | if !$websocket_enabled && $callbacks{on_websocket}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $websocket_enabled and $callbacks{"on_websocket"}
MC/DC0%0/2
not $websocket_enabled and $callbacks{"on_websocket"}
not $websocket_enabled
$callbacks{"on_websocket"}
Truth table33%1/3
not(A) and B
A= not $websocket_enabledB= $callbacks{"on_websocket"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | croak 'new(): multiplexed stream handoff requires a defer callback' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | if ($policy->websocket_enabled('h2') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | || $policy->websocket_enabled('h3') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 8 | ▶ | || $callbacks{on_handoff}) && !$defer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$policy->websocket_enabled("h2") || $policy->websocket_enabled("h3") || $callbacks{"on_handoff"} and not $defer
$policy->websocket_enabled("h2") or $policy->websocket_enabled("h3") or $callbacks{"on_handoff"}
$policy->websocket_enabled("h2") or $policy->websocket_enabled("h3")
MC/DC0%0/4
$policy->websocket_enabled("h2") || $policy->websocket_enabled("h3") || $callbacks{"on_handoff"} and not $defer
$policy->websocket_enabled("h2")
$policy->websocket_enabled("h3")
$callbacks{"on_handoff"}
not $defer
Truth table14%1/7
A or B or C and not(D)
A= $policy->websocket_enabled("h2")B= $policy->websocket_enabled("h3")C= $callbacks{"on_handoff"}D= not $defer
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | return bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | policy => $policy, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | on_websocket => $callbacks{on_websocket}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | on_handoff => $callbacks{on_handoff}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | defer => $defer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # Map once at definition time; no transaction or body wrapper. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | callbacks => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | on_request => $callbacks{on_headers} || \&_ignore_headers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | on_request_end => $callbacks{on_request}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 8 | ▶ | ($callbacks{on_error} ? (on_error => $callbacks{on_error}) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$callbacks{'on_headers'} || \&Unblock::HTTP::Server::_ignore_headers
MC/DC0%0/1
$callbacks{'on_headers'} || \&Unblock::HTTP::Server::_ignore_headers
$callbacks{'on_headers'}
Truth table50%1/2
A
A= $callbacks{'on_headers'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | ▶ | sub _ignore_headers { return } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ignore_headers: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # Recognize even incomplete WebSocket attempts so a malformed upgrade is not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # silently treated as an ordinary application request. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub _websocket_candidate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_websocket_candidate: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my ($request) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | for my $index (0 .. $request->header_count - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $name = lc $request->header_name($index); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | return 1 if $name =~ /\Asec-websocket-/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | next unless $name eq 'upgrade'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | for my $token (split /,/, $request->header_value($index)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | return 1 if $token =~ /\A[ \t]*websocket[ \t]*\z/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # HTTP1 sends a complete 101 Upgrade or successful CONNECT response before | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # yielding the socket. The new consumer is framework-owned and implements | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # the generic input/EOF/error/output interface, NOT an HTTP or WS class. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub _generic_switch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generic_switch: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my ($self, $host, $engine, $tx, $response) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | my $handler = $self->{on_handoff} or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my $successor = $handler->($tx, $tx->request, $response, $host); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | croak 'on_handoff must return a successor protocol consumer' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | unless blessed($successor); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | for my $method (qw(input input_eof transport_error resume_output)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | croak "on_handoff successor must implement $method()" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | unless $successor->can($method); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $host->unblock_upgrade($successor); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $tail = $engine->take_remainder; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | $successor->input($tail) if length $tail; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub _attach_handoff_stream { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_attach_handoff_stream: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my ($self, $transport, $engine_options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | croak 'attach_stream(): HTTP1 handoff requires unblock_upgrade()' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | unless $transport->can('unblock_upgrade'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $host = $transport; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | weaken($host); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $engine; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my %callbacks = %{ $self->{callbacks} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | $callbacks{on_switch} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my ($tx, $response) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | croak 'handoff transport no longer exists' unless $host; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $self->_generic_switch($host, $engine, $tx, $response); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my $attached = Unblock::HTTP::_EngineFactory->create( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 'Server', 'http/1.1', %$engine_options, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | %callbacks, transport => $transport, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $engine = $attached; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | weaken($engine); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | return $attached; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # HTTP1 switches the complete byte stream, not an individual transaction. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # Keep the lower engine and transport as the only byte owners. Only this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # opted-in attachment gets a pair of per-connection transition callbacks. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub _attach_websocket_stream { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_attach_websocket_stream: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my ($self, $transport, $engine_options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | croak 'attach_stream(): HTTP1 WebSocket transport must implement unblock_upgrade()' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | unless $transport->can('unblock_upgrade'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $host = $transport; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | weaken($host); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | my $engine; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my $handler = $self->{on_websocket}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my $on_http_request = $self->{callbacks}{on_request_end}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $pending; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | my $on_request_end = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my ($tx, $request) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | return $on_http_request->(@_) unless _websocket_candidate($request); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my $selected = $handler->($tx, $request); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | unless (defined $selected) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $tx->respond(status => 403, body => 'WebSocket denied'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | croak 'on_websocket must return a hash reference or undef' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | unless ref($selected) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my %option = %$selected; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my %handshake_option; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | for my $name (qw(subprotocols permessage_deflate)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | $handshake_option{$name} = delete $option{$name} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if exists $option{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my $on_open = delete $option{on_open}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | croak 'on_websocket on_open must be a coderef' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $on_open and ref $on_open ne "CODE"
MC/DC0%0/2
defined $on_open and ref $on_open ne "CODE"
defined $on_open
ref $on_open ne "CODE"
Truth table0%0/3
A and B
A= defined $on_openB= ref $on_open ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | if defined($on_open) && ref($on_open) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | croak 'on_websocket may not override the attached transport' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | if exists $option{transport}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | require Unblock::WebSocket::Handshake; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | require Unblock::WebSocket::Server; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | my $handshake; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my $valid = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $handshake = Unblock::WebSocket::Handshake->server_accept( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | $request, %handshake_option, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | unless ($valid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $tx->respond(status => 400, body => 'Invalid WebSocket handshake'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | my $ws = Unblock::WebSocket::Server->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | %{ $handshake->connection_options }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | %option, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | transport => $host, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $pending = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | transaction => refaddr($tx), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | websocket => $ws, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | on_open => $on_open, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | request => $request, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # Even a failed host write must release the pending WebSocket state. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | $tx->on_finish(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | $pending = undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | if $pending && $pending->{transaction} == refaddr($_[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$pending and $pending->{"transaction"} == builtin::refaddr($_[0])
MC/DC0%0/2
$pending and $pending->{"transaction"} == builtin::refaddr($_[0])
$pending
$pending->{"transaction"} == builtin::refaddr($_[0])
Truth table0%0/3
A and B
A= $pendingB= $pending->{"transaction"} == builtin::refaddr($_[0])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my $ok = eval { $tx->respond($handshake->server_response); 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | unless ($ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | $pending = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | die $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | my $on_switch = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | my ($tx) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # An ordinary CONNECT or unrelated protocol switch remains the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # lower HTTP1 engine's responsibility, not an implicit WebSocket. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | if (!$pending) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | croak 'handoff transport no longer exists' unless $host; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | return $self->_generic_switch($host, $engine, $tx, $tx->response) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | if $self->{on_handoff}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | croak 'WebSocket switch transaction does not match the handshake' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | unless $pending->{transaction} == refaddr($tx); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | my $ready = $pending; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $pending = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my $ws = $ready->{websocket}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | croak 'WebSocket transport was destroyed during handshake' unless $host; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $host->unblock_upgrade($ws); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | $ready->{on_open}->($ws, $tx, $ready->{request}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | if $ready->{on_open}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | my $tail = $engine->take_remainder; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | $ws->input($tail) if length $tail; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my %callbacks = %{ $self->{callbacks} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | $callbacks{on_request_end} = $on_request_end; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | $callbacks{on_switch} = $on_switch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | my $attached = Unblock::HTTP::_EngineFactory->create( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 'Server', 'http/1.1', %$engine_options, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | %callbacks, transport => $transport, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $engine = $attached; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | weaken($engine); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | return $attached; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # A generic CONNECT takes ownership of one multiplexed stream, not the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # TCP/TLS/QUIC transport. Reuse the existing bounded deferred body bridge. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # The caller supplies a byte consumer, never a new HTTP parser. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | sub _generic_multiplexed_handoff { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generic_multiplexed_handoff: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my ($self, $tx, $request, $sessions, $attempts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my $id = $tx->stream_id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | $attempts->{$id} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | require Unblock::HTTP::_WebSocketH2Body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | my $bridge = Unblock::HTTP::_WebSocketH2Body->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | transaction => $tx, defer => $self->{defer}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my $consumer = $self->{on_handoff}->($tx, $request, $bridge); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | unless (defined $consumer) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | $bridge->detach; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | $tx->on_finish(sub { delete $attempts->{$id} }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | $tx->respond(status => 403, body => 'CONNECT denied'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | croak 'on_handoff must return a stream consumer' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | unless blessed($consumer); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | for my $method (qw(input input_eof transport_error resume_output)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | croak "on_handoff stream consumer must implement $method()" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | unless $consumer->can($method); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | $bridge->consumer($consumer); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | $sessions->{$id} = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | bridge => $bridge, consumer => $consumer, generic => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | $tx->on_data(sub { $consumer->input($_[1]) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | $tx->on_finish(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my ($finished_tx) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | $consumer->transport_error( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$finished_tx->error || 'CONNECT stream ended'
MC/DC0%0/1
$finished_tx->error || 'CONNECT stream ended'
$finished_tx->error
Truth table0%0/2
A
A= $finished_tx->error
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | $finished_tx->error || 'CONNECT stream ended', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | ) unless $finished_tx->is_complete; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | $bridge->detach; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | delete $sessions->{$id}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | delete $attempts->{$id}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | $tx->respond( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | status => 200, stream_body => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | on_drain => sub { $bridge->resume }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # Extended CONNECT belongs to one H2 transaction; the HTTP/2 connection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | # remains able to serve independent ordinary HTTP and other WebSockets. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # Outgoing WebSocket frames must NEVER re-enter nghttp2 from input callbacks. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | sub _attach_h2_websocket_stream { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_attach_h2_websocket_stream: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my ($self, $transport, $engine_options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | require Unblock::HTTP::_WebSocketH2Body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | my $handler = $self->{on_websocket}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | my $defer = $self->{defer}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | my $on_headers = $self->{callbacks}{on_request}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | my $on_request_end = $self->{callbacks}{on_request_end}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | my (%sessions, %handled_generic); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | my $on_request = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=17 SCAR=57.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my ($tx, $request) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my $protocol = $request->protocol; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | my $candidate = $handler && $request->method eq 'CONNECT' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/12
$handler && $request->method eq 'CONNECT' && (defined $protocol && $protocol eq 'websocket' || _websocket_candidate($request))
$handler and $request->method eq "CONNECT"
defined $protocol and $protocol eq "websocket" or _websocket_candidate($request)
defined $protocol and $protocol eq "websocket"
MC/DC0%0/5
$handler && $request->method eq 'CONNECT' && (defined $protocol && $protocol eq 'websocket' || _websocket_candidate($request))
$handler
$request->method eq "CONNECT"
defined $protocol
$protocol eq "websocket"
_websocket_candidate($request)
Truth table0%0/7
A and B && C and D or E
A= $handlerB= $request->method eq "CONNECT"C= defined $protocolD= $protocol eq "websocket"E= _websocket_candidate($request)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | && ((defined($protocol) && $protocol eq 'websocket') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | || _websocket_candidate($request)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | unless ($candidate) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | return $self->_generic_multiplexed_handoff( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | $tx, $request, \%sessions, \%handled_generic, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | ) if $self->{on_handoff} && $request->method eq 'CONNECT'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"on_handoff"} and $request->method eq "CONNECT"
MC/DC0%0/2
$self->{"on_handoff"} and $request->method eq "CONNECT"
$self->{"on_handoff"}
$request->method eq "CONNECT"
Truth table0%0/3
A and B
A= $self->{"on_handoff"}B= $request->method eq "CONNECT"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | return $on_headers->(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my $selected = $handler->($tx, $request); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | unless (defined $selected) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $tx->respond(status => 403, body => 'WebSocket denied'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | croak 'on_websocket must return a hash reference or undef' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | unless ref($selected) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | my %option = %$selected; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my %handshake_option; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | for my $name (qw(subprotocols permessage_deflate)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | $handshake_option{$name} = delete $option{$name} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | if exists $option{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | my $on_open = delete $option{on_open}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | croak 'on_websocket on_open must be a coderef' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $on_open and ref $on_open ne "CODE"
MC/DC0%0/2
defined $on_open and ref $on_open ne "CODE"
defined $on_open
ref $on_open ne "CODE"
Truth table0%0/3
A and B
A= defined $on_openB= ref $on_open ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | if defined($on_open) && ref($on_open) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | croak 'on_websocket may not override the H2 stream transport' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | if exists $option{transport}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | require Unblock::WebSocket::Handshake; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | require Unblock::WebSocket::Server; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my $handshake; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my $valid = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | $handshake = Unblock::WebSocket::Handshake->server_accept( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | $request, %handshake_option, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | unless ($valid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | $tx->respond(status => 400, body => 'Invalid WebSocket handshake'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my $bridge = Unblock::HTTP::_WebSocketH2Body->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | transaction => $tx, defer => $defer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | my $ws = Unblock::WebSocket::Server->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | %{ $handshake->connection_options }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | %option, transport => $bridge, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | $bridge->websocket($ws); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | my $id = $tx->stream_id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | $sessions{$id} = { bridge => $bridge, websocket => $ws }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | $tx->on_data(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | $ws->input($_[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | $tx->on_finish(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | $bridge->detach; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | delete $sessions{$id}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | $tx->respond( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | $handshake->server_response, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | stream_body => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | on_drain => sub { $bridge->resume }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | $on_open->($ws, $tx, $request) if $on_open; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | my $on_request_complete = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | my ($tx) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | my $id = $tx->stream_id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | if (my $session = $sessions{$id}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | if ($session->{generic}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | $session->{consumer}->input_eof; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | $session->{websocket}->input_eof; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | return if $handled_generic{$id}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | return $on_request_end->(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | my %callbacks = %{ $self->{callbacks} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $callbacks{on_request} = $on_request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $callbacks{on_request_end} = $on_request_complete; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | return Unblock::HTTP::_EngineFactory->create( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 'Server', 'h2', %$engine_options, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | %callbacks, transport => $transport, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | # A WebSocket CONNECT occupies an H3 QUIC request stream, not the QUIC | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | # connection. The real Transaction owns both directions; the private body | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | # bridge only defers outgoing WebSocket writes past the H3 receive callback. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | sub _attach_h3_websocket_connection { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_attach_h3_websocket_connection: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | my ($self, $connection, $engine_options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | require Unblock::HTTP::_WebSocketH2Body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | my $handler = $self->{on_websocket}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | my $defer = $self->{defer}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | my $on_headers = $self->{callbacks}{on_request}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | my $on_request_end = $self->{callbacks}{on_request_end}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | my (%sessions, %websocket_attempts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | my $on_request = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=17 SCAR=57.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | my ($tx, $request) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | my $protocol = $request->protocol; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | my $candidate = $handler && $request->method eq 'CONNECT' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/12
$handler && $request->method eq 'CONNECT' && (defined $protocol && $protocol eq 'websocket' || _websocket_candidate($request))
$handler and $request->method eq "CONNECT"
defined $protocol and $protocol eq "websocket" or _websocket_candidate($request)
defined $protocol and $protocol eq "websocket"
MC/DC0%0/5
$handler && $request->method eq 'CONNECT' && (defined $protocol && $protocol eq 'websocket' || _websocket_candidate($request))
$handler
$request->method eq "CONNECT"
defined $protocol
$protocol eq "websocket"
_websocket_candidate($request)
Truth table0%0/7
A and B && C and D or E
A= $handlerB= $request->method eq "CONNECT"C= defined $protocolD= $protocol eq "websocket"E= _websocket_candidate($request)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | && ((defined($protocol) && $protocol eq 'websocket') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | || _websocket_candidate($request)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | unless ($candidate) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | return $self->_generic_multiplexed_handoff( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | $tx, $request, \%sessions, \%websocket_attempts, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | ) if $self->{on_handoff} && $request->method eq 'CONNECT'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"on_handoff"} and $request->method eq "CONNECT"
MC/DC0%0/2
$self->{"on_handoff"} and $request->method eq "CONNECT"
$self->{"on_handoff"}
$request->method eq "CONNECT"
Truth table0%0/3
A and B
A= $self->{"on_handoff"}B= $request->method eq "CONNECT"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | return $on_headers->(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | my $id = $tx->stream_id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | $websocket_attempts{$id} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | my $selected = $handler->($tx, $request); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | ▶ | unless (defined $selected) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | $tx->on_finish(sub { delete $websocket_attempts{$id} }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $tx->respond(status => 403, body => 'WebSocket denied'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | croak 'on_websocket must return a hash reference or undef' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | unless ref($selected) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | my %option = %$selected; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | my %handshake_option; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | for my $name (qw(subprotocols permessage_deflate)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | $handshake_option{$name} = delete $option{$name} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | ▶ | if exists $option{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | my $on_open = delete $option{on_open}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | croak 'on_websocket on_open must be a coderef' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $on_open and ref $on_open ne "CODE"
MC/DC0%0/2
defined $on_open and ref $on_open ne "CODE"
defined $on_open
ref $on_open ne "CODE"
Truth table0%0/3
A and B
A= defined $on_openB= ref $on_open ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | if defined($on_open) && ref($on_open) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | croak 'on_websocket may not override the H3 stream transport' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | if exists $option{transport}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | require Unblock::WebSocket::Handshake; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | require Unblock::WebSocket::Server; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | my $handshake; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | my $valid = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $handshake = Unblock::WebSocket::Handshake->server_accept( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | $request, %handshake_option, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | unless ($valid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | $tx->on_finish(sub { delete $websocket_attempts{$id} }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | $tx->respond(status => 400, body => 'Invalid WebSocket handshake'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | my $bridge = Unblock::HTTP::_WebSocketH2Body->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | transaction => $tx, defer => $defer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | my $ws = Unblock::WebSocket::Server->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | %{ $handshake->connection_options }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | %option, transport => $bridge, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | $bridge->websocket($ws); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | $sessions{$id} = { bridge => $bridge, websocket => $ws }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | $tx->on_data(sub { $ws->input($_[1]) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | $tx->on_finish(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | $bridge->detach; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | delete $sessions{$id}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | delete $websocket_attempts{$id}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | $tx->respond( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | $handshake->server_response, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | stream_body => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | ▶ | on_drain => sub { $bridge->resume }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | $on_open->($ws, $tx, $request) if $on_open; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | ▶ | my $on_request_complete = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | my ($tx) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | my $id = $tx->stream_id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | ▶ | if ($websocket_attempts{$id}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | ▶ | if (my $session = $sessions{$id}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | if ($session->{generic}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | $session->{consumer}->input_eof; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | $session->{websocket}->input_eof; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | # Even a 400/403 CONNECT belongs to on_websocket, not to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | # the ordinary request-end responder. Do not respond twice. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | return $on_request_end->(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | my %callbacks = %{ $self->{callbacks} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | $callbacks{on_request} = $on_request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | $callbacks{on_request_end} = $on_request_complete; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | my $engine = Unblock::HTTP::_EngineFactory->create( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 'Server', 'h3', %$engine_options, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | %callbacks, quic => $connection, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | $engine->start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | return $engine; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 1 | ▶ | sub protocols { return $_[0]{policy}->protocols } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
protocols: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 3 | ▶ | sub alpn_protocols { return $_[0]{policy}->alpn_protocols } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
alpn_protocols: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 9 | ▶ | sub supports { return $_[0]{policy}->enabled($_[1]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supports: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 18 | ▶ | sub attach_stream { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attach_stream: called CC=22 SCAR=31.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 18 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 18 | ▶ | croak 'attach_stream(): expected named arguments' if @args % 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 17 | my %options = @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | croak 'attach_stream(): specify either protocol or alpn, not both' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 17 | ▶ | if exists($options{protocol}) && exists($options{alpn}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $options{"protocol"} and exists $options{"alpn"}
MC/DC100%2/2
exists $options{"protocol"} and exists $options{"alpn"}
exists $options{"protocol"}
exists $options{"alpn"}
Truth table100%3/3
A and B
A= exists $options{"protocol"}B= exists $options{"alpn"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 16 | my $transport = delete $options{transport}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 16 | my $protocol = delete $options{protocol}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 16 | my $alpn = delete $options{alpn}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 16 | ▶ | croak 'attach_stream(): unknown option: ' . join(', ', sort keys %options) if %options; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 14 | ▶ | croak 'attach_stream(): protocol and alpn must be scalars' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $protocol or ref $alpn
MC/DC50%1/2
ref $protocol or ref $alpn
ref $protocol
ref $alpn
Truth table66%2/3
A or B
A= ref $protocolB= ref $alpn
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | if ref($protocol) || ref($alpn); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 13 | ▶ | $protocol = defined($alpn) && length($alpn) ? $alpn : 'http/1.1' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
defined $alpn and length $alpn
MC/DC100%2/2
defined $alpn and length $alpn
defined $alpn
length $alpn
Truth table100%3/3
A and B
A= defined $alpnB= length $alpn
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | unless defined $protocol; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 13 | ▶ | croak "attach_stream(): unsupported byte-stream protocol '$protocol'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$protocol eq "http/1.1" or $protocol eq "h2"
MC/DC100%2/2
$protocol eq "http/1.1" or $protocol eq "h2"
$protocol eq "http/1.1"
$protocol eq "h2"
Truth table100%3/3
A or B
A= $protocol eq "http/1.1"B= $protocol eq "h2"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | unless $protocol eq 'http/1.1' || $protocol eq 'h2'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 11 | my $engine_options = $self->{policy}->options($protocol); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 9 | ▶ | croak 'attach_stream(): transport must be an object' unless blessed($transport); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 8 | for my $method (qw(unblock_send unblock_finish unblock_abort)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 22 | ▶ | croak "attach_stream(): transport must implement $method()" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | unless $transport->can($method); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | return $self->_attach_websocket_stream($transport, $engine_options) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 7 | ▶ | if $protocol eq 'http/1.1' && $self->{policy}->websocket_enabled($protocol); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$protocol eq "http/1.1" and $self->{"policy"}->websocket_enabled($protocol)
MC/DC0%0/2
$protocol eq "http/1.1" and $self->{"policy"}->websocket_enabled($protocol)
$protocol eq "http/1.1"
$self->{"policy"}->websocket_enabled($protocol)
Truth table66%2/3
A and B
A= $protocol eq "http/1.1"B= $self->{"policy"}->websocket_enabled($protocol)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | return $self->_attach_handoff_stream($transport, $engine_options) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 7 | ▶ | if $protocol eq 'http/1.1' && $self->{on_handoff}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$protocol eq "http/1.1" and $self->{"on_handoff"}
MC/DC0%0/2
$protocol eq "http/1.1" and $self->{"on_handoff"}
$protocol eq "http/1.1"
$self->{"on_handoff"}
Truth table66%2/3
A and B
A= $protocol eq "http/1.1"B= $self->{"on_handoff"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | return $self->_attach_h2_websocket_stream($transport, $engine_options) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | if $protocol eq 'h2' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | && ($self->{policy}->websocket_enabled($protocol) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 7 | ▶ | || $self->{on_handoff}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$protocol eq "h2" and $self->{"policy"}->websocket_enabled($protocol) || $self->{"on_handoff"}
$self->{"policy"}->websocket_enabled($protocol) or $self->{"on_handoff"}
MC/DC0%0/3
$protocol eq "h2" and $self->{"policy"}->websocket_enabled($protocol) || $self->{"on_handoff"}
$protocol eq "h2"
$self->{"policy"}->websocket_enabled($protocol)
$self->{"on_handoff"}
Truth table50%2/4
A and B or C
A= $protocol eq "h2"B= $self->{"policy"}->websocket_enabled($protocol)C= $self->{"on_handoff"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | return Unblock::HTTP::_EngineFactory->create( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 'Server', $protocol, %$engine_options, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 7 | %{ $self->{callbacks} }, transport => $transport, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 12 | ▶ | sub attach_quic { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attach_quic: called CC=10 SCAR=23.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 12 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 12 | ▶ | croak 'attach_quic(): expected named arguments' if @args % 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 11 | my %options = @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 11 | my $connection = delete $options{connection}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 11 | ▶ | croak 'attach_quic(): unknown option: ' . join(', ', sort keys %options) if %options; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 10 | my $engine_options = $self->{policy}->options('h3'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 9 | ▶ | croak 'attach_quic(): connection must be a QUIC connection object' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
builtin::blessed($connection) and $connection->can("ready") and $connection->can("closed")
builtin::blessed($connection) and $connection->can("ready")
MC/DC33%1/3
builtin::blessed($connection) and $connection->can("ready") and $connection->can("closed")
builtin::blessed($connection)
$connection->can("ready")
$connection->can("closed")
Truth table50%2/4
A and B and C
A= builtin::blessed($connection)B= $connection->can("ready")C= $connection->can("closed")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | unless blessed($connection) && $connection->can('ready') && $connection->can('closed'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 8 | ▶ | croak 'attach_quic(): connection is closed' if $connection->closed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 7 | ▶ | croak 'attach_quic(): connection is not ready' unless $connection->ready; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | return $self->_attach_h3_websocket_connection($connection, $engine_options) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 6 | ▶ | if $self->{policy}->websocket_enabled('h3') || $self->{on_handoff}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"policy"}->websocket_enabled("h3") or $self->{"on_handoff"}
MC/DC0%0/2
$self->{"policy"}->websocket_enabled("h3") or $self->{"on_handoff"}
$self->{"policy"}->websocket_enabled("h3")
$self->{"on_handoff"}
Truth table33%1/3
A or B
A= $self->{"policy"}->websocket_enabled("h3")B= $self->{"on_handoff"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | my $engine = Unblock::HTTP::_EngineFactory->create( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 'Server', 'h3', %$engine_options, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 6 | %{ $self->{callbacks} }, quic => $connection, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 6 | $engine->start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 6 | return $engine; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||