Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong websocket scheme is chosen #437

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions tornado/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ def accept_connection(self):
logging.debug("Malformed WebSocket request received")
self._abort()
return
scheme = "wss" if self.request.protocol == "https" else "ws"
scheme = "wss" if self.request.headers['Origin'].startswith('https') \
else "ws"
# 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 Expand Up @@ -380,7 +381,7 @@ def accept_connection(self):
logging.debug("Malformed WebSocket request received")
self._abort()
return

def _handle_websocket_headers(self):
"""Verifies all invariant- and required headers

Expand Down Expand Up @@ -472,7 +473,7 @@ def _on_frame_start(self, data):
def _on_frame_length_16(self, data):
self._frame_length = struct.unpack("!H", data)[0];
self.stream.read_bytes(4, self._on_masking_key);

def _on_frame_length_64(self, data):
self._frame_length = struct.unpack("!Q", data)[0];
self.stream.read_bytes(4, self._on_masking_key);
Expand Down Expand Up @@ -521,7 +522,7 @@ def _on_frame_data(self, data):

if not self.client_terminated:
self._receive_frame()


def _handle_message(self, opcode, data):
if self.client_terminated: return
Expand Down Expand Up @@ -551,7 +552,7 @@ def _handle_message(self, opcode, data):
pass
else:
self._abort()

def close(self):
"""Closes the WebSocket connection."""
self._write_frame(True, 0x8, b(""))
Expand Down