diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2021-02-07 02:01:37 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2021-02-07 02:05:50 +1300 |
commit | 6ba517dfd0d85efb30250dcb2bc7e59af1859ffa (patch) | |
tree | fcf58e301aa06add756dfa3642384660ade3d221 /lib | |
parent | Use CRLF line endings in GET request (diff) | |
download | POE-Component-Client-WebSocket-6ba517dfd0d85efb30250dcb2bc7e59af1859ffa.tar.gz POE-Component-Client-WebSocket-6ba517dfd0d85efb30250dcb2bc7e59af1859ffa.zip |
Switch protocol for Origin header based on TLS
If the websocket server is running over TLS, it's likely that the origin
server matching it should be specified as HTTPS.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/POE/Component/Client/WebSocket.pm | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/POE/Component/Client/WebSocket.pm b/lib/POE/Component/Client/WebSocket.pm index e428672..8f5ff3c 100644 --- a/lib/POE/Component/Client/WebSocket.pm +++ b/lib/POE/Component/Client/WebSocket.pm @@ -132,6 +132,9 @@ sub new { my $key = ""; for (1..16) { $key .= int(rand(9)) } + my $origin = (uc $scheme eq 'WSS' ? 'https' : 'http') + . "://$host"; + $self->{session} = POE::Session->create( package_states => [ $self => { @@ -167,7 +170,7 @@ sub new { port => $port, }, req => { - 'origin' => 'http://'.$host, + 'origin' => $origin, 'sec-websocket-key' => encode_base64($key), }, _state => { |