From 84d7b458f956727c3b0d6710b68050186ce01a35 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sun, 23 Oct 2011 13:39:19 -0700 Subject: [PATCH] Sigh... More websocket protocol changes. Closes #385. --- tornado/websocket.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tornado/websocket.py b/tornado/websocket.py index 3a17f93e10..ecc80ac436 100644 --- a/tornado/websocket.py +++ b/tornado/websocket.py @@ -5,10 +5,11 @@ .. warning:: - The WebSocket protocol is still in development. This module currently - implements the "hixie-76" and "hybi-10" versions of the protocol. - See this `browser compatibility table - `_ on Wikipedia. + The WebSocket protocol is still in development. This module + currently implements the "hixie-76", "hybi-10", and "hybi-17" + versions of the protocol. See this `browser compatibility table + `_ on + Wikipedia. """ # Author: Jacob Kristhammar, 2010 @@ -31,10 +32,12 @@ class WebSocketHandler(tornado.web.RequestHandler): See http://dev.w3.org/html5/websockets/ for details on the JavaScript interface. This implement the protocol as specified at + http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17 + The older protocol versions specified at http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10 - The older protocol version specified at + and http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76. - is also supported. + are also supported. Here is an example Web Socket handler that echos back all received messages back to the client:: @@ -79,8 +82,10 @@ def _execute(self, transforms, *args, **kwargs): self.open_args = args self.open_kwargs = kwargs - if (self.request.headers.get("Sec-WebSocket-Version") == "8" or - self.request.headers.get("Sec-WebSocket-Version") == "7"): + # The difference between version 8 and 13 is that in 8 the + # client sends a "Sec-Websocket-Origin" header and in 13 it's + # simply "Origin". + if self.request.headers.get("Sec-WebSocket-Version") in ("7", "8", "13"): self.ws_connection = WebSocketProtocol8(self) self.ws_connection.accept_connection()