Permalink
Browse files

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.
  • Loading branch information...
1 parent 4edf278 commit cc671cb55cd788f21cbd6c4fa0fd2abe2119f2c5 @bdarnell bdarnell committed Jan 21, 2012
Showing with 13 additions and 1 deletion.
  1. +13 −1 tornado/websocket.py
View
@@ -149,6 +149,18 @@ def allow_draft76(self):
"""
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 @@ def accept_connection(self):
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

0 comments on commit cc671cb

Please sign in to comment.