Example #1
0
    def _get_key(self):
        key = get_mandatory_header(self._request,
                                   common.SEC_WEBSOCKET_KEY_HEADER)

        decoded_key = self._validate_key(key)

        self._logger.debug('%s: %r (%s)', common.SEC_WEBSOCKET_KEY_HEADER, key,
                           util.hexify(decoded_key))

        return key.encode('UTF-8')
Example #2
0
    def _validate_connection_header(self):
        connection = get_mandatory_header(self._request,
                                          common.CONNECTION_HEADER)

        try:
            connection_tokens = parse_token_list(connection)
        except HandshakeException as e:
            raise HandshakeException('Failed to parse %s: %s' %
                                     (common.CONNECTION_HEADER, e))

        connection_is_valid = False
        for token in connection_tokens:
            if token.lower() == common.UPGRADE_CONNECTION_TYPE.lower():
                connection_is_valid = True
                break
        if not connection_is_valid:
            raise HandshakeException(
                '%s header doesn\'t contain "%s"' %
                (common.CONNECTION_HEADER, common.UPGRADE_CONNECTION_TYPE))
Example #3
0
 def _validate_request(self):
     check_connect_method(self._request)
     validate_mandatory_header(self._request, ':protocol', 'websocket')
     get_mandatory_header(self._request, 'authority')
Example #4
0
 def _validate_request(self):
     check_request_line(self._request)
     validate_mandatory_header(self._request, common.UPGRADE_HEADER,
                               common.WEBSOCKET_UPGRADE_TYPE)
     self._validate_connection_header()
     unused_host = get_mandatory_header(self._request, common.HOST_HEADER)