Show More
@@ -34,6 +34,55 b' try:' | |||
|
34 | 34 | except ImportError: |
|
35 | 35 | publish_string = None |
|
36 | 36 | |
|
37 | #----------------------------------------------------------------------------- | |
|
38 | # Monkeypatch for Tornado 2.1.1 - Remove when no longer necessary! | |
|
39 | #----------------------------------------------------------------------------- | |
|
40 | ||
|
41 | # Google Chrome, as of release 16, changed its websocket protocol number. The | |
|
42 | # parts tornado cares about haven't really changed, so it's OK to continue | |
|
43 | # accepting Chrome connections, but as of Tornado 2.1.1 (the currently released | |
|
44 | # version as of Oct 30/2011) the version check fails, see the issue report: | |
|
45 | ||
|
46 | # https://github.com/facebook/tornado/issues/385 | |
|
47 | ||
|
48 | # This issue has been fixed in Tornado post 2.1.1: | |
|
49 | ||
|
50 | # https://github.com/facebook/tornado/commit/84d7b458f956727c3b0d6710 | |
|
51 | ||
|
52 | # Here we manually apply the same patch as above so that users of IPython can | |
|
53 | # continue to work with an officially released Tornado. We make the | |
|
54 | # monkeypatch version check as narrow as possible to limit its effects; once | |
|
55 | # Tornado 2.1.1 is no longer found in the wild we'll delete this code. | |
|
56 | ||
|
57 | import tornado | |
|
58 | ||
|
59 | if tornado.version == '2.1.1': | |
|
60 | ||
|
61 | def _execute(self, transforms, *args, **kwargs): | |
|
62 | from tornado.websocket import WebSocketProtocol8, WebSocketProtocol76 | |
|
63 | ||
|
64 | self.open_args = args | |
|
65 | self.open_kwargs = kwargs | |
|
66 | ||
|
67 | # The difference between version 8 and 13 is that in 8 the | |
|
68 | # client sends a "Sec-Websocket-Origin" header and in 13 it's | |
|
69 | # simply "Origin". | |
|
70 | if self.request.headers.get("Sec-WebSocket-Version") in ("7", "8", "13"): | |
|
71 | self.ws_connection = WebSocketProtocol8(self) | |
|
72 | self.ws_connection.accept_connection() | |
|
73 | ||
|
74 | elif self.request.headers.get("Sec-WebSocket-Version"): | |
|
75 | self.stream.write(tornado.escape.utf8( | |
|
76 | "HTTP/1.1 426 Upgrade Required\r\n" | |
|
77 | "Sec-WebSocket-Version: 8\r\n\r\n")) | |
|
78 | self.stream.close() | |
|
79 | ||
|
80 | else: | |
|
81 | self.ws_connection = WebSocketProtocol76(self) | |
|
82 | self.ws_connection.accept_connection() | |
|
83 | ||
|
84 | websocket.WebSocketHandler._execute = _execute | |
|
85 | del _execute | |
|
37 | 86 | |
|
38 | 87 | #----------------------------------------------------------------------------- |
|
39 | 88 | # Decorator for disabling read-only handlers |
General Comments 0
You need to be logged in to leave comments.
Login now