Skip to content
This repository has been archived by the owner on Jan 13, 2020. It is now read-only.

WebSocket headers are case insensitive #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion openwebrx.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,9 @@ def do_GET(self):
cma("do_GET /ws/")
client_i=get_client_by_id(self.path[4:], False)
myclient=clients[client_i]
except rxws.WebSocketException: ws_success=False
except rxws.WebSocketException as e:
access_log("Error connecting WebSocket: {}".format(e))
ws_success=False
except ClientNotFoundException: ws_success=False
finally:
if clients_mutex.locked(): cmr()
Expand Down
11 changes: 8 additions & 3 deletions rxws.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
import code

class WebSocketException(Exception):
pass
def __init__(self, message):
self.msg_ = message
def __str__(self):
return self.msg_

def handshake(myself):
my_client_id=myself.path[4:]
Expand All @@ -38,8 +41,10 @@ def handshake(myself):
#print h_key_exists("upgrade")
#print h_value("upgrade")
#print h_key_exists("sec-websocket-key")
if (not h_key_exists("upgrade")) or not (h_value("upgrade")=="websocket") or (not h_key_exists("sec-websocket-key")):
raise WebSocketException
# NB: WebSocket headers are case insensitive (RFC 6455, p19)
if (not h_key_exists("upgrade")) or not (h_value("upgrade").lower()=="websocket") or (not h_key_exists("sec-websocket-key")):
raise WebSocketException("Bad WebSocket handshake: upgrade={}, sec-websocket-key={}"
.format(h_value("upgrade"), h_value("sec-websocket-key")))
ws_key=h_value("sec-websocket-key")
ws_key_toreturn=base64.b64encode(sha.new(ws_key+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest())
#A sample list of keys we get: [('origin', 'http://localhost:8073'), ('upgrade', 'websocket'), ('sec-websocket-extensions', 'x-webkit-deflate-frame'), ('sec-websocket-version', '13'), ('host', 'localhost:8073'), ('sec-websocket-key', 't9J1rgy4fc9fg2Hshhnkmg=='), ('connection', 'Upgrade'), ('pragma', 'no-cache'), ('cache-control', 'no-cache')]
Expand Down