From 6ba517dfd0d85efb30250dcb2bc7e59af1859ffa Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 7 Feb 2021 02:01:37 +1300 Subject: 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. --- lib/POE/Component/Client/WebSocket.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 => { -- cgit v1.2.3