diff options
author | Solly Ross <sross@redhat.com> | 2015-08-25 16:44:24 -0400 |
---|---|---|
committer | Solly Ross <sross@redhat.com> | 2015-08-25 17:52:20 -0400 |
commit | 1e2b5c2256d31e34083935f8adb2c8433cd40f7f (patch) | |
tree | 6e445718408ab9bfd5290aafed21f288051586d3 /websockify/websocket.py | |
parent | 6c1543c05b79ae8bef2d2f7d703002a432776baf (diff) | |
download | websockify-feature/http-auth-plugins.tar.gz |
Rework Auth Plugins to Support HTTP Authfeature/http-auth-plugins
This commit reworks auth plugins slightly to enable
support for HTTP authentication. By raising an
AuthenticationError, auth plugins can now return
HTTP responses to the upgrade request (such as 401).
Related to kanaka/noVNC#522
Diffstat (limited to 'websockify/websocket.py')
-rw-r--r-- | websockify/websocket.py | 12 |
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: |