summaryrefslogtreecommitdiff
path: root/websockify/websocket.py
diff options
context:
space:
mode:
Diffstat (limited to 'websockify/websocket.py')
-rw-r--r--websockify/websocket.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/websockify/websocket.py b/websockify/websocket.py
index 1cbf583..7fa9651 100644
--- a/websockify/websocket.py
+++ b/websockify/websocket.py
@@ -474,9 +474,13 @@ class WebSocketRequestHandler(SimpleHTTPRequestHandler):
"""Upgrade a connection to Websocket, if requested. If this succeeds,
new_websocket_client() will be called. Otherwise, False is returned.
"""
+
if (self.headers.get('upgrade') and
self.headers.get('upgrade').lower() == 'websocket'):
+ # ensure connection is authorized, and determine the target
+ self.validate_connection()
+
if not self.do_websocket_handshake():
return False
@@ -549,6 +553,10 @@ class WebSocketRequestHandler(SimpleHTTPRequestHandler):
""" Do something with a WebSockets client connection. """
raise Exception("WebSocketRequestHandler.new_websocket_client() must be overloaded")
+ def validate_connection(self):
+ """ Ensure that the connection is a valid connection, and set the target. """
+ pass
+
def do_HEAD(self):
if self.only_upgrade:
self.send_error(405, "Method Not Allowed")
@@ -789,7 +797,7 @@ class WebSocketServer(object):
"""
ready = select.select([sock], [], [], 3)[0]
-
+
if not ready:
raise self.EClose("ignoring socket not ready")
# Peek, but do not read the data so that we have a opportunity
@@ -903,7 +911,7 @@ class WebSocketServer(object):
def top_new_client(self, startsock, address):
""" Do something with a WebSockets client connection. """
- # handler process
+ # handler process
client = None
try:
try: