Skip to content

Commit cc671cb

Browse files
committed
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 tornadoweb#437.
1 parent 4edf278 commit cc671cb

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tornado/websocket.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ def allow_draft76(self):
149149
"""
150150
return False
151151

152+
def get_websocket_scheme(self):
153+
"""Return the url scheme used for this request, either "ws" or "wss".
154+
155+
This is normally decided by HTTPServer, but applications
156+
may wish to override this if they are using an SSL proxy
157+
that does not provide the X-Scheme header as understood
158+
by HTTPServer.
159+
160+
Note that this is only used by the draft76 protocol.
161+
"""
162+
return "wss" if self.request.protocol == "https" else "ws"
163+
152164
def async_callback(self, callback, *args, **kwargs):
153165
"""Wrap callbacks with this if they are used on asynchronous requests.
154166
@@ -228,7 +240,7 @@ def accept_connection(self):
228240
logging.debug("Malformed WebSocket request received")
229241
self._abort()
230242
return
231-
scheme = "wss" if self.request.protocol == "https" else "ws"
243+
scheme = self.handler.get_websocket_scheme()
232244
# Write the initial headers before attempting to read the challenge.
233245
# This is necessary when using proxies (such as HAProxy), which
234246
# need to see the Upgrade headers before passing through the

0 commit comments

Comments
 (0)