From: Ben Darnell Date: Sat, 21 Jan 2012 22:56:43 +0000 (-0800) Subject: Allow handlers to override the selection of "ws" or "wss" in the draft76 X-Git-Tag: v2.2.0~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cc671cb55cd788f21cbd6c4fa0fd2abe2119f2c5;p=thirdparty%2Ftornado.git Allow handlers to override the selection of "ws" or "wss" in the draft76 handshake, to work with SSL proxies that do not insert an X-Scheme header. Closes #437. --- diff --git a/tornado/websocket.py b/tornado/websocket.py index 8fcca2012..7471c4cde 100644 --- a/tornado/websocket.py +++ b/tornado/websocket.py @@ -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