« blib/lib/Linux/Event/WebSocket/_Engine.pm
↑ Summary
blib/lib/Linux/Event/WebSocket/Server/_HTTPConnection.pm »
| 1 | package Linux::Event::WebSocket::Client::_HTTPConnection; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 6 | ▶ | use parent 'Linux::Event::IO::Sock::Stream'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Unblock::HTTP1::Client; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use Linux::Event::Framer (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use Linux::Event::WebSocket::_BQ (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | # Begin with the existing HTTP-byte native consumer so Linux::Event can | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # replace it with the native bq WebSocket consumer during transition_to(). | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # Linux::Event forbids adding a first provider during a live transition. | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 6 | Linux::Event::Framer->declare_native_consumer( | |||||||||||||||||||||||||||||||||||||||||
| 18 | __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||
| 19 | Linux::Event::WebSocket::_BQ->http_bridge_consumer_definition, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 81 | ▶ | sub can ($class, $name) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 81 | ▶ | return undef if $name eq 'on_data'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 76 | return UNIVERSAL::can($class, $name); | |||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 7 | ▶ | sub _websocket_http_input ($self, $bytes) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_websocket_http_input: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 7 | return $self->on_data($bytes); | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 6 | ▶ | use Linux::Event::WebSocket::_Handshake; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | # The HTTP opening exchange uses Unblock::HTTP1. On 101, this same Stream | ||||||||||||||||||||||||||||||||||||||||||
| 34 | # transitions directly to the caller's established WebSocket Connection class. | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # Its native bq input provider takes over, preserving TLS and queued output. | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 7 | ▶ | sub _websocket_state ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_websocket_state: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 7 | my $state = $self->SUPER::data; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 7 | ▶ | croak 'WebSocket client connection state is unavailable' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($state) and $state->isa("Linux::Event::WebSocket::_State")
MC/DC0%0/2
builtin::blessed($state) and $state->isa("Linux::Event::WebSocket::_State")
builtin::blessed($state)
$state->isa("Linux::Event::WebSocket::_State")
Truth table33%1/3
A and B
A= builtin::blessed($state)B= $state->isa("Linux::Event::WebSocket::_State")
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | unless blessed($state) | ||||||||||||||||||||||||||||||||||||||||||
| 40 | && $state->isa('Linux::Event::WebSocket::_State'); | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 7 | return $state; | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub data ($self, @value) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
data: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my $state = $self->_websocket_state; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | croak 'data() accepts at most one value' if @value > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | $state->{data} = $value[0] if @value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | return $state->{data}; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub _report_error ($self, $error) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_report_error: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $state = $self->_websocket_state; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | return if $state->{handshake_error_reported}++; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $message = "$error"; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $message =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if (my $callback = $state->{callbacks}{error}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $callback->($self, $message); | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 7 | ▶ | sub on_ready ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_ready: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 7 | my $state = $self->_websocket_state; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 7 | my $http = Unblock::HTTP1::Client->new(transport => $self); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 7 | $self->{ws_opening_http} = $http; | |||||||||||||||||||||||||||||||||||||||||
| 66 | $http->request( | ||||||||||||||||||||||||||||||||||||||||||
| 67 | $state->{request}, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 7 | ▶ | on_response => sub ($tx, $response) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 7 | $state->{response} = $response; | |||||||||||||||||||||||||||||||||||||||||
| 70 | Linux::Event::WebSocket::_Handshake->validate_client_response( | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 7 | $state->{handshake}, $response, | |||||||||||||||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 73 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 7 | ▶ | on_switch => sub ($tx, $response) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 7 | $state->{response} = $response; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 7 | my $opening = delete $self->{ws_opening_http}; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 7 | ▶ | my $tail = $opening ? $opening->take_remainder : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 7 | $self->transition_to($state->{connection_class}); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 7 | $self->_ensure_websocket_open; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 7 | ▶ | $state->{engine}->feed($tail) if length $tail && !$self->is_closed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $tail and not $self->is_closed
MC/DC50%1/2
length $tail and not $self->is_closed
length $tail
not $self->is_closed
Truth table66%2/3
A and not(B)
A= length $tailB= not $self->is_closed
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | on_error => sub ($tx, $error) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $self->_report_error($error); | |||||||||||||||||||||||||||||||||||||||||
| 84 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||
| 86 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 7 | ▶ | sub on_data ($self, $bytes) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_data: called CC=4 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 7 | ▶ | my $http = $self->{ws_opening_http} or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 7 | my $ok = eval { $http->input($bytes); 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 7 | ▶ | unless ($ok) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $self->_report_error($@); | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | $self->SUPER::close unless $self->is_closed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub on_eof ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_eof: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my $http = $self->{ws_opening_http}; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ($http && !$http->is_closed && !$http->is_switched) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$http and not $http->is_closed and not $http->is_switched
$http and not $http->is_closed
MC/DC0%0/3
$http and not $http->is_closed and not $http->is_switched
$http
not $http->is_closed
not $http->is_switched
Truth table0%0/4
A and not(B) and not(C)
A= $httpB= not $http->is_closedC= not $http->is_switched
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | eval { $http->input_eof }; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | $self->SUPER::close unless $self->is_closed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub on_error ($self, $error) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $self->_report_error($error); | |||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub on_drain ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_drain: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $http = $self->{ws_opening_http}; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | $http->resume_output if $http && !$http->is_closed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$http and not $http->is_closed
MC/DC0%0/2
$http and not $http->is_closed
$http
not $http->is_closed
Truth table0%0/3
A and not(B)
A= $httpB= not $http->is_closed
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub on_close ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_close: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my $http = delete $self->{ws_opening_http}; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ($http && !$http->is_closed && !$http->is_switched) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$http and not $http->is_closed and not $http->is_switched
$http and not $http->is_closed
MC/DC0%0/3
$http and not $http->is_closed and not $http->is_switched
$http
not $http->is_closed
not $http->is_switched
Truth table0%0/4
A and not(B) and not(C)
A= $httpB= not $http->is_closedC= not $http->is_switched
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $http->transport_error('WebSocket opening transport closed'); | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 7 | ▶ | sub unblock_send ($self, $bytes) { return $self->write($bytes) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unblock_send: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub unblock_finish ($self) { return $self->end } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unblock_finish: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub unblock_abort ($self, $error) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unblock_abort: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | $self->SUPER::close unless $self->is_closed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||