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.
This commit is contained in:
Pierre Ossman 2017-02-08 16:06:14 +01:00
parent c7bde00a4e
commit df317822d6
1 changed files with 10 additions and 0 deletions

View File

@ -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