From 30942f12d3909fd9bb4302a9d0b0567c7bcd216a Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 19 Jan 2017 14:53:15 +0100 Subject: [PATCH] Close connection after Websocket handshake Otherwise we might misinterpret trailing binary data as a second HTTP request. This happens when we return from the handler with data still queued up in the socket. --- websockify/websocket.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/websockify/websocket.py b/websockify/websocket.py index b146eeb..ebb3a53 100644 --- a/websockify/websocket.py +++ b/websockify/websocket.py @@ -467,6 +467,10 @@ class WebSocketRequestHandler(SimpleHTTPRequestHandler): else: self.send_header("Sec-WebSocket-Protocol", "binary") self.end_headers() + + # Other requests cannot follow Websocket data + self.close_connection = True + return True else: self.send_error(400, "Missing Sec-WebSocket-Version header. Hixie protocols not supported.")