blib/lib/Linux/Event/WebSocket/_Handshake.pm

filter: Statementstmt 97.9% 142 / 145 Branchbran 60.4% 58 / 96 Conditioncond 41.0% 32 / 78 MC/DCmcdc 11.6% 5 / 43 Subroutinesub 100% 22 / 22 Podpod 0.0% 0 / 5 totaltotal 66.5% 259 / 389 CC 83 SCAR 34.2
CC
83
Cov
73%
client_request
75.5
validate_client_response
24.4
server_from_request
16.0
CRAP 30.6
« blib/lib/Linux/Event/WebSocket/_State.pm ↑ Summary blib/lib/Linux/Event/WebSocket/_Parser.pm »
1 package Linux::Event::WebSocket::_Handshake;
2 8 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use Digest::SHA qw(sha1);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use MIME::Base64 qw(decode_base64 encode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use URI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 8 ▶use Uniform::HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use Linux::Event::WebSocket::_Random;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 8 my $GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
15 8 my $TOKEN_RE = qr/\A[!#\$%&'*+\-.^_`|~0-9A-Za-z]+\z/;
16  
17 65 ▶sub _trim ($value) {
Subroutine _trim: called CC=1 SCAR=0.0
18 65 $value =~ s/\A[ \t]+//;
19 65 $value =~ s/[ \t]+\z//;
20 65 return $value;
21 }
22  
23 83 ▶sub _header_values ($message, $wanted) {
Subroutine _header_values: called CC=3 SCAR=11.0
24 83 my @value;
25 83 for my $index (0 .. $message->header_count - 1) {
26 349 my $name = $message->header_name($index);
27 349 ▶ push @value, $message->header_value($index)
Branch: 1 branch
BranchTrueFalseTotal
if lc $name eq lc $wanted 63 286 349
28 if lc($name) eq lc($wanted);
29 }
30 83 return @value;
31 }
32  
33 44 ▶sub _tokens ($where, @value) {
Subroutine _tokens: called CC=5 SCAR=16.3
34 44 my @token;
35 44 for my $value (@value) {
36 38 for my $token (split /,/, $value, -1) {
37 40 $token = _trim($token);
38 40 ▶ croak "$where contains an empty token" if $token eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $token eq "" 0 40 40
39 40 ▶ croak "$where contains an invalid token '$token'"
Branch: 1 branch
BranchTrueFalseTotal
unless $token =~ /$TOKEN_RE/u 0 40 40
40 if $token !~ $TOKEN_RE;
41 40 push @token, $token;
42 }
43 }
44 44 return @token;
45 }
46  
47 34 ▶sub _has_token ($message, $name, $wanted) {
Subroutine _has_token: called CC=3 SCAR=11.2
48 34 for my $token (_tokens($name, _header_values($message, $name))) {
49 35 ▶ return 1 if lc($token) eq lc($wanted);
Branch: 1 branch
BranchTrueFalseTotal
if lc $token eq lc $wanted 34 1 35
50 }
51 0 return 0;
52 }
53  
54 25 ▶sub _singleton ($message, $name) {
Subroutine _singleton: called CC=3 SCAR=11.4
55 25 my @value = _header_values($message, $name);
56 25 ▶ croak "WebSocket handshake requires $name" if !@value;
Branch: 1 branch
BranchTrueFalseTotal
unless @value 0 25 25
57 25 ▶ croak "WebSocket handshake contains duplicate $name" if @value > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @value > 1 0 25 25
58 25 return _trim($value[0]);
59 }
60  
61 17 ▶sub _valid_key ($key) {
Subroutine _valid_key: called CC=2 SCAR=7.2
62 17 ▶ return 0 if $key !~ /\A[A-Za-z0-9+\/]{22}==\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $key =~ m[\A[A-Za-z0-9+/]{22}==\z]u 0 17 17
63 17 return length(decode_base64($key)) == 16;
64 }
65  
66 17 ▶sub _accept ($key) {
Subroutine _accept: called CC=1 SCAR=0.0
67 17 return encode_base64(sha1($key . $GUID), '');
68 }
69  
70 19 ▶sub _checked_subprotocols ($where, $subprotocols) {
Subroutine _checked_subprotocols: called CC=7 SCAR=22.5
71 19 ▶ croak "$where: subprotocols must be an array reference"
Branch: 1 branch
BranchTrueFalseTotal
if ref $subprotocols ne "ARRAY" 0 19 19
72 if ref($subprotocols) ne 'ARRAY';
73  
74 19 my %seen;
75 my @copy;
76 19 for my $token (@$subprotocols) {
77 6 ▶ croak "$where: each subprotocol must be a WebSocket token"
Branch: 1 branch
BranchTrueFalseTotal
if not defined $token or ref $token or not $token =~ /$TOKEN_RE/u 0 6 6
Condition33%2/6
not defined $token or ref $token or not $token =~ /$TOKEN_RE/u
l!l&&r!l&&!r
006
not defined $token or ref $token
l!l&&r!l&&!r
006
MC/DC0%0/3
not defined $token or ref $token or not $token =~ /$TOKEN_RE/u
not defined $token ref $token not $token =~ /$TOKEN_RE/u
Truth table25%1/4
not(A) or B or not(C)
A= not defined $tokenB= ref $tokenC= not $token =~ /$TOKEN_RE/u
ABCresult
1XX1
01X1
0011
0000
78 if !defined($token) || ref($token) || $token !~ $TOKEN_RE;
79 croak "$where: duplicate subprotocol '$token'"
80 6 ▶ if $seen{$token}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$token}++ 0 6 6
81 6 push @copy, "$token";
82 }
83 19 return \@copy;
84 }
85  
86 10 ▶sub server_from_request ($class, $request, %option) {
Subroutine server_from_request: called CC=14 SCAR=27.7
Pod undocumented
87 10 ▶ croak 'server_from_request(): request object is required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $request and ref $request 0 10 10
Condition33%1/3
defined $request and ref $request
!ll&&!rl&&r
0010
MC/DC0%0/2
defined $request and ref $request
defined $request ref $request
Truth table33%1/3
A and B
A= defined $requestB= ref $request
ABresult
0X0
100
111
88 if !defined($request) || !ref($request);
89  
90 my $supported = _checked_subprotocols(
91 'server_from_request()',
92 10 ▶ delete($option{subprotocols}) // [],
Condition100%2/2
delete $option{"subprotocols"} // []
l!l
82
MC/DC100%1/1
delete $option{"subprotocols"} // []
delete $option{"subprotocols"}
Truth table100%2/2
A
A= delete $option{"subprotocols"}
Aresult
11
00
93 );
94 10 ▶ croak 'server_from_request(): unknown option(s): '
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 10 10
95 . join(', ', sort keys %option)
96 if %option;
97  
98 10 ▶ croak 'WebSocket handshake method must be GET'
Branch: 1 branch
BranchTrueFalseTotal
if $request->method ne "GET" 1 9 10
99 if $request->method ne 'GET';
100 9 ▶ croak 'WebSocket handshake requires HTTP/1.1'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $request->version or $request->version ne "1.1" 1 8 9
Condition66%2/3
not defined $request->version or $request->version ne "1.1"
l!l&&r!l&&!r
018
MC/DC50%1/2
not defined $request->version or $request->version ne "1.1"
not defined $request->version $request->version ne "1.1"
Truth table66%2/3
not(A) or B
A= not defined $request->versionB= $request->version ne "1.1"
ABresult
1X1
011
000
101 if !defined($request->version) || $request->version ne '1.1';
102 8 ▶ croak 'WebSocket handshake Upgrade header must contain websocket'
Branch: 1 branch
BranchTrueFalseTotal
unless _has_token($request, "Upgrade", "websocket") 0 8 8
103 if !_has_token($request, 'Upgrade', 'websocket');
104 8 ▶ croak 'WebSocket handshake Connection header must contain Upgrade'
Branch: 1 branch
BranchTrueFalseTotal
unless _has_token($request, "Connection", "Upgrade") 0 8 8
105 if !_has_token($request, 'Connection', 'Upgrade');
106  
107 8 my $version = _singleton($request, 'Sec-WebSocket-Version');
108 8 ▶ croak 'WebSocket handshake Sec-WebSocket-Version must be 13'
Branch: 1 branch
BranchTrueFalseTotal
if $version ne 13 0 8 8
109 if $version ne '13';
110  
111 8 my $key = _singleton($request, 'Sec-WebSocket-Key');
112 8 ▶ croak 'WebSocket handshake contains invalid Sec-WebSocket-Key'
Branch: 1 branch
BranchTrueFalseTotal
unless _valid_key($key) 0 8 8
113 if !_valid_key($key);
114  
115 8 my @offered = _tokens(
116 'Sec-WebSocket-Protocol',
117 _header_values($request, 'Sec-WebSocket-Protocol'),
118 );
119 8 my %offered_seen;
120 8 for my $token (@offered) {
121 croak "WebSocket handshake contains duplicate subprotocol '$token'"
122 3 ▶ if $offered_seen{$token}++;
Branch: 1 branch
BranchTrueFalseTotal
if $offered_seen{$token}++ 0 3 3
123 }
124  
125 8 my %supported = map { $_ => 1 } @$supported;
126 8 my ($selected) = grep { $supported{$_} } @offered;
127  
128 8 return bless {
129 endpoint_type => 'server',
130 key => $key,
131 offered_subprotocols => \@offered,
132 selected_subprotocol => $selected,
133 }, $class;
134 }
135  
136 8 ▶sub apply_server_response ($class, $handshake, $response) {
Subroutine apply_server_response: called CC=8 SCAR=23.9
Pod undocumented
137 croak 'apply_server_response(): handshake object is required'
138 if !defined($handshake) || !ref($handshake)
139 8 ▶ || !$handshake->isa($class) || $handshake->{endpoint_type} ne 'server';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $handshake && ref $handshake && $handshake->isa($class) or $handshake->{"endpoint_type"} ne "server" 0 8 8
Condition33%3/9
not defined $handshake && ref $handshake && $handshake->isa($class) or $handshake->{"endpoint_type"} ne "server"
l!l&&r!l&&!r
008
defined $handshake && ref $handshake && $handshake->isa($class)
!ll&&!rl&&r
008
defined $handshake and ref $handshake
!ll&&!rl&&r
008
MC/DC0%0/4
not defined $handshake && ref $handshake && $handshake->isa($class) or $handshake->{"endpoint_type"} ne "server"
defined $handshake ref $handshake $handshake->isa($class) $handshake->{"endpoint_type"} ne "server"
Truth table20%1/5
not(A and B && C) or D
A= defined $handshakeB= ref $handshakeC= $handshake->isa($class)D= $handshake->{"endpoint_type"} ne "server"
ABCDresult
0XXX1
10XX1
110X1
11111
11100
140 8 ▶ croak 'apply_server_response(): response object is required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $response and ref $response 0 8 8
Condition33%1/3
defined $response and ref $response
!ll&&!rl&&r
008
MC/DC0%0/2
defined $response and ref $response
defined $response ref $response
Truth table33%1/3
A and B
A= defined $responseB= ref $response
ABresult
0X0
100
111
141 if !defined($response) || !ref($response);
142  
143 8 $response->status(101);
144 8 $response->reason('Switching Protocols');
145 8 $response->header(Upgrade => 'websocket');
146 8 $response->header(Connection => 'Upgrade');
147 8 $response->header('Sec-WebSocket-Accept' => _accept($handshake->{key}));
148 8 ▶ if (defined $handshake->{selected_subprotocol}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $handshake->{"selected_subprotocol"}) 2 6 8
149 $response->header(
150 'Sec-WebSocket-Protocol' => $handshake->{selected_subprotocol},
151 2 );
152 }
153 8 return $response;
154 }
155  
156 9 ▶sub client_request ($class, $url, %option) {
Subroutine client_request: called CC=31 SCAR=43.2
Pod undocumented
157 9 ▶ croak 'client_request(): URL must be a non-empty scalar'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $url or ref $url or $url eq "" 0 9 9
Condition33%2/6
not defined $url or ref $url or $url eq ""
l!l&&r!l&&!r
009
not defined $url or ref $url
l!l&&r!l&&!r
009
MC/DC0%0/3
not defined $url or ref $url or $url eq ""
not defined $url ref $url $url eq ""
Truth table25%1/4
not(A) or B or C
A= not defined $urlB= ref $urlC= $url eq ""
ABCresult
1XX1
01X1
0011
0000
158 if !defined($url) || ref($url) || $url eq '';
159  
160 9 my $origin = delete $option{origin};
161 9 ▶ croak 'client_request(): origin must be a scalar'
Branch: 1 branch
BranchTrueFalseTotal
if defined $origin and ref $origin 0 9 9
Condition66%2/3
defined $origin and ref $origin
!ll&&!rl&&r
810
MC/DC0%0/2
defined $origin and ref $origin
defined $origin ref $origin
Truth table66%2/3
A and B
A= defined $originB= ref $origin
ABresult
0X0
100
111
162 if defined($origin) && ref($origin);
163  
164 my $subprotocols = _checked_subprotocols(
165 'client_request()',
166 9 ▶ delete($option{subprotocols}) // [],
Condition100%2/2
delete $option{"subprotocols"} // []
l!l
81
MC/DC100%1/1
delete $option{"subprotocols"} // []
delete $option{"subprotocols"}
Truth table100%2/2
A
A= delete $option{"subprotocols"}
Aresult
11
00
167 );
168  
169 9 ▶ my $headers = delete($option{headers}) // [];
Condition100%2/2
delete $option{"headers"} // []
l!l
81
MC/DC100%1/1
delete $option{"headers"} // []
delete $option{"headers"}
Truth table100%2/2
A
A= delete $option{"headers"}
Aresult
11
00
170 9 ▶ croak 'client_request(): headers must be an array reference'
Branch: 1 branch
BranchTrueFalseTotal
if ref $headers ne "ARRAY" 0 9 9
171 if ref($headers) ne 'ARRAY';
172  
173 9 my $host_header = delete $option{host_header};
174 9 ▶ croak 'client_request(): host_header must be a scalar'
Branch: 1 branch
BranchTrueFalseTotal
if defined $host_header and ref $host_header 0 9 9
Condition33%1/3
defined $host_header and ref $host_header
!ll&&!rl&&r
090
MC/DC0%0/2
defined $host_header and ref $host_header
defined $host_header ref $host_header
Truth table33%1/3
A and B
A= defined $host_headerB= ref $host_header
ABresult
0X0
100
111
175 if defined($host_header) && ref($host_header);
176  
177 9 my $key = delete $option{key};
178 9 ▶ $key = encode_base64(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 8 1 9
179 Linux::Event::WebSocket::_Random->bytes(16),
180 '',
181 ) if !defined $key;
182 9 ▶ croak 'client_request(): key must be a valid base64-encoded 16-byte value'
Branch: 1 branch
BranchTrueFalseTotal
if ref $key or not _valid_key($key) 0 9 9
Condition33%1/3
ref $key or not _valid_key($key)
l!l&&r!l&&!r
009
MC/DC0%0/2
ref $key or not _valid_key($key)
ref $key not _valid_key($key)
Truth table33%1/3
A or not(B)
A= ref $keyB= not _valid_key($key)
ABresult
1X1
011
000
183 if ref($key) || !_valid_key($key);
184  
185 9 ▶ croak 'client_request(): unknown option(s): '
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 9 9
186 . join(', ', sort keys %option)
187 if %option;
188  
189 9 my @extra;
190 9 for my $pair (@$headers) {
191 1 ▶ croak 'client_request(): each header must be a [name, value] pair'
Branch: 1 branch
BranchTrueFalseTotal
if ref $pair ne "ARRAY" or @$pair != 2 0 1 1
Condition33%1/3
ref $pair ne "ARRAY" or @$pair != 2
l!l&&r!l&&!r
001
MC/DC0%0/2
ref $pair ne "ARRAY" or @$pair != 2
ref $pair ne "ARRAY" @$pair != 2
Truth table33%1/3
A or B
A= ref $pair ne "ARRAY"B= @$pair != 2
ABresult
1X1
011
000
192 if ref($pair) ne 'ARRAY' || @$pair != 2;
193 1 my ($name, $value) = @$pair;
194 1 ▶ croak 'client_request(): header name and value must be scalars'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $name or ref $name or not defined $value or ref $value 0 1 1
Condition33%3/9
not defined $name or ref $name or not defined $value or ref $value
l!l&&r!l&&!r
001
not defined $name or ref $name or not defined $value
l!l&&r!l&&!r
001
not defined $name or ref $name
l!l&&r!l&&!r
001
MC/DC0%0/4
not defined $name or ref $name or not defined $value or ref $value
not defined $name ref $name not defined $value ref $value
Truth table20%1/5
not(A) or B or not(C) or D
A= not defined $nameB= ref $nameC= not defined $valueD= ref $value
ABCDresult
1XXX1
01XX1
001X1
00011
00000
195 if !defined($name) || ref($name) || !defined($value) || ref($value);
196 1 push @extra, [ "$name", "$value" ];
197 }
198  
199 9 my $uri = URI->new("$url");
200 9 my $target = $uri->path;
201 9 ▶ $target = '/' if !defined($target) || $target eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $target or $target eq "" 0 9 9
Condition33%1/3
not defined $target or $target eq ""
l!l&&r!l&&!r
009
MC/DC0%0/2
not defined $target or $target eq ""
not defined $target $target eq ""
Truth table33%1/3
not(A) or B
A= not defined $targetB= $target eq ""
ABresult
1X1
011
000
202 9 my $query = $uri->query;
203 9 ▶ $target .= "?$query" if defined($query) && length($query);
Branch: 1 branch
BranchTrueFalseTotal
if defined $query and length $query 1 8 9
Condition66%2/3
defined $query and length $query
!ll&&!rl&&r
801
MC/DC50%1/2
defined $query and length $query
defined $query length $query
Truth table66%2/3
A and B
A= defined $queryB= length $query
ABresult
0X0
100
111
204  
205 9 ▶ if (!defined $host_header) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $host_header) 0 9 9
206 0 $host_header = $uri->authority;
207 0 ▶ croak 'client_request(): URL must contain an authority'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $host_header or $host_header eq "" 0 0 0
Condition0%0/3
not defined $host_header or $host_header eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $host_header or $host_header eq ""
not defined $host_header $host_header eq ""
Truth table0%0/3
not(A) or B
A= not defined $host_headerB= $host_header eq ""
ABresult
1X1
011
000
208 if !defined($host_header) || $host_header eq '';
209 }
210  
211 9 my @http_headers = (
212 [ Host => "$host_header" ],
213 [ Upgrade => 'websocket' ],
214 [ Connection => 'Upgrade' ],
215 [ 'Sec-WebSocket-Key' => "$key" ],
216 [ 'Sec-WebSocket-Version' => '13' ],
217 );
218 9 ▶ push @http_headers,
Branch: 1 branch
BranchTrueFalseTotal
if @$subprotocols 2 7 9
219 [ 'Sec-WebSocket-Protocol' => join(', ', @$subprotocols) ]
220 if @$subprotocols;
221 9 ▶ push @http_headers, [ Origin => "$origin" ] if defined $origin;
Branch: 1 branch
BranchTrueFalseTotal
if defined $origin 1 8 9
222 9 push @http_headers, @extra;
223  
224 9 my $request = Uniform::HTTP::Request->new(
225 method => 'GET',
226 target => $target,
227 version => '1.1',
228 headers => \@http_headers,
229 );
230  
231 9 my $handshake = bless {
232 endpoint_type => 'client',
233 key => "$key",
234 offered_subprotocols => [ @$subprotocols ],
235 selected_subprotocol => undef,
236 }, $class;
237  
238 9 return ($handshake, $request);
239 }
240  
241 9 ▶sub validate_client_response ($class, $handshake, $response) {
Subroutine validate_client_response: called CC=16 SCAR=32.0
Pod undocumented
242 croak 'validate_client_response(): handshake object is required'
243 if !defined($handshake) || !ref($handshake)
244 9 ▶ || !$handshake->isa($class) || $handshake->{endpoint_type} ne 'client';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $handshake && ref $handshake && $handshake->isa($class) or $handshake->{"endpoint_type"} ne "client" 0 9 9
Condition33%3/9
not defined $handshake && ref $handshake && $handshake->isa($class) or $handshake->{"endpoint_type"} ne "client"
l!l&&r!l&&!r
009
defined $handshake && ref $handshake && $handshake->isa($class)
!ll&&!rl&&r
009
defined $handshake and ref $handshake
!ll&&!rl&&r
009
MC/DC0%0/4
not defined $handshake && ref $handshake && $handshake->isa($class) or $handshake->{"endpoint_type"} ne "client"
defined $handshake ref $handshake $handshake->isa($class) $handshake->{"endpoint_type"} ne "client"
Truth table20%1/5
not(A and B && C) or D
A= defined $handshakeB= ref $handshakeC= $handshake->isa($class)D= $handshake->{"endpoint_type"} ne "client"
ABCDresult
0XXX1
10XX1
110X1
11111
11100
245 9 ▶ croak 'validate_client_response(): response object is required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $response and ref $response 0 9 9
Condition33%1/3
defined $response and ref $response
!ll&&!rl&&r
009
MC/DC0%0/2
defined $response and ref $response
defined $response ref $response
Truth table33%1/3
A and B
A= defined $responseB= ref $response
ABresult
0X0
100
111
246 if !defined($response) || !ref($response);
247  
248 9 ▶ croak 'WebSocket handshake response status must be 101'
Branch: 1 branch
BranchTrueFalseTotal
if $response->status != 101 0 9 9
249 if $response->status != 101;
250 9 ▶ croak 'WebSocket handshake response Upgrade header must contain websocket'
Branch: 1 branch
BranchTrueFalseTotal
unless _has_token($response, "Upgrade", "websocket") 0 9 9
251 if !_has_token($response, 'Upgrade', 'websocket');
252 9 ▶ croak 'WebSocket handshake response Connection header must contain Upgrade'
Branch: 1 branch
BranchTrueFalseTotal
unless _has_token($response, "Connection", "Upgrade") 0 9 9
253 if !_has_token($response, 'Connection', 'Upgrade');
254  
255 9 my $accept = _singleton($response, 'Sec-WebSocket-Accept');
256 croak 'WebSocket handshake response has invalid Sec-WebSocket-Accept'
257 9 ▶ if $accept ne _accept($handshake->{key});
Branch: 1 branch
BranchTrueFalseTotal
if $accept ne _accept($handshake->{"key"}) 1 8 9
258  
259 8 ▶ croak 'WebSocket handshake response selected an unsupported extension'
Branch: 1 branch
BranchTrueFalseTotal
if _header_values($response, "Sec-WebSocket-Extensions") 0 8 8
260 if _header_values($response, 'Sec-WebSocket-Extensions');
261  
262 8 my @protocol = _header_values($response, 'Sec-WebSocket-Protocol');
263 8 ▶ croak 'WebSocket handshake response contains duplicate Sec-WebSocket-Protocol'
Branch: 1 branch
BranchTrueFalseTotal
if @protocol > 1 0 8 8
264 if @protocol > 1;
265 8 ▶ if (@protocol) {
Branch: 1 branch
BranchTrueFalseTotal
if (@protocol) 2 6 8
266 2 my @token = _tokens('Sec-WebSocket-Protocol', $protocol[0]);
267 2 ▶ croak 'WebSocket handshake response must select one subprotocol'
Branch: 1 branch
BranchTrueFalseTotal
if @token != 1 0 2 2
268 if @token != 1;
269 2 my %offered = map { $_ => 1 } @{$handshake->{offered_subprotocols}};
270 croak "WebSocket handshake response selected unknown subprotocol '$token[0]'"
271 2 ▶ if !$offered{$token[0]};
Branch: 1 branch
BranchTrueFalseTotal
unless $offered{$token[0]} 0 2 2
272 2 $handshake->{selected_subprotocol} = $token[0];
273 }
274  
275 8 return $handshake;
276 }
277  
278 16 ▶sub subprotocol ($class, $handshake) {
Subroutine subprotocol: called CC=1 SCAR=0.0
Pod undocumented
279 16 return $handshake->{selected_subprotocol};
280 }
281  
282 8 1;
« blib/lib/Linux/Event/WebSocket/_State.pm ↑ Summary blib/lib/Linux/Event/WebSocket/_Parser.pm »