]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Allow handlers to override the selection of "ws" or "wss" in the draft76
authorBen Darnell <ben@bendarnell.com>
Sat, 21 Jan 2012 22:56:43 +0000 (14:56 -0800)
committerBen Darnell <ben@bendarnell.com>
Sat, 21 Jan 2012 22:56:43 +0000 (14:56 -0800)
handshake, to work with SSL proxies that do not insert an X-Scheme header.

Closes #437.

tornado/websocket.py

index 8fcca20123ad4f13a87b10158c4e7da809119560..7471c4cde18b415f7cdfd6d271e7f017c97cc607 100644 (file)
@@ -149,6 +149,18 @@ class WebSocketHandler(tornado.web.RequestHandler):
         """
         return False
 
+    def get_websocket_scheme(self):
+        """Return the url scheme used for this request, either "ws" or "wss".
+
+        This is normally decided by HTTPServer, but applications
+        may wish to override this if they are using an SSL proxy
+        that does not provide the X-Scheme header as understood
+        by HTTPServer.
+        
+        Note that this is only used by the draft76 protocol.
+        """
+        return "wss" if self.request.protocol == "https" else "ws"
+
     def async_callback(self, callback, *args, **kwargs):
         """Wrap callbacks with this if they are used on asynchronous requests.
 
@@ -228,7 +240,7 @@ class WebSocketProtocol76(WebSocketProtocol):
             logging.debug("Malformed WebSocket request received")
             self._abort()
             return
-        scheme = "wss" if self.request.protocol == "https" else "ws"
+        scheme = self.handler.get_websocket_scheme()
         # Write the initial headers before attempting to read the challenge.
         # This is necessary when using proxies (such as HAProxy), which
         # need to see the Upgrade headers before passing through the