Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Monkeypatch Tornado 2.1.1 so it works with Google Chrome 16. #948

Merged
merged 2 commits into from

3 participants

@fperez
Owner

We're just applying manually a fix from Tornado itself, see for
details:

tornadoweb/tornado#385
tornadoweb/tornado@84d7b45

This isn't sufficient to take care of #934 completely, as we should also put out a proper websocket diagnostic message for any connection message. But it should at least take care of users of the -dev Chrome channel in normal circumstances.

@satra, let us know if this fixes the behavior you saw on Friday; I tested with Chrome 16.... on my linux box and it does fix it for me.

IPython/frontend/html/notebook/handlers.py
((23 lines not shown))
+import tornado
+
+if tornado.version == '2.1.1':
@takluyver Owner

Should we do this check so that it also gets 2.1.0?

@fperez Owner
fperez added a note

No, I think 2.1.0 doesn't actually work, if I remember right. But perhaps it does? Do you know for sure it does? If so, then yes.

@takluyver Owner

Seems to be working for me with Firefox (I installed tornado just after the 2.1 release). I guess there aren't many people using it, but it's simple enough to do tornado.version_info <= (2,1,1).

@fperez Owner
fperez added a note

What's the version_info value for 2.1? I'd rather check specifically for 2.1 or 2.1.1: monkeypatches are ugly, I like them as tightly constrained as possible.

@minrk Owner
minrk added a note

Our version checks are for 2.1.0, so if it doesn't work, we should update them. version_info reports (2,1,0) for 2.1.0, though since tornado < (2,1,0) doesn't work at all (you can't even import the handlers file where the monkeypatch resides if tornado is pre-2.1 because notebook.__init__ checks for it), you should be able to do a simple <= (2,1,1) test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@takluyver
Owner

Let's open a low-priority issue when we merge this, to remove it when it's no longer needed, just so it doesn't get lost under the radar.

@fperez
Owner

Good idea, go ahead.

@fperez
Owner

OK, I've made the change to using version_info and working with 2.1.{0,1}. Thanks for the review. Anything else, or should I merge?

@minrk
Owner

Looks good to me

@fperez fperez merged commit f76ea91 into ipython:master
@fperez fperez referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 30, 2011
  1. @fperez

    Monkeypatch Tornado 2.1.1 so it works with Google Chrome 16.

    fperez authored
    We're just applying manually a fix from Tornado itself, see for
    details:
    
    tornadoweb/tornado#385
    tornadoweb/tornado@84d7b45
  2. @fperez
This page is out of date. Refresh to see the latest.
Showing with 49 additions and 0 deletions.
  1. +49 −0 IPython/frontend/html/notebook/handlers.py
View
49 IPython/frontend/html/notebook/handlers.py
@@ -34,7 +34,56 @@
except ImportError:
publish_string = None
+#-----------------------------------------------------------------------------
+# Monkeypatch for Tornado <= 2.1.1 - Remove when no longer necessary!
+#-----------------------------------------------------------------------------
+
+# Google Chrome, as of release 16, changed its websocket protocol number. The
+# parts tornado cares about haven't really changed, so it's OK to continue
+# accepting Chrome connections, but as of Tornado 2.1.1 (the currently released
+# version as of Oct 30/2011) the version check fails, see the issue report:
+
+# https://github.com/facebook/tornado/issues/385
+
+# This issue has been fixed in Tornado post 2.1.1:
+
+# https://github.com/facebook/tornado/commit/84d7b458f956727c3b0d6710
+
+# Here we manually apply the same patch as above so that users of IPython can
+# continue to work with an officially released Tornado. We make the
+# monkeypatch version check as narrow as possible to limit its effects; once
+# Tornado 2.1.1 is no longer found in the wild we'll delete this code.
+import tornado
+
+if tornado.version_info <= (2,1,1):
+
+ def _execute(self, transforms, *args, **kwargs):
+ from tornado.websocket import WebSocketProtocol8, WebSocketProtocol76
+
+ self.open_args = args
+ self.open_kwargs = kwargs
+
+ # 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()
+
+ elif self.request.headers.get("Sec-WebSocket-Version"):
+ self.stream.write(tornado.escape.utf8(
+ "HTTP/1.1 426 Upgrade Required\r\n"
+ "Sec-WebSocket-Version: 8\r\n\r\n"))
+ self.stream.close()
+
+ else:
+ self.ws_connection = WebSocketProtocol76(self)
+ self.ws_connection.accept_connection()
+
+ websocket.WebSocketHandler._execute = _execute
+ del _execute
+
#-----------------------------------------------------------------------------
# Decorator for disabling read-only handlers
#-----------------------------------------------------------------------------
Something went wrong with that request. Please try again.