Skip to content
This repository

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

Merged
merged 2 commits into from over 2 years ago

3 participants

Fernando Perez Thomas Kluyver Min RK
Fernando Perez
Owner

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

facebook/tornado#385
facebook/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.

Fernando Perez Monkeypatch Tornado 2.1.1 so it works with Google Chrome 16.
We're just applying manually a fix from Tornado itself, see for
details:

facebook/tornado#385
facebook/tornado@84d7b45
113b26e
IPython/frontend/html/notebook/handlers.py
((23 lines not shown))
37 56
 
  57
+import tornado
  58
+
  59
+if tornado.version == '2.1.1':
5
Thomas Kluyver Collaborator

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

Fernando Perez Owner
fperez added a note October 30, 2011

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.

Thomas Kluyver Collaborator

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).

Fernando Perez Owner
fperez added a note October 30, 2011

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.

Min RK Owner
minrk added a note October 30, 2011

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
Thomas Kluyver
Collaborator

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.

Fernando Perez
Owner

Good idea, go ahead.

Fernando Perez
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?

Min RK
Owner

Looks good to me

Fernando Perez fperez merged commit f76ea91 into from October 30, 2011
Fernando Perez fperez closed this October 30, 2011
Fernando Perez fperez referenced this pull request from a commit January 10, 2012
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

Showing 2 unique commits by 1 author.

Oct 30, 2011
Fernando Perez Monkeypatch Tornado 2.1.1 so it works with Google Chrome 16.
We're just applying manually a fix from Tornado itself, see for
details:

facebook/tornado#385
facebook/tornado@84d7b45
113b26e
Fernando Perez Update version check to work with tornado 2.1.0 or 2.1.1 36ccaa3
This page is out of date. Refresh to see the latest.
49  IPython/frontend/html/notebook/handlers.py
@@ -34,7 +34,56 @@
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.
37 56
 
  57
+import tornado
  58
+
  59
+if tornado.version_info <= (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
  86
+    
38 87
 #-----------------------------------------------------------------------------
39 88
 # Decorator for disabling read-only handlers
40 89
 #-----------------------------------------------------------------------------
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.