From df317822d6af7dc954913e5a9947d36b33bfbf33 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Wed, 8 Feb 2017 16:06:14 +0100 Subject: [PATCH] Be backwards compatible with older websockify clients They will specify a sub-protocol, and the specification requires us to choose one of the specified protocols. --- websockify/websockifyserver.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/websockify/websockifyserver.py b/websockify/websockifyserver.py index fc88261..01004cc 100644 --- a/websockify/websockifyserver.py +++ b/websockify/websockifyserver.py @@ -41,6 +41,14 @@ if sys.platform == 'win32': from websockify.websocket import WebSocket, WebSocketWantReadError, WebSocketWantWriteError from websockify.websocketserver import WebSocketRequestHandler +class CompatibleWebSocket(WebSocket): + def select_subprotocol(self, protocols): + # Handle old websockify clients that still specifiy a sub-protocol + if 'binary' in protocols: + return 'binary' + else: + return '' + # HTTP handler with WebSocket upgrade support class WebSockifyRequestHandler(WebSocketRequestHandler, SimpleHTTPRequestHandler): """ @@ -61,6 +69,8 @@ class WebSockifyRequestHandler(WebSocketRequestHandler, SimpleHTTPRequestHandler protocol_version = "HTTP/1.1" + SocketClass = CompatibleWebSocket + # An exception while the WebSocket client was connected class CClose(Exception): pass