| 1 | package Protocol::WebSocket::Request; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 15 | ▶ | use base 'Protocol::WebSocket::Message'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 15 | require Carp; | |||||||||||||||||||||||||||||||||||||||||
| 9 | 15 | ▶ | use MIME::Base64 (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 15 | ▶ | use Protocol::WebSocket::Cookie::Request; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 68 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 68 | my $self = shift->SUPER::new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 15 | 68 | my (%params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 68 | ▶ | $self->{headers} = $params{headers} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$params{'headers'} || []
MC/DC100%1/1
$params{'headers'} || []
$params{'headers'}
Truth table100%2/2
A
A= $params{'headers'}
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 68 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 9 | ▶ | sub new_from_psgi { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_from_psgi: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 9 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 9 | ▶ | my $env = @_ > 1 ? {@_} : shift; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 9 | ▶ | Carp::croak('env is required') unless keys %$env; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 7 | my $version = ''; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 7 | my $cookies; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | my $fields = { | ||||||||||||||||||||||||||||||||||||||||||
| 33 | upgrade => $env->{HTTP_UPGRADE}, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | connection => $env->{HTTP_CONNECTION}, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | host => $env->{HTTP_HOST}, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 7 | ▶ | if ($env->{HTTP_WEBSOCKET_PROTOCOL}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | $fields->{'websocket-protocol'} = | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | $env->{HTTP_WEBSOCKET_PROTOCOL}; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | elsif ($env->{HTTP_SEC_WEBSOCKET_PROTOCOL}) { | ||||||||||||||||||||||||||||||||||||||||||
| 43 | $fields->{'sec-websocket-protocol'} = | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 3 | $env->{HTTP_SEC_WEBSOCKET_PROTOCOL}; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 7 | ▶ | if (exists $env->{HTTP_SEC_WEBSOCKET_VERSION}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | $fields->{'sec-websocket-version'} = | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 4 | $env->{HTTP_SEC_WEBSOCKET_VERSION}; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 4 | ▶ | if ($env->{HTTP_SEC_WEBSOCKET_VERSION} eq '13') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | $version = 'draft-ietf-hybi-17'; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | $version = 'draft-ietf-hybi-10'; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 7 | ▶ | if ($env->{HTTP_SEC_WEBSOCKET_KEY}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | $fields->{'sec-websocket-key'} = $env->{HTTP_SEC_WEBSOCKET_KEY}; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | elsif ($env->{HTTP_SEC_WEBSOCKET_KEY1}) { | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | $version = 'draft-ietf-hybi-00'; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | $fields->{'sec-websocket-key1'} = $env->{HTTP_SEC_WEBSOCKET_KEY1}; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | $fields->{'sec-websocket-key2'} = $env->{HTTP_SEC_WEBSOCKET_KEY2}; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 7 | ▶ | if ($version eq 'draft-ietf-hybi-10') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | $fields->{'sec-websocket-origin'} = $env->{HTTP_SEC_WEBSOCKET_ORIGIN}; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 6 | $fields->{origin} = $env->{HTTP_ORIGIN}; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 7 | ▶ | if ($env->{HTTP_COOKIE}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 3 | $cookies = Protocol::WebSocket::Cookie->new->parse($env->{HTTP_COOKIE}); | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | my $self = $class->new( | ||||||||||||||||||||||||||||||||||||||||||
| 79 | version => $version, | ||||||||||||||||||||||||||||||||||||||||||
| 80 | fields => $fields, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | cookies => $cookies, | ||||||||||||||||||||||||||||||||||||||||||
| 82 | resource_name => "$env->{SCRIPT_NAME}$env->{PATH_INFO}" | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 7 | ▶ | . ($env->{QUERY_STRING} ? "?$env->{QUERY_STRING}" : "") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 7 | $self->state('body'); | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 7 | ▶ | if ( $env->{HTTP_X_FORWARDED_PROTO} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$env->{"HTTP_X_FORWARDED_PROTO"} and $env->{"HTTP_X_FORWARDED_PROTO"} eq "https"
MC/DC50%1/2
$env->{"HTTP_X_FORWARDED_PROTO"} and $env->{"HTTP_X_FORWARDED_PROTO"} eq "https"
$env->{"HTTP_X_FORWARDED_PROTO"}
$env->{"HTTP_X_FORWARDED_PROTO"} eq "https"
Truth table66%2/3
A and B
A= $env->{"HTTP_X_FORWARDED_PROTO"}B= $env->{"HTTP_X_FORWARDED_PROTO"} eq "https"
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | && $env->{HTTP_X_FORWARDED_PROTO} eq 'https') | ||||||||||||||||||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | $self->secure(1); | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 7 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 45 | ▶ | sub cookies { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cookies: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 45 | ▶ | if(@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 32 | my $cookie = Protocol::WebSocket::Cookie->new; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 32 | ▶ | return unless $_[1]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 9 | ▶ | if (my $cookies = $cookie->parse($_[1])) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 9 | $_[0]->{cookies} = $cookies; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 13 | return $_[0]->{cookies}; | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 101 | ▶ | sub resource_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resource_name: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 101 | ▶ | @_ > 1 ? $_[0]->{resource_name} = $_[1] : $_[0]->{resource_name} || '/'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$_[0]{"resource_name"} or "/"
MC/DC0%0/1
$_[0]{"resource_name"} or "/"
$_[0]{"resource_name"}
Truth table50%1/2
A
A= $_[0]{"resource_name"}
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 64 | ▶ | sub upgrade { shift->field('Upgrade') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
upgrade: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 34 | ▶ | sub connection { shift->field('Connection') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connection: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 20 | ▶ | sub number1 { shift->_number('number1', 'key1', @_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
number1: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 20 | ▶ | sub number2 { shift->_number('number2', 'key2', @_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
number2: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 45 | ▶ | sub key { shift->_key('key' => @_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
key: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 92 | ▶ | sub key1 { shift->_key('key1' => @_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
key1: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 45 | ▶ | sub key2 { shift->_key('key2' => @_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
key2: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 20 | ▶ | sub to_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=21 SCAR=30.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 20 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 20 | ▶ | my $version = $self->version || 'draft-ietf-hybi-17'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->version || 'draft-ietf-hybi-17'
MC/DC100%1/1
$self->version || 'draft-ietf-hybi-17'
$self->version
Truth table100%2/2
A
A= $self->version
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 20 | my $string = ''; | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 20 | ▶ | Carp::croak(qq/resource_name is required/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | unless defined $self->resource_name; | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 20 | $string .= "GET " . $self->resource_name . " HTTP/1.1\x0d\x0a"; | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 20 | $string .= "Upgrade: WebSocket\x0d\x0a"; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 20 | $string .= "Connection: Upgrade\x0d\x0a"; | |||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 20 | ▶ | Carp::croak(qq/Host is required/) unless defined $self->host; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 20 | $string .= "Host: " . $self->host . "\x0d\x0a"; | |||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 20 | ▶ | if (ref $self->{cookies} eq 'Protocol::WebSocket::Cookie') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 8 | my $cookie_string = $self->{cookies}->to_string; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 8 | ▶ | $string .= 'Cookie: ' . $cookie_string . "\x0d\x0a" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | if $cookie_string; | ||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 20 | ▶ | my $origin = $self->origin ? $self->origin : 'http://' . $self->host; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 20 | ▶ | $origin =~ s{^http:}{https:} if $self->secure; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 20 | ▶ | $string .= ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | $version eq 'draft-ietf-hybi-10' | ||||||||||||||||||||||||||||||||||||||||||
| 150 | ? "Sec-WebSocket-Origin" | ||||||||||||||||||||||||||||||||||||||||||
| 151 | : "Origin" | ||||||||||||||||||||||||||||||||||||||||||
| 152 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 153 | . ': ' | ||||||||||||||||||||||||||||||||||||||||||
| 154 | . $origin | ||||||||||||||||||||||||||||||||||||||||||
| 155 | . "\x0d\x0a"; | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 20 | ▶ | if ($version eq 'draft-ietf-hybi-10' || $version eq 'draft-ietf-hybi-17') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$version eq "draft-ietf-hybi-10" or $version eq "draft-ietf-hybi-17"
MC/DC100%2/2
$version eq "draft-ietf-hybi-10" or $version eq "draft-ietf-hybi-17"
$version eq "draft-ietf-hybi-10"
$version eq "draft-ietf-hybi-17"
Truth table100%3/3
A or B
A= $version eq "draft-ietf-hybi-10"B= $version eq "draft-ietf-hybi-17"
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 9 | my $key = $self->key; | |||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 9 | ▶ | if (!$key) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 3 | $key = ''; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 3 | $key .= chr(int(rand(256))) for 1 .. 16; | |||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 3 | $key = MIME::Base64::encode_base64($key); | |||||||||||||||||||||||||||||||||||||||||
| 165 | 3 | $key =~ s{\s+}{}g; | |||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | $string | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 9 | ▶ | .= 'Sec-WebSocket-Protocol: ' . $self->subprotocol . "\x0d\x0a" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | if defined $self->subprotocol; | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 9 | $string .= 'Sec-WebSocket-Key: ' . $key . "\x0d\x0a"; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 9 | ▶ | $string | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | .= 'Sec-WebSocket-Version: ' | ||||||||||||||||||||||||||||||||||||||||||
| 175 | . ($version eq 'draft-ietf-hybi-17' ? 13 : 8) | ||||||||||||||||||||||||||||||||||||||||||
| 176 | . "\x0d\x0a"; | ||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | elsif ($version eq 'draft-ietf-hybi-00') { | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 7 | $self->_generate_keys; | |||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 7 | ▶ | $string | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | .= 'Sec-WebSocket-Protocol: ' . $self->subprotocol . "\x0d\x0a" | ||||||||||||||||||||||||||||||||||||||||||
| 183 | if defined $self->subprotocol; | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 7 | $string .= 'Sec-WebSocket-Key1: ' . $self->key1 . "\x0d\x0a"; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 7 | $string .= 'Sec-WebSocket-Key2: ' . $self->key2 . "\x0d\x0a"; | |||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 7 | $string .= 'Content-Length: ' . length($self->challenge) . "\x0d\x0a"; | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | elsif ($version eq 'draft-hixie-75') { | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 4 | ▶ | $string .= 'WebSocket-Protocol: ' . $self->subprotocol . "\x0d\x0a" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | if defined $self->subprotocol; | ||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | Carp::croak('Version ' . $self->version . ' is not supported'); | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 20 | my @headers = @{$self->{headers}}; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 20 | ▶ | while (my ($key, $value) = splice @headers, 0, 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 2 | $key =~ s{[\x0d\x0a]}{}gsm; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 2 | $value =~ s{[\x0d\x0a]}{}gsm; | |||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | $string .= "$key: $value\x0d\x0a"; | |||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 20 | $string .= "\x0d\x0a"; | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 20 | ▶ | $string .= $self->challenge if $version eq 'draft-ietf-hybi-00'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 20 | return $string; | |||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 200 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 200 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 200 | my $retval = $self->SUPER::parse($_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 200 | ▶ | if (!$self->{finalized} && ($self->is_body || $self->is_done)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not $self->{"finalized"} and $self->is_body || $self->is_done
$self->is_body or $self->is_done
MC/DC100%3/3
not $self->{"finalized"} and $self->is_body || $self->is_done
not $self->{"finalized"}
$self->is_body
$self->is_done
Truth table100%4/4
not(A) and B or C
A= not $self->{"finalized"}B= $self->is_bodyC= $self->is_done
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 30 | $self->{finalized} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 30 | ▶ | if ($self->key1 && $self->key2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$self->key1 and $self->key2
MC/DC50%1/2
$self->key1 and $self->key2
$self->key1
$self->key2
Truth table66%2/3
A and B
A= $self->key1B= $self->key2
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 7 | $self->version('draft-ietf-hybi-00'); | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | elsif ($self->key) { | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 11 | ▶ | if ($self->field('sec-websocket-version') eq '13') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 7 | $self->version('draft-ietf-hybi-17'); | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 4 | $self->version('draft-ietf-hybi-10'); | |||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 12 | $self->version('draft-hixie-75'); | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 30 | ▶ | if (!$self->_finalize) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 2 | $self->error('Not a valid request'); | |||||||||||||||||||||||||||||||||||||||||
| 237 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 198 | return $retval; | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 27 | ▶ | sub _parse_first_line { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_first_line: called CC=6 SCAR=18.9
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 27 | my ($self, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 27 | my ($req, $resource_name, $http) = split ' ' => $line; | |||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 27 | ▶ | unless ($req && $resource_name && $http) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$req and $resource_name and $http
$req and $resource_name
MC/DC66%2/3
$req and $resource_name and $http
$req
$resource_name
$http
Truth table75%3/4
A and B and C
A= $reqB= $resource_nameC= $http
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 2 | $self->error('Wrong request line'); | |||||||||||||||||||||||||||||||||||||||||
| 251 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 25 | ▶ | unless ($req eq 'GET' && $http eq 'HTTP/1.1') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$req eq "GET" and $http eq "HTTP/1.1"
MC/DC0%0/2
$req eq "GET" and $http eq "HTTP/1.1"
$req eq "GET"
$http eq "HTTP/1.1"
Truth table33%1/3
A and B
A= $req eq "GET"B= $http eq "HTTP/1.1"
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | $self->error('Wrong method or http version'); | |||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 25 | $self->resource_name($resource_name); | |||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 25 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 32 | ▶ | sub _parse_body { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_body: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 32 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 32 | ▶ | if ($self->key1 && $self->key2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->key1 and $self->key2
MC/DC50%1/2
$self->key1 and $self->key2
$self->key1
$self->key2
Truth table66%2/3
A and B
A= $self->key1B= $self->key2
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 8 | ▶ | return 1 if length $self->{buffer} < 8; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 6 | my $challenge = substr $self->{buffer}, 0, 8, ''; | |||||||||||||||||||||||||||||||||||||||||
| 271 | 6 | $self->challenge($challenge); | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 30 | ▶ | if (length $self->{buffer}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 1 | $self->error('Leftovers'); | |||||||||||||||||||||||||||||||||||||||||
| 276 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 29 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 40 | ▶ | sub _number { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_number: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 40 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 40 | my ($name, $key, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 40 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 2 | $self->{$name} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 38 | ▶ | return $self->{$name} if defined $self->{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 18 | ▶ | return $self->{$name} ||= $self->_extract_number($self->$key); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{$name} ||= $self->_extract_number($self->$key)
MC/DC0%0/2
$self->{$name} ||= $self->_extract_number($self->$key)
$self->{$name}
$self->_extract_number($self->$key)
Truth table33%1/3
A ||= B
A= $self->{$name}B= $self->_extract_number($self->$key)
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 182 | ▶ | sub _key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_key: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 182 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 298 | 182 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 299 | 182 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 182 | ▶ | unless (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 170 | ▶ | if (my $value = delete $self->{$name}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 9 | $self->field("Sec-WebSocket-" . ucfirst($name) => $value); | |||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 170 | return $self->field("Sec-WebSocket-" . ucfirst($name)); | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 12 | $self->field("Sec-WebSocket-" . ucfirst($name) => $value); | |||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 12 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 7 | ▶ | sub _generate_keys { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_keys: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 7 | ▶ | unless ($self->key1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | my ($number, $key) = $self->_generate_key; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 1 | $self->number1($number); | |||||||||||||||||||||||||||||||||||||||||
| 320 | 1 | $self->key1($key); | |||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 7 | ▶ | unless ($self->key2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 1 | my ($number, $key) = $self->_generate_key; | |||||||||||||||||||||||||||||||||||||||||
| 325 | 1 | $self->number2($number); | |||||||||||||||||||||||||||||||||||||||||
| 326 | 1 | $self->key2($key); | |||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 7 | ▶ | $self->challenge($self->_generate_challenge) unless $self->challenge; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 7 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 2 | ▶ | sub _generate_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_key: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | # A random integer from 1 to 12 inclusive | ||||||||||||||||||||||||||||||||||||||||||
| 338 | 2 | my $spaces = int(rand(12)) + 1; | |||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | # The largest integer not greater than 4,294,967,295 divided by spaces | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 2 | my $max = int(4_294_967_295 / $spaces); | |||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | # A random integer from 0 to $max inclusive | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 2 | my $number = int(rand($max + 1)); | |||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | # The result of multiplying $number and $spaces together | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 2 | my $product = $number * $spaces; | |||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | # A string consisting of $product, expressed in base ten | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 2 | my $key = "$product"; | |||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | # Insert between one and twelve random characters from the ranges U+0021 | ||||||||||||||||||||||||||||||||||||||||||
| 353 | # to U+002F and U+003A to U+007E into $key at random positions. | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 2 | my $random_characters = int(rand(12)) + 1; | |||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 2 | for (1 .. $random_characters) { | |||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | # From 0 to the last position | ||||||||||||||||||||||||||||||||||||||||||
| 359 | 19 | my $random_position = int(rand(length($key) + 1)); | |||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | # Random character | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 19 | ▶ | my $random_character = chr( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | int(rand(2)) | ||||||||||||||||||||||||||||||||||||||||||
| 364 | ? int(rand(0x2f - 0x21 + 1)) + 0x21 | ||||||||||||||||||||||||||||||||||||||||||
| 365 | : int(rand(0x7e - 0x3a + 1)) + 0x3a | ||||||||||||||||||||||||||||||||||||||||||
| 366 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | # Insert random character at random position | ||||||||||||||||||||||||||||||||||||||||||
| 369 | 19 | substr $key, $random_position, 0, $random_character; | |||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | # Insert $spaces U+0020 SPACE characters into $key at random positions | ||||||||||||||||||||||||||||||||||||||||||
| 373 | # other than the start or end of the string. | ||||||||||||||||||||||||||||||||||||||||||
| 374 | 2 | for (1 .. $spaces) { | |||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | # From 1 to the last-1 position | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 17 | my $random_position = int(rand(length($key) - 1)) + 1; | |||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | # Insert | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 17 | substr $key, $random_position, 0, ' '; | |||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | 2 | return ($number, $key); | |||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 1 | ▶ | sub _generate_challenge { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_challenge: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | # A string consisting of eight random bytes (or equivalently, a random 64 | ||||||||||||||||||||||||||||||||||||||||||
| 390 | # bit integer encoded in big-endian order). | ||||||||||||||||||||||||||||||||||||||||||
| 391 | 1 | my $challenge = ''; | |||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 1 | $challenge .= chr(int(rand(256))) for 1 .. 8; | |||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 1 | return $challenge; | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 30 | ▶ | sub _finalize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_finalize: called CC=11 SCAR=24.1
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | 30 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 30 | ▶ | return unless $self->upgrade && lc $self->upgrade eq 'websocket'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->upgrade and lc $self->upgrade eq "websocket"
MC/DC0%0/2
$self->upgrade and lc $self->upgrade eq "websocket"
$self->upgrade
lc $self->upgrade eq "websocket"
Truth table33%1/3
A and B
A= $self->upgradeB= lc $self->upgrade eq "websocket"
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | 30 | my $connection = $self->connection; | |||||||||||||||||||||||||||||||||||||||||
| 404 | 30 | ▶ | return unless $connection; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | 30 | my @connections = split /\s*,\s*/, $connection; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 30 | ▶ | return unless grep { lc $_ eq 'upgrade' } @connections; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | 29 | ▶ | my $origin = $self->field('Sec-WebSocket-Origin') || $self->field('Origin'); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->field('Sec-WebSocket-Origin') || $self->field('Origin')
MC/DC100%2/2
$self->field('Sec-WebSocket-Origin') || $self->field('Origin')
$self->field('Sec-WebSocket-Origin')
$self->field('Origin')
Truth table100%3/3
A || B
A= $self->field('Sec-WebSocket-Origin')B= $self->field('Origin')
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | #return unless $origin; | ||||||||||||||||||||||||||||||||||||||||||
| 411 | 29 | $self->origin($origin); | |||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 29 | ▶ | if (defined $self->origin) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 27 | ▶ | $self->secure(1) if $self->origin =~ m{^https:}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | 29 | my $host = $self->field('Host'); | |||||||||||||||||||||||||||||||||||||||||
| 418 | 29 | ▶ | return unless $host; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | 28 | $self->host($host); | |||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 28 | ▶ | my $subprotocol = $self->field('Sec-WebSocket-Protocol') | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->field('Sec-WebSocket-Protocol') || $self->field('WebSocket-Protocol')
MC/DC100%2/2
$self->field('Sec-WebSocket-Protocol') || $self->field('WebSocket-Protocol')
$self->field('Sec-WebSocket-Protocol')
$self->field('WebSocket-Protocol')
Truth table100%3/3
A || B
A= $self->field('Sec-WebSocket-Protocol')B= $self->field('WebSocket-Protocol')
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | || $self->field('WebSocket-Protocol'); | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 28 | ▶ | $self->subprotocol($subprotocol) if $subprotocol; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | 28 | $self->cookies($self->field('Cookie')); | |||||||||||||||||||||||||||||||||||||||||
| 426 | 28 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | ▶ | sub _build_cookie { Protocol::WebSocket::Cookie::Request->new } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_cookie: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | 15 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 432 | __END__ | ||||||||||||||||||||||||||||||||||||||||||