# This is necessary when using proxies (such as HAProxy), which
# need to see the Upgrade headers before passing through the
# non-HTTP traffic that follows.
- self.stream.write(
+ self.stream.write(tornado.escape.utf8(
"HTTP/1.1 101 Web Socket Protocol Handshake\r\n"
"Upgrade: WebSocket\r\n"
"Connection: Upgrade\r\n"
origin=self.request.headers["Origin"],
scheme=scheme,
host=self.request.host,
- uri=self.request.uri)))
+ uri=self.request.uri))))
self.stream.read_bytes(8, self._handle_challenge)
def _handle_challenge(self, challenge):
"""Processes the key headers and calculates their key value.
Raises ValueError when feed invalid key."""
- number, spaces = filter(str.isdigit, key), filter(str.isspace, key)
+ number = int(''.join(c for c in key if c.isdigit()))
+ spaces = len([c for c in key if c.isspace()])
try:
- key_number = int(number) / len(spaces)
+ key_number = number / spaces
except (ValueError, ZeroDivisionError):
raise ValueError
return struct.pack(">I", key_number)