Skip to content

Commit

Permalink
Allow handlers to override the selection of "ws" or "wss" in the draft76
Browse files Browse the repository at this point in the history
handshake, to work with SSL proxies that do not insert an X-Scheme header.

Closes tornadoweb#437.
  • Loading branch information
bdarnell committed Jan 21, 2012
1 parent 4edf278 commit cc671cb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tornado/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cc671cb

Please sign in to comment.