WebSocket/Request.pm

filter: Statementstmt 50.8% 203 / 399 Branchbran 21.1% 64 / 302 Conditioncond 26.7% 43 / 161 MC/DCmcdc 3.5% 3 / 85 Subroutinesub 75.4% 40 / 53 Podpod 100% 16 / 16 totaltotal 36.3% 369 / 1016 CC 211 SCAR 72.3
CC
211
Cov
36%
parse
3692.5
__ANON__
140.2
_parse_postprocess
127.7
CRAP 1385.0
« WebSocket/Response.pm ↑ Summary WebSocket/HeaderValue.pm »
1 ##----------------------------------------------------------------------------
2 ## WebSocket Client & Server - ~/lib/WebSocket/Request.pm
3 ## Version v0.1.1
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/09/16
7 ## Modified 2023/04/21
8 ## You can use, copy, modify and redistribute this package and associated
9 ## files under the same terms as Perl itself.
10 ##----------------------------------------------------------------------------
11 package WebSocket::Request;
12 BEGIN
13 5 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶ use WebSocket::Common qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶ use parent qw( WebSocket::Common );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶ use Digest::MD5 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶ use HTTP::Request ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶ use MIME::Base64 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶ use Nice::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 ▶ use Scalar::Util qw( readonly );
Subroutine BEGIN: called CC=1 SCAR=0.0
24 5 ▶ use Want;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 5 ▶ use WebSocket::Extension;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 5 ▶ use WebSocket::Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 5 ▶ use WebSocket::Version;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 5 our $VERSION = 'v0.1.1';
29 };
30  
31 sub init
32 13 ▶{
Subroutine init: called CC=9 SCAR=24.1
Pod documented
33 13 my $self = shift( @_ );
34 13 my( $headers, $buffer );
35 13 ▶ if( @_ &&
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and $self->_is_array($_[0]) || $self->_is_a($_[0], "HTTP::Headers")) 8 5 13
Condition83%5/6
@_ and $self->_is_array($_[0]) || $self->_is_a($_[0], "HTTP::Headers")
!ll&&!rl&&r
148
$self->_is_array($_[0]) or $self->_is_a($_[0], "HTTP::Headers")
l!l&&r!l&&!r
804
MC/DC66%2/3
@_ and $self->_is_array($_[0]) || $self->_is_a($_[0], "HTTP::Headers")
@_ $self->_is_array($_[0]) $self->_is_a($_[0], "HTTP::Headers")
Truth table75%3/4
A and B or C
A= @_B= $self->_is_array($_[0])C= $self->_is_a($_[0], "HTTP::Headers")
ABCresult
0XX0
1000
11X1
1011
36 ( $self->_is_array( $_[0] ) || $self->_is_a( $_[0], 'HTTP::Headers' ) ) )
37 {
38 8 $headers = shift( @_ );
39 8 ▶ if( $self->_is_a( $headers, 'HTTP::Headers' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($headers, 'HTTP::Headers')) { } 0 8 8
40 {
41 0 $headers = $headers->clone;
42 0 $headers = bless( $headers => 'WebSocket::Headers' );
43 }
44 else
45 {
46 8 $headers = WebSocket::Headers->new( @$headers );
47 }
48 # $req->new( $headers, $buffer, k1 => v1, k2 => v2);
49 # $req->new( $headers, $buffer, { k1 => v1, k2 => v2 });
50 # $req->new( $headers, k1 => v1, k2 => v2);
51 # $req->new( $headers, { k1 => v1, k2 => v2 });
52 8 ▶ if( ( ( @_ % 2 ) && ref( $_[1] ) ne 'HASH' ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2 and ref $_[1] ne "HASH" or ref $_[1] eq "HASH") 0 8 8
Condition33%2/6
@_ % 2 and ref $_[1] ne "HASH" or ref $_[1] eq "HASH"
l!l&&r!l&&!r
008
@_ % 2 and ref $_[1] ne "HASH"
!ll&&!rl&&r
800
MC/DC0%0/3
@_ % 2 and ref $_[1] ne "HASH" or ref $_[1] eq "HASH"
@_ % 2 ref $_[1] ne "HASH" ref $_[1] eq "HASH"
Truth table20%1/5
A and B or C
A= @_ % 2B= ref $_[1] ne "HASH"C= ref $_[1] eq "HASH"
ABCresult
11X1
0X11
1011
0X00
1000
53 ref( $_[1] ) eq 'HASH' )
54 {
55 0 $buffer = shift( @_ );
56 }
57 }
58 13 $self->{buffer} = $buffer;
59 13 $self->{headers} = $headers;
60 13 $self->{method} = '';
61 13 $self->{_init_strict_use_sub} = 1;
62 13 $self->{_init_params_order} = [qw( buffer headers )];
63 13 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 13 0 13
64 13 return( $self );
65 }
66  
67 sub as_string
68 2 ▶{
Subroutine as_string: called CC=24 SCAR=46.4
Pod documented
69 2 my $self = shift( @_ );
70 2 ▶ my $eol = shift( @_ ) || "\x0d\x0a";
Condition50%1/2
shift @_ || "\r\n"
l!l
02
MC/DC0%0/1
shift @_ || "\r\n"
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
71  
72 2 ▶ my $version = $self->version || WebSocket::Version->new( WEBSOCKET_DRAFT_VERSION_DEFAULT );
Condition33%1/3
$self->version || 'WebSocket::Version'->new('draft-ietf-hybi-17')
l!l&&r!l&&!r
200
MC/DC0%0/2
$self->version || 'WebSocket::Version'->new('draft-ietf-hybi-17')
$self->version 'WebSocket::Version'->new('draft-ietf-hybi-17')
Truth table33%1/3
A || B
A= $self->versionB= 'WebSocket::Version'->new('draft-ietf-hybi-17')
ABresult
1X1
011
000
73 2 ▶ return( $self->error( "uri is required" ) ) unless( defined( $self->uri ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->uri 0 2 2
74 2 ▶ return( $self->error( "Host is required" ) ) unless( $self->host->defined && $self->host->length );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->host->defined and $self->host->length 0 2 2
Condition33%1/3
$self->host->defined and $self->host->length
!ll&&!rl&&r
020
MC/DC0%0/2
$self->host->defined and $self->host->length
$self->host->defined $self->host->length
Truth table33%1/3
A and B
A= $self->host->definedB= $self->host->length
ABresult
0X0
100
111
75 2 ▶ my $req_line = "GET " . ( $self->uri->path_query || '/' ) . " HTTP/1.1";
Condition50%1/2
$self->uri->path_query || '/'
l!l
20
MC/DC0%0/1
$self->uri->path_query || '/'
$self->uri->path_query
Truth table50%1/2
A
A= $self->uri->path_query
Aresult
11
00
76 2 my $h = $self->headers;
77 2 $h->header( Upgrade => 'WebSocket', Connection => 'Upgrade' );
78 2 ▶ if( $self->cookies->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cookies->length) 0 2 2
79 {
80 0 $h->header( Cookie => $self->cookies->scalar );
81 }
82 2 ▶ my $origin = $self->origin ? $self->origin : 'http://' . $self->host;
Branch: 1 branch
BranchTrueFalseTotal
$self->origin ? : 1 1 2
83 2 ▶ $origin =~ s{^http:}{https:} if( $self->secure );
Branch: 1 branch
BranchTrueFalseTotal
if $self->secure 0 2 2
84 # Version 10 or lower; From version 11, it uses 'Origin' only; but from version 0 to 3, it uses also Origin
85 2 ▶ if( $version->type eq 'hybi' &&
Branch: 1 branch
BranchTrueFalseTotal
if ($version->type eq 'hybi' and ($version->revision >= 4 and $version->revision <= 10)) { } 0 2 2
Condition33%2/6
$version->type eq "hybi" and ($version->revision >= 4 and $version->revision <= 10)
!ll&&!rl&&r
020
$version->revision >= 4 and $version->revision <= 10
!ll&&!rl&&r
020
MC/DC0%0/3
$version->type eq "hybi" and ($version->revision >= 4 and $version->revision <= 10)
$version->type eq "hybi" $version->revision >= 4 $version->revision <= 10
Truth table25%1/4
A and B and C
A= $version->type eq "hybi"B= $version->revision >= 4C= $version->revision <= 10
ABCresult
0XX0
10X0
1100
1111
86 ( $version->revision >= 4 && $version->revision <= 10 ) )
87 {
88 0 $h->header( 'Sec-WebSocket-Origin' => $origin );
89 }
90 else
91 {
92 2 $h->header( Origin => $origin );
93 }
94
95 2 ▶ if( $version->type eq 'hybi' && $version->revision >= 4 )
Branch: 3 branches
BranchTrueFalseTotal
if ($version->type eq 'hybi' and $version->revision >= 4) { } 2 0 2
elsif ($version->type eq 'hybi' or $version->type eq 'hixie' and $version->revision == 76) { } 0 0 0
elsif ($version->type eq 'hixie') { } 0 0 0
Condition33%1/3
$version->type eq "hybi" and $version->revision >= 4
!ll&&!rl&&r
002
MC/DC0%0/2
$version->type eq "hybi" and $version->revision >= 4
$version->type eq "hybi" $version->revision >= 4
Truth table33%1/3
A and B
A= $version->type eq "hybi"B= $version->revision >= 4
ABresult
0X0
100
111
96 {
97 2 my $key = $self->key;
98 2 ▶ if( !$key )
Branch: 1 branch
BranchTrueFalseTotal
unless ($key) 1 1 2
99 {
100 1 $key = $self->_generate_16bit_nonce();
101 }
102
103 # rfc6455, section 4.1 ยง10 <https://datatracker.ietf.org/doc/html/rfc6455#section-4.1>
104 # "If present, this value indicates one or more comma-separated subprotocol the client wishes to speak, ordered by preference."
105 2 ▶ if( $self->subprotocol->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->subprotocol->length) 2 0 2
106 {
107 2 $h->header( 'Sec-WebSocket-Protocol' => $self->subprotocol->join( ',' )->scalar );
108 }
109 2 $h->header( 'Sec-WebSocket-Key' => $key );
110 # $h->header( 'Sec-WebSocket-Version' => ( $version eq 'draft-ietf-hybi-17' ? 13 : 8 ) );
111 2 $h->header( 'Sec-WebSocket-Version' => "$version" );
112 }
113 # Otherwise from hybi version 0 to 3 there is no version request header
114 ▶ elsif( $version->type eq 'hybi' ||
Condition0%0/6
$version->type eq "hybi" or $version->type eq "hixie" and $version->revision == 76
l!l&&r!l&&!r
000
$version->type eq "hixie" and $version->revision == 76
!ll&&!rl&&r
000
MC/DC0%0/3
$version->type eq "hybi" or $version->type eq "hixie" and $version->revision == 76
$version->type eq "hybi" $version->type eq "hixie" $version->revision == 76
Truth table0%0/4
A or B and C
A= $version->type eq "hybi"B= $version->type eq "hixie"C= $version->revision == 76
ABCresult
1XX1
0111
00X0
0100
115 ( $version->type eq 'hixie' && $version->revision == 76 ) )
116 {
117 0 $self->_generate_keys;
118 # Up to version HyBi 04, subprotocol are separated by a space
119 0 ▶ if( $self->subprotocol->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->subprotocol->length) 0 0 0
120 {
121 0 $h->header( 'Sec-WebSocket-Protocol' => $self->subprotocol->join( ' ' )->scalar );
122 }
123 0 $h->header( 'Sec-WebSocket-Key1' => $self->key1 );
124 0 $h->header( 'Sec-WebSocket-Key2' => $self->key2 );
125 0 $h->header( 'Content-Length' => length( $self->challenge ) );
126 }
127 elsif( $version->type eq 'hixie' )
128 {
129 # Up to version HyBi 04, subprotocol are separated by a space
130 0 ▶ $h->header( 'WebSocket-Protocol' => $self->subprotocol->join( ' ' )->scalar ) if( $self->subprotocol->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->subprotocol->length 0 0 0
131 }
132 else
133 {
134 0 return( $self->error( 'Version ' . $self->version . ' is not supported' ) );
135 }
136
137 return(
138 2 ▶ join(
Branch: 1 branch
BranchTrueFalseTotal
$version eq 'draft-ietf-hybi-00' ? : 0 2 2
139 '',
140 $req_line,
141 $eol,
142 $self->headers->as_string( $eol ),
143 $eol,
144 ( $version eq 'draft-ietf-hybi-00' ? $self->challenge : '' )
145 )
146 );
147 }
148  
149 1 ▶sub connection { return( shift->headers->header( 'Connection', @_ ) ); }
Subroutine connection: called CC=1 SCAR=0.0
Pod documented
150  
151 sub cookie_jar
152 0 ▶{
Subroutine cookie_jar: not called CC=7 SCAR=40.3
Pod documented
153 0 my $self = shift( @_ );
154 0 ▶ if( @_ )
Branch: 2 branches
BranchTrueFalseTotal
if (@_) { } 0 0 0
elsif (not $self->{'cookie_jar'}) { } 0 0 0
155 {
156 0 $self->{cookie_jar} = shift( @_ );
157 }
158 elsif( !$self->{cookie_jar} )
159 {
160 0 my $jar;
161 0 ▶ if( $self->_load_class( 'Cookie::Jar' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_load_class("Cookie::Jar")) 0 0 0
162 {
163 0 $jar = Cookie::Jar->new;
164 0 ▶ $jar->fetch( request => $self ) || return( $self->pass_error( $jar->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$jar->fetch("request", $self) or return $self->pass_error($jar->error) 0 0 0
165 0 $self->{cookie_jar} = $jar;
166 }
167 }
168
169 0 ▶ if( !$self->{cookie_jar} && Want::want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"cookie_jar"} and Want::want("OBJECT")) 0 0 0
Condition0%0/3
not $self->{"cookie_jar"} and Want::want("OBJECT")
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->{"cookie_jar"} and Want::want("OBJECT")
not $self->{"cookie_jar"} Want::want("OBJECT")
Truth table0%0/3
not(A) and B
A= not $self->{"cookie_jar"}B= Want::want("OBJECT")
ABresult
0X0
100
111
170 {
171 0 require Module::Generic::Null;
172 0 my $null = Module::Generic::Null->new( '', { debug => $self->{debug} });
173 0 return( $null );
174 }
175 0 return( $self->{cookie_jar} );
176 }
177  
178 2 ▶sub cookies { return( shift->_set_get_scalar_as_object( 'cookies', @_ ) ); }
Subroutine cookies: called CC=1 SCAR=0.0
Pod documented
179  
180 0 ▶sub header { return( shift->headers->header( @_ ) ); }
Subroutine header: not called CC=1 SCAR=6.9
Pod documented
181  
182 3 ▶sub key { return( shift->_key( key => @_ ) ); }
Subroutine key: called CC=1 SCAR=0.0
Pod documented
183  
184 2 ▶sub key1 { return( shift->_key( key1 => @_ ) ); }
Subroutine key1: called CC=1 SCAR=0.0
Pod documented
185  
186 0 ▶sub key2 { return( shift->_key( key2 => @_ ) ); }
Subroutine key2: not called CC=1 SCAR=6.9
Pod documented
187  
188 4 ▶sub method { return( shift->_set_get_scalar_as_object( 'method', @_ ) ); }
Subroutine method: called CC=1 SCAR=0.0
Pod documented
189  
190 0 ▶sub number1 { return( shift->_number( 'number1', 'key1', @_ ) ); }
Subroutine number1: not called CC=1 SCAR=6.9
Pod documented
191  
192 0 ▶sub number2 { return( shift->_number( 'number2', 'key2', @_ ) ); }
Subroutine number2: not called CC=1 SCAR=6.9
Pod documented
193  
194 sub origin
195 4 ▶{
Subroutine origin: called CC=13 SCAR=38.5
Pod documented
196 4 my $self = shift( @_ );
197 4 my $h = $self->headers;
198 4 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 3 4
199 {
200 # Based on our version, we set the right header
201 1 my $v = $self->version;
202 1 ▶ if( $v && $v->type eq 'hybi' && $v->revision >= 4 && $v->revision <= 10 )
Branch: 2 branches
BranchTrueFalseTotal
if ($v and $v->type eq 'hybi' and $v->revision >= 4 and $v->revision <= 10) { } 0 1 1
elsif ($v and $v->type eq 'hybi' and $v->revision >= 0 && $v->revision <= 3 || $v->revision >= 11 && $v->revision <= 17) { } 0 2 2
Condition33%3/9
$v and $v->type eq "hybi" and $v->revision >= 4 and $v->revision <= 10
!ll&&!rl&&r
100
$v and $v->type eq "hybi" and $v->revision >= 4
!ll&&!rl&&r
100
$v and $v->type eq "hybi"
!ll&&!rl&&r
100
MC/DC0%0/4
$v and $v->type eq "hybi" and $v->revision >= 4 and $v->revision <= 10
$v $v->type eq "hybi" $v->revision >= 4 $v->revision <= 10
Truth table20%1/5
A and B and C and D
A= $vB= $v->type eq "hybi"C= $v->revision >= 4D= $v->revision <= 10
ABCDresult
0XXX0
10XX0
110X0
11100
11111
203 {
204 0 $h->header( 'Sec-WebSocket-Origin' => shift( @_ ) );
205 }
206 ▶ elsif( $v &&
Condition13%2/15
$v and $v->type eq "hybi" and $v->revision >= 0 && $v->revision <= 3 || $v->revision >= 11 && $v->revision <= 17
!ll&&!rl&&r
100
$v and $v->type eq "hybi"
!ll&&!rl&&r
100
$v->revision >= 0 and $v->revision <= 3 or $v->revision >= 11 and $v->revision <= 17
l!l&&r!l&&!r
000
$v->revision >= 0 and $v->revision <= 3
!ll&&!rl&&r
000
$v->revision >= 11 and $v->revision <= 17
!ll&&!rl&&r
000
MC/DC0%0/6
$v and $v->type eq "hybi" and $v->revision >= 0 && $v->revision <= 3 || $v->revision >= 11 && $v->revision <= 17
$v $v->type eq "hybi" $v->revision >= 0 $v->revision <= 3 $v->revision >= 11 $v->revision <= 17
Truth table11%1/9
A and B and C and D or E and F
A= $vB= $v->type eq "hybi"C= $v->revision >= 0D= $v->revision <= 3E= $v->revision >= 11F= $v->revision <= 17
ABCDEFresult
0XXXXX0
10XXXX0
110X0X0
110X100
11100X0
1110100
1111XX1
110X111
1110111
207 $v->type eq 'hybi' &&
208 (
209 ( $v->revision >= 0 && $v->revision <= 3 ) ||
210 ( $v->revision >= 11 && $v->revision <= 17 )
211 ) )
212 {
213 0 $h->header( 'Origin' => shift( @_ ) );
214 }
215 }
216 4 ▶ return( $h->header( 'Origin' ) || $h->header( 'Sec-WebSocket-Origin' ) );
Condition66%2/3
$h->header('Origin') || $h->header('Sec-WebSocket-Origin')
l!l&&r!l&&!r
310
MC/DC0%0/2
$h->header('Origin') || $h->header('Sec-WebSocket-Origin')
$h->header('Origin') $h->header('Sec-WebSocket-Origin')
Truth table66%2/3
A || B
A= $h->header('Origin')B= $h->header('Sec-WebSocket-Origin')
ABresult
1X1
011
000
217 }
218  
219 sub parse
220 2 ▶{
Subroutine parse: called CC=96 SCAR=82.1
Pod documented
221 2 my $self = shift( @_ );
222 2 my $req;
223 0 ▶ try
Subroutine __ANON__: called CC=2 SCAR=7.4
Subroutine __ANON__: called CC=22 SCAR=49.4
Branch: 3 branches
BranchTrueFalseTotal
unless defined $Nice::Try::NEED_TO_RETURN 2 0 2
if ($INC{"threads.pm"} and not exists $INC{"forks.pm"}) 0 2 2
wantarray ? : 0 1 1
Condition33%1/3
$INC{"threads.pm"} and not exists $INC{"forks.pm"}
!ll&&!rl&&r
200
MC/DC0%0/2
$INC{"threads.pm"} and not exists $INC{"forks.pm"}
$INC{"threads.pm"} not exists $INC{"forks.pm"}
Truth table33%1/3
A and not(B)
A= $INC{"threads.pm"}B= not exists $INC{"forks.pm"}
ABresult
0X0
100
111
224 2 {
225 2 ▶ return(1) unless( defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 2 2
226 # Add data to buffer
227 2 ▶ $self->_append( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_append(@_) or return &$Nice::Try::RETURN($self->pass_error) 1 1 2
228 1 my $re;
229 1 ▶ unless( $re = $self->buffer->match( qr/^(?<method>\w+)[[:blank:]\h]+(?<uri>\S+)[[:blank:]\h]+(?<proto>HTTP\/\d+\.\d+)/ ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($re = $self->buffer->match(qr"^(?<method>\w+)[[:blank:]\h]+(?<uri>\S+)[[:blank:]\h]+(?<proto>HTTP/\d+\.\d+)")) 0 1 1
230 {
231 0 return( $self->error( "Wrong request line" ) );
232 }
233 1 ▶ unless( $re->name->method eq 'GET' && $re->name->proto eq 'HTTP/1.1' )
Branch: 1 branch
BranchTrueFalseTotal
unless ($re->name->method eq "GET" and $re->name->proto eq "HTTP/1.1") 0 1 1
Condition33%1/3
$re->name->method eq "GET" and $re->name->proto eq "HTTP/1.1"
!ll&&!rl&&r
001
MC/DC0%0/2
$re->name->method eq "GET" and $re->name->proto eq "HTTP/1.1"
$re->name->method eq "GET" $re->name->proto eq "HTTP/1.1"
Truth table33%1/3
A and B
A= $re->name->method eq "GET"B= $re->name->proto eq "HTTP/1.1"
ABresult
0X0
100
111
234 {
235 0 return( $self->error( "Wrong method or http version" ) );
236 }
237 1 $req = HTTP::Request->parse( $self->buffer->scalar );
238 1 $self->method( $req->method );
239 1 $self->uri( $req->uri );
240 1 $self->protocol( $req->protocol );
241 1 $self->headers( $req->headers );
242 # The rest is the body
243 1 $self->buffer( $req->content );
244 }
245 0 ▶ catch( $e )
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine BEGIN: called CC=1 SCAR=3.4
Subroutine __ANON__: not called CC=1 SCAR=3.4
Subroutine __ANON__: not called CC=1 SCAR=3.4
Subroutine __ANON__: not called CC=3 SCAR=20.1
Branch: 34 branches
BranchTrueFalseTotal
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 2 2
if ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
elsif ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
&$Nice::Try::TRY ? : 0 0 0
if scalar @Nice::Try::VOID 0 0 0
if ($Nice::Try::WANTARRAY) { } 0 2 2
elsif (defined $Nice::Try::WANTARRAY) { } 2 0 2
if defined $Nice::Try::LAST_VAL 0 0 0
length $@ ? : 0 2 2
unless builtin::blessed($@) 2 0 2
if ($Nice::Try::DIED) 0 2 2
if ($Nice::Try::HAS_CATCH) 0 0 0
if not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL 0 1 1
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 1 1
if ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
elsif ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
if ($Nice::Try::WANTARRAY) { } 0 1 1
elsif (defined $Nice::Try::WANTARRAY) { } 1 0 1
Condition37%3/8
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
200
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
!ll
10
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
100
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
MC/DC0%0/1
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
not defined $Nice::Try::WANTARRAY
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
Truth table33%1/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
Truth table50%1/2
not(A)
A= not defined $Nice::Try::WANTARRAY
Aresult
00
11
Truth table33%1/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
246 0 {
247 0 return( $self->error( "Error parsing request data: $e" ) );
248 0 ▶ }
Subroutine BEGIN: called CC=1 SCAR=4.4
Subroutine BEGIN: called CC=1 SCAR=4.4
Subroutine BEGIN: called CC=1 SCAR=4.4
Branch: 56 branches
BranchTrueFalseTotal
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 0 0
if ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
elsif ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
&$Nice::Try::CATCH ? : 0 0 0
if scalar @Nice::Try::VOID 0 0 0
if ($Nice::Try::WANTARRAY) { } 0 0 0
elsif (defined $Nice::Try::WANTARRAY) { } 0 0 0
if $@ 0 0 0
if (defined $Nice::Try::CATCH_DIED) 0 2 2
if (defined $Nice::Try::WANTARRAY || defined $Nice::Try::BREAK && $Nice::Try::BREAK eq 'return' and !builtin::blessed($Nice::Try::RETVAL[0]) || builtin::blessed($Nice::Try::RETVAL[0]) && !$Nice::Try::RETVAL[0]->isa('Nice::Try::SENTINEL')) { } 1 1 2
elsif (scalar @Nice::Try::VOID and !builtin::blessed($Nice::Try::VOID[0]) || builtin::blessed($Nice::Try::VOID[0]) && !$Nice::Try::VOID[0]->isa('Nice::Try::SENTINEL')) { } 0 1 1
if defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return" 0 1 1
if (not defined $Nice::Try::BREAK or $Nice::Try::BREAK eq "return") 1 0 1
if (defined $Nice::Try::WANT and length $Nice::Try::WANT) { } 0 1 1
if ($Nice::Try::WANT eq 'LIST') { } 0 0 0
elsif ($Nice::Try::WANT eq 'VOID') { } 0 0 0
elsif ($Nice::Try::WANT eq 'OBJECT') { } 0 0 0
elsif ($Nice::Try::WANT eq 'REFSCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'SCALAR') { } 0 0 0
elsif ($Nice::Try::WANT eq 'BOOLEAN') { } 0 0 0
elsif ($Nice::Try::WANT eq 'CODE') { } 0 0 0
elsif ($Nice::Try::WANT eq 'HASH') { } 0 0 0
elsif ($Nice::Try::WANT eq 'ARRAY') { } 0 0 0
elsif ($Nice::Try::WANT eq 'GLOB') { } 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
if (defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq '__NEXT__') { } 0 0 0
elsif (defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq '__LAST__') { } 0 0 0
elsif (defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq '__REDO__') { } 0 0 0
elsif (defined $Nice::Try::BREAK and $Nice::Try::BREAK eq 'return') { } 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 0 0 0
$Nice::Try::NEED_TO_RETURN ? : 1 0 1
$Nice::Try::WANTARRAY ? : 0 1 1
$Nice::Try::WANTARRAY ? : 0 0 0
scalar @Nice::Try::VOID > 1 ? : 0 0 0
if (defined $Nice::Try::BREAK) 0 1 1
if ($Nice::Try::BREAK eq 'next') { } 0 0 0
elsif ($Nice::Try::BREAK eq 'last') { } 0 0 0
elsif ($Nice::Try::BREAK eq 'redo') { } 0 0 0
scalar @Nice::Try::LAST_VAL > 1 ? : 0 1 1
if not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL 0 0 0
Condition24%12/50
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
000
defined $Nice::Try::WANTARRAY || defined $Nice::Try::BREAK && $Nice::Try::BREAK eq "return" and !builtin::blessed($Nice::Try::RETVAL[0]) || builtin::blessed($Nice::Try::RETVAL[0]) && !$Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
011
defined $Nice::Try::WANTARRAY or defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
l!l&&r!l&&!r
200
defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
!ll&&!rl&&r
000
not builtin::blessed($Nice::Try::RETVAL[0]) or builtin::blessed($Nice::Try::RETVAL[0]) and not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
l!l&&r!l&&!r
101
builtin::blessed($Nice::Try::RETVAL[0]) and not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
010
defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
!ll&&!rl&&r
100
not defined $Nice::Try::BREAK or $Nice::Try::BREAK eq "return"
l!l&&r!l&&!r
100
defined $Nice::Try::WANT and length $Nice::Try::WANT
!ll&&!rl&&r
100
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__NEXT__"
!ll&&!rl&&r
000
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__LAST__"
!ll&&!rl&&r
000
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__REDO__"
!ll&&!rl&&r
000
defined $Nice::Try::BREAK and $Nice::Try::BREAK eq "return"
!ll&&!rl&&r
000
scalar @Nice::Try::VOID and !builtin::blessed($Nice::Try::VOID[0]) || builtin::blessed($Nice::Try::VOID[0]) && !$Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
010
not builtin::blessed($Nice::Try::VOID[0]) or builtin::blessed($Nice::Try::VOID[0]) and not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
l!l&&r!l&&!r
001
builtin::blessed($Nice::Try::VOID[0]) and not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
!ll&&!rl&&r
010
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
!ll
00
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
MC/DC16%1/6
defined $Nice::Try::WANTARRAY || defined $Nice::Try::BREAK && $Nice::Try::BREAK eq "return" and !builtin::blessed($Nice::Try::RETVAL[0]) || builtin::blessed($Nice::Try::RETVAL[0]) && !$Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
defined $Nice::Try::WANTARRAY defined $Nice::Try::BREAK $Nice::Try::BREAK eq "return" not builtin::blessed($Nice::Try::RETVAL[0]) builtin::blessed($Nice::Try::RETVAL[0]) not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
MC/DC0%0/2
not defined $Nice::Try::BREAK or $Nice::Try::BREAK eq "return"
not defined $Nice::Try::BREAK $Nice::Try::BREAK eq "return"
MC/DC0%0/2
defined $Nice::Try::WANT and length $Nice::Try::WANT
defined $Nice::Try::WANT length $Nice::Try::WANT
MC/DC0%0/2
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__NEXT__"
defined $Nice::Try::RETVAL[0] $Nice::Try::RETVAL[0] eq "__NEXT__"
MC/DC0%0/2
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__LAST__"
defined $Nice::Try::RETVAL[0] $Nice::Try::RETVAL[0] eq "__LAST__"
MC/DC0%0/2
defined $Nice::Try::RETVAL[0] and $Nice::Try::RETVAL[0] eq "__REDO__"
defined $Nice::Try::RETVAL[0] $Nice::Try::RETVAL[0] eq "__REDO__"
MC/DC0%0/4
scalar @Nice::Try::VOID and !builtin::blessed($Nice::Try::VOID[0]) || builtin::blessed($Nice::Try::VOID[0]) && !$Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
scalar @Nice::Try::VOID not builtin::blessed($Nice::Try::VOID[0]) builtin::blessed($Nice::Try::VOID[0]) not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
MC/DC0%0/1
not defined $Nice::Try::WANTARRAY and scalar @Nice::Try::LAST_VAL
not defined $Nice::Try::WANTARRAY
Truth table0%0/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
Truth table20%2/10
A or B and C and not(D) or E and not(F)
A= defined $Nice::Try::WANTARRAYB= defined $Nice::Try::BREAKC= $Nice::Try::BREAK eq "return"D= not builtin::blessed($Nice::Try::RETVAL[0])E= builtin::blessed($Nice::Try::RETVAL[0])F= not $Nice::Try::RETVAL[0]->isa("Nice::Try::SENTINEL")
ABCDEFresult
00XXXX0
010XXX0
1XX00X0
1XX0100
01100X0
0110100
1XX1XX1
1XX0111
0111XX1
0110111
Truth table33%1/3
not(A) or B
A= not defined $Nice::Try::BREAKB= $Nice::Try::BREAK eq "return"
ABresult
1X1
011
000
Truth table33%1/3
A and B
A= defined $Nice::Try::WANTB= length $Nice::Try::WANT
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $Nice::Try::RETVAL[0]B= $Nice::Try::RETVAL[0] eq "__NEXT__"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $Nice::Try::RETVAL[0]B= $Nice::Try::RETVAL[0] eq "__LAST__"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $Nice::Try::RETVAL[0]B= $Nice::Try::RETVAL[0] eq "__REDO__"
ABresult
0X0
100
111
Truth table20%1/5
A and not(B) or C and not(D)
A= scalar @Nice::Try::VOIDB= not builtin::blessed($Nice::Try::VOID[0])C= builtin::blessed($Nice::Try::VOID[0])D= not $Nice::Try::VOID[0]->isa("Nice::Try::SENTINEL")
ABCDresult
0XXX0
100X0
10100
11XX1
10111
Truth table0%0/2
not(A)
A= not defined $Nice::Try::WANTARRAY
Aresult
00
11
249 # Used in both parse() and parse_chunk()
250 1 return( $self->parse_body );
251 }
252  
253 sub parse_body
254 1 ▶{
Subroutine parse_body: called CC=12 SCAR=36.1
Pod documented
255 1 my $self = shift( @_ );
256 # Check body
257 1 ▶ if( $self->key1 && $self->key2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->key1 and $self->key2) 0 1 1
Condition33%1/3
$self->key1 and $self->key2
!ll&&!rl&&r
100
MC/DC0%0/2
$self->key1 and $self->key2
$self->key1 $self->key2
Truth table33%1/3
A and B
A= $self->key1B= $self->key2
ABresult
0X0
100
111
258 {
259 0 ▶ return(1) if( $self->buffer->length < 8 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->buffer->length < 8 0 0 0
260  
261 0 my $challenge = $self->buffer->substr( 0, 8, '' );
262 0 $self->challenge( $challenge );
263 }
264 1 ▶ return( $self->error( "Excessive unknown data found in request body: ", $self->buffer->scalar ) ) if( $self->buffer->length );
Branch: 1 branch
BranchTrueFalseTotal
if $self->buffer->length 0 1 1
265 # return( $self->error( "Message is too long" ) ) if( $self->buffer->length );
266 1 $self->is_done(1);
267
268 1 ▶ if( !$self->{_parse_postprocessed} && $self->is_done )
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"_parse_postprocessed"} and $self->is_done) 1 0 1
Condition33%1/3
not $self->{"_parse_postprocessed"} and $self->is_done
!ll&&!rl&&r
001
MC/DC0%0/2
not $self->{"_parse_postprocessed"} and $self->is_done
not $self->{"_parse_postprocessed"} $self->is_done
Truth table33%1/3
not(A) and B
A= not $self->{"_parse_postprocessed"}B= $self->is_done
ABresult
0X0
100
111
269 {
270 1 $self->{_parse_postprocessed} = 1;
271 1 ▶ if( $self->key1 && $self->key2 )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->key1 and $self->key2) { } 0 1 1
elsif ($self->key) { } 0 1 1
Condition33%1/3
$self->key1 and $self->key2
!ll&&!rl&&r
100
MC/DC0%0/2
$self->key1 and $self->key2
$self->key1 $self->key2
Truth table33%1/3
A and B
A= $self->key1B= $self->key2
ABresult
0X0
100
111
272 {
273 # $self->version( 'draft-ietf-hybi-00' );
274 # Latest draft revision that uses key1 and key2
275 0 $self->version( 'draft-ietf-hybi-03' );
276 }
277 elsif( $self->key )
278 {
279 0 ▶ if( $self->headers->header( 'Sec-WebSocket-Version' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->headers->header('Sec-WebSocket-Version')) { } 0 0 0
280 {
281 0 $self->version( $self->headers->header( 'Sec-WebSocket-Version' )->scalar );
282 }
283 # Since there is no Sec-WebSocket-Version in request, maybe we should set
284 # the version to draft protocol revision 3 or earlier when there was no
285 # Sec-WebSocket-Version header?
286 else
287 {
288 # $self->version( 'draft-ietf-hybi-10' );
289 0 $self->version( WEBSOCKET_DRAFT_VERSION_DEFAULT );
290 }
291 }
292 else
293 {
294 1 $self->version( 'draft-hixie-75' );
295 }
296  
297 1 ▶ if( !$self->_parse_postprocess )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_parse_postprocess) 1 0 1
298 {
299 1 return( $self->error( 'Not a valid request: ', $self->error ) );
300 }
301 }
302 0 return( $self );
303 }
304  
305 1 ▶sub upgrade { return( shift->headers->header( 'Upgrade', @_ ) ); }
Subroutine upgrade: called CC=1 SCAR=0.0
Pod documented
306  
307 sub _generate_keys
308 0 ▶{
Subroutine _generate_keys: not called CC=4 SCAR=30.0
309 0 my $self = shift( @_ );
310  
311 0 ▶ unless( $self->key1 )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->key1) 0 0 0
312 {
313 0 my( $number, $key ) = $self->_generate_key;
314 0 $self->number1( $number );
315 0 $self->key1( $key );
316 }
317  
318 0 ▶ unless( $self->key2 )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->key2) 0 0 0
319 {
320 0 my( $number, $key ) = $self->_generate_key;
321 0 $self->number2( $number );
322 0 $self->key2( $key );
323 }
324 0 ▶ $self->challenge( $self->_generate_challenge ) unless( $self->challenge );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->challenge 0 0 0
325 0 return( $self );
326 }
327  
328 sub _generate_key
329 0 ▶{
Subroutine _generate_key: not called CC=4 SCAR=30.0
330 0 my $self = shift( @_ );
331  
332 # A random integer from 1 to 12 inclusive
333 0 my $spaces = int( rand(12) ) + 1;
334  
335 # The largest integer not greater than 4,294,967,295 divided by spaces
336 0 my $max = int( 4_294_967_295 / $spaces );
337  
338 # A random integer from 0 to $max inclusive
339 0 my $number = int( rand( $max + 1 ) );
340  
341 # The result of multiplying $number and $spaces together
342 0 my $product = $number * $spaces;
343  
344 # A string consisting of $product, expressed in base ten
345 0 my $key = "$product";
346  
347 # Insert between one and twelve random characters from the ranges U+0021
348 # to U+002F and U+003A to U+007E into $key at random positions.
349 0 my $random_characters = int( rand(12) ) + 1;
350  
351 0 for( 1 .. $random_characters )
352 {
353 # From 0 to the last position
354 0 my $random_position = int( rand( length( $key ) + 1 ) );
355  
356 # Random character
357 0 ▶ my $random_character = chr(
Branch: 1 branch
BranchTrueFalseTotal
int rand 2 ? : 0 0 0
358 int( rand(2) )
359 ? int( rand( 0x2f - 0x21 + 1 ) ) + 0x21
360 : int( rand( 0x7e - 0x3a + 1 ) ) + 0x3a
361 );
362  
363 # Insert random character at random position
364 0 substr( $key, $random_position, 0, $random_character );
365 }
366  
367 # Insert $spaces U+0020 SPACE characters into $key at random positions
368 # other than the start or end of the string.
369 0 for( 1 .. $spaces )
370 {
371 # From 1 to the last-1 position
372 0 my $random_position = int( rand( length( $key ) - 1 ) ) + 1;
373  
374 # Insert
375 0 substr( $key, $random_position, 0, ' ' );
376 }
377 0 return( $number, $key );
378 }
379  
380 sub _generate_challenge
381 0 ▶{
Subroutine _generate_challenge: not called CC=2 SCAR=17.9
382 0 my $self = shift( @_ );
383 # A string consisting of eight random bytes (or equivalently, a random 64
384 # bit integer encoded in big-endian order).
385 0 my $challenge = '';
386  
387 0 $challenge .= chr( int( rand(256) ) ) for( 1 .. 8 );
388 0 return( $challenge );
389 }
390  
391 sub _key
392 5 ▶{
Subroutine _key: called CC=4 SCAR=18.6
393 5 my $self = shift( @_ );
394 5 ▶ my $name = shift( @_ ) || return( $self->error( "No Sec-WebSocket header name was provided" ) );
Condition50%1/2
shift @_ || (return $self->error('No Sec-WebSocket header name was provided'))
l!l
50
MC/DC0%0/1
shift @_ || (return $self->error('No Sec-WebSocket header name was provided'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
395 5 my $hname = 'Sec-WebSocket-' . ucfirst( lc( $name ) );
396 5 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 5 5
397 {
398 0 my $val = shift( @_ );
399 0 ▶ if( !defined( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val) { } 0 0 0
400 {
401 0 $self->headers->remove_header( $hname );
402 }
403 else
404 {
405 0 $self->headers->header( $hname => $val );
406 }
407 }
408 5 return( $self->headers->header( $hname ) );
409 }
410  
411 sub _number
412 0 ▶{
Subroutine _number: not called CC=4 SCAR=30.0
413 0 my $self = shift( @_ );
414 0 my( $name, $key, $value ) = @_;
415  
416 0 ▶ if( defined( $value ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
417 {
418 0 $self->{ $name} = $value;
419 0 return( $self );
420 }
421 0 ▶ return( $self->{ $name } ) if( defined( $self->{ $name } ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{$name} 0 0 0
422 0 ▶ return( $self->{ $name } ||= $self->_extract_number( $self->$key ) );
Condition0%0/3
$self->{$name} ||= $self->_extract_number($self->$key)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{$name} ||= $self->_extract_number($self->$key)
$self->{$name} $self->_extract_number($self->$key)
Truth table0%0/3
A ||= B
A= $self->{$name}B= $self->_extract_number($self->$key)
ABresult
1X1
011
000
423 }
424  
425 # Called from parse_chunk()
426 sub _parse_body_chunk
427 0 ▶{
Subroutine _parse_body_chunk: not called CC=1 SCAR=6.9
428 0 my $self = shift( @_ );
429 0 my $req = $self->SUPER::_parse_body_chunk;
430 0 $self->method( $req->method );
431 0 $self->uri( $req->uri );
432 0 $self->protocol( $req->protocol );
433 0 $self->headers( $req->headers );
434 # The rest is the body
435 0 $self->buffer( $req->content );
436 # Used in both parse() and parse_chunk()
437 0 return( $self->parse_body );
438 }
439  
440 sub _parse_postprocess
441 1 ▶{
Subroutine _parse_postprocess: called CC=18 SCAR=48.5
442 1 my $self = shift( @_ );
443 1 ▶ return( $self->error( "No upgrade header or its value is not \"WebSocket\"." ) ) unless( $self->upgrade->lc eq 'websocket' );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->upgrade->lc eq "websocket" 0 1 1
444  
445 1 my $connection = $self->connection;
446 1 ▶ return( $self->error( "No \"Connection\" header" ) ) unless( $connection->length );
Branch: 1 branch
BranchTrueFalseTotal
unless $connection->length 0 1 1
447
448 1 my $connections = $connection->split( qr/[[:blank:]\h]*\,[[:blank:]\h]*/ );
449 1 ▶ return( $self->error( "Connection header has no \"Upgrade\" value." ) ) unless( $connections->grep(sub{ lc( $_ ) eq 'upgrade' })->length );
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
unless $connections->grep(sub { lc $_ eq "upgrade"; } )->length 0 1 1
450 1 ▶ my $origin = $self->headers->header( 'Sec-WebSocket-Origin' ) || $self->headers->header( 'Origin' );
Condition33%1/3
$self->headers->header('Sec-WebSocket-Origin') || $self->headers->header('Origin')
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->headers->header('Sec-WebSocket-Origin') || $self->headers->header('Origin')
$self->headers->header('Sec-WebSocket-Origin') $self->headers->header('Origin')
Truth table33%1/3
A || B
A= $self->headers->header('Sec-WebSocket-Origin')B= $self->headers->header('Origin')
ABresult
1X1
011
000
451 1 $self->origin( $origin );
452 1 ▶ if( $origin->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($origin->length) 1 0 1
453 {
454 1 ▶ $self->secure(1) if( $origin->match( qr/^https:/i ) );
Branch: 1 branch
BranchTrueFalseTotal
if $origin->match(qr/^https:/i) 0 1 1
455 }
456 1 my $host = $self->host;
457 1 ▶ return( $self->error( "No \"Host\" header value found." ) ) unless( $host->length );
Branch: 1 branch
BranchTrueFalseTotal
unless $host->length 1 0 1
458 # $self->host($host);
459  
460 0 ▶ my $subprotocol = $self->headers->header( 'Sec-WebSocket-Protocol' ) ||
Condition0%0/3
$self->headers->header('Sec-WebSocket-Protocol') || $self->headers->header('WebSocket-Protocol')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->headers->header('Sec-WebSocket-Protocol') || $self->headers->header('WebSocket-Protocol')
$self->headers->header('Sec-WebSocket-Protocol') $self->headers->header('WebSocket-Protocol')
Truth table0%0/3
A || B
A= $self->headers->header('Sec-WebSocket-Protocol')B= $self->headers->header('WebSocket-Protocol')
ABresult
1X1
011
000
461 $self->headers->header( 'WebSocket-Protocol' );
462 0 my $v = $self->version;
463 # rfc6455, section 4.1: multiple values are comma separated
464 # Careful. If version is < HyBi 04 subprotocol are separated by a space, not by a comma
465 0 ▶ if( $subprotocol->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($subprotocol->length) 0 0 0
466 {
467 0 ▶ if( $subprotocol->index( ',' ) != -1 )
Branch: 1 branch
BranchTrueFalseTotal
if ($subprotocol->index(',') != -1) { } 0 0 0
468 {
469 0 $self->subprotocol( $subprotocol->split( qr/[[:blank:]\h]*\,[[:blank:]\h]*/ ) );
470 }
471 # version older than draft hybi revision 4
472 else
473 {
474 0 $self->subprotocol( $subprotocol->split( qr/[[:blank:]\h]+/ ) );
475 0 ▶ if( $v->type eq 'hybi' && $v->revision > 3 )
Branch: 1 branch
BranchTrueFalseTotal
if ($v->type eq "hybi" and $v->revision > 3) 0 0 0
Condition0%0/3
$v->type eq "hybi" and $v->revision > 3
!ll&&!rl&&r
000
MC/DC0%0/2
$v->type eq "hybi" and $v->revision > 3
$v->type eq "hybi" $v->revision > 3
Truth table0%0/3
A and B
A= $v->type eq "hybi"B= $v->revision > 3
ABresult
0X0
100
111
476 {
477 0 ▶ $v = $self->version(2) || return( $self->pass_error );
Condition0%0/2
$self->version(2) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->version(2) || (return $self->pass_error)
$self->version(2)
Truth table0%0/2
A
A= $self->version(2)
Aresult
11
00
478 }
479 }
480 }
481
482 0 ▶ if( $v->type eq 'hybi' && $v->revision >= 4 )
Branch: 1 branch
BranchTrueFalseTotal
if ($v->type eq "hybi" and $v->revision >= 4) 0 0 0
Condition0%0/3
$v->type eq "hybi" and $v->revision >= 4
!ll&&!rl&&r
000
MC/DC0%0/2
$v->type eq "hybi" and $v->revision >= 4
$v->type eq "hybi" $v->revision >= 4
Truth table0%0/3
A and B
A= $v->type eq "hybi"B= $v->revision >= 4
ABresult
0X0
100
111
483 {
484 0 my $extensions = $self->headers->header( 'Sec-WebSocket-Extensions' );
485 0 ▶ if( $extensions->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($extensions->length) 0 0 0
486 {
487 # Returns a Module::Generic::Array of WebSocket::Extension objects
488 0 ▶ my $ref = WebSocket::Extension->new_from_multi( $extensions->scalar ) ||
Condition0%0/2
'WebSocket::Extension'->new_from_multi($extensions->scalar) || (return $self->pass_error('WebSocket::Extension'->error))
l!l
00
MC/DC0%0/1
'WebSocket::Extension'->new_from_multi($extensions->scalar) || (return $self->pass_error('WebSocket::Extension'->error))
'WebSocket::Extension'->new_from_multi($extensions->scalar)
Truth table0%0/2
A
A= 'WebSocket::Extension'->new_from_multi($extensions->scalar)
Aresult
11
00
489 return( $self->pass_error( WebSocket::Extension->error ) );
490 0 $self->extensions( $ref );
491 }
492 }
493
494 0 $self->cookies( $self->headers->header( 'Cookie' ) );
495 0 return( $self );
496 }
497  
498 5 1;
499 # NOTE: POD
500 __END__
« WebSocket/Response.pm ↑ Summary WebSocket/HeaderValue.pm »