Beispiel #1
0
    def test_parse_with_allow_quoted_string(self):
        for formatted_string, definition in _TEST_TOKEN_EXTENSION_DATA:
            self._verify_extension_list(
                definition, parse_extensions(formatted_string,
                                             allow_quoted_string=True))

        for formatted_string, definition in _TEST_QUOTED_EXTENSION_DATA:
            self._verify_extension_list(
                definition, parse_extensions(formatted_string,
                                             allow_quoted_string=True))
Beispiel #2
0
    def test_parse_redundant_data_with_allow_quoted_string(self):
        for (formatted_string,
             definition) in _TEST_REDUNDANT_TOKEN_EXTENSION_DATA:
            self._verify_extension_list(
                definition, parse_extensions(formatted_string,
                                             allow_quoted_string=True))

        for (formatted_string,
             definition) in _TEST_REDUNDANT_QUOTED_EXTENSION_DATA:
            self._verify_extension_list(
                definition, parse_extensions(formatted_string,
                                             allow_quoted_string=True))
Beispiel #3
0
    def _set_extensions(self):
        self._request.ws_deflate = False

        extensions_header = self._request.headers_in.get(
            common.SEC_WEBSOCKET_EXTENSIONS_HEADER)
        if not extensions_header:
            self._request.ws_requested_extensions = None
            self._request.ws_extensions = None
            return

        self._request.ws_extensions = []

        requested_extensions = parse_extensions(extensions_header)

        for extension in requested_extensions:
            extension_name = extension.name()
            # We now support only deflate-stream extension. Any other
            # extension requests are just ignored for now.
            if (extension_name == 'deflate-stream' and
                len(extension.get_parameter_names()) == 0):
                self._request.ws_extensions.append(extension)
                self._request.ws_deflate = True

        self._request.ws_requested_extensions = requested_extensions

        self._logger.debug(
            'Extensions requested: %r',
            map(Extension.name, self._request.ws_requested_extensions))
        self._logger.debug(
            'Extensions accepted: %r',
            map(Extension.name, self._request.ws_extensions))
Beispiel #4
0
    def _set_extensions(self):
        self._request.ws_deflate = False

        extensions_header = self._request.headers_in.get(
            common.SEC_WEBSOCKET_EXTENSIONS_HEADER)
        if not extensions_header:
            self._request.ws_requested_extensions = None
            self._request.ws_extensions = None
            return

        self._request.ws_extensions = []

        requested_extensions = parse_extensions(extensions_header)

        for extension in requested_extensions:
            extension_name = extension.name()
            # We now support only deflate-stream extension. Any other
            # extension requests are just ignored for now.
            if (extension_name == 'deflate-stream'
                    and len(extension.get_parameter_names()) == 0):
                self._request.ws_extensions.append(extension)
                self._request.ws_deflate = True

        self._request.ws_requested_extensions = requested_extensions

        self._logger.debug(
            'Extensions requested: %r',
            map(Extension.name, self._request.ws_requested_extensions))
        self._logger.debug('Extensions accepted: %r',
                           map(Extension.name, self._request.ws_extensions))
Beispiel #5
0
    def test_parse(self):
        for formatted_string, definition in _TEST_TOKEN_EXTENSION_DATA:
            self._verify_extension_list(
                definition, parse_extensions(formatted_string,
                                             allow_quoted_string=False))

        for formatted_string, unused_definition in _TEST_QUOTED_EXTENSION_DATA:
            self.assertRaises(
                HandshakeException, parse_extensions, formatted_string, False)
Beispiel #6
0
    def test_parse_redundant_data(self):
        for (formatted_string,
             definition) in _TEST_REDUNDANT_TOKEN_EXTENSION_DATA:
            self._verify_extension_list(
                definition, parse_extensions(formatted_string,
                                             allow_quoted_string=False))

        for (formatted_string,
             definition) in _TEST_REDUNDANT_QUOTED_EXTENSION_DATA:
            self.assertRaises(
                HandshakeException, parse_extensions, formatted_string, False)
Beispiel #7
0
    def _parse_extensions(self):
        extensions_header = self._request.headers_in.get(
            common.SEC_WEBSOCKET_EXTENSIONS_HEADER)
        if not extensions_header:
            self._request.ws_requested_extensions = None
            return

        if self._request.ws_version is common.VERSION_HYBI08:
            allow_quoted_string=False
        else:
            allow_quoted_string=True
        self._request.ws_requested_extensions = parse_extensions(
            extensions_header, allow_quoted_string=allow_quoted_string)

        self._logger.debug(
            'Extensions requested: %r',
            map(common.ExtensionParameter.name,
                self._request.ws_requested_extensions))
Beispiel #8
0
    def _parse_extensions(self):
        extensions_header = self._request.headers_in.get(
            common.SEC_WEBSOCKET_EXTENSIONS_HEADER)
        if not extensions_header:
            self._request.ws_requested_extensions = None
            return

        if self._request.ws_version is common.VERSION_HYBI08:
            allow_quoted_string = False
        else:
            allow_quoted_string = True
        self._request.ws_requested_extensions = parse_extensions(
            extensions_header, allow_quoted_string=allow_quoted_string)

        self._logger.debug(
            'Extensions requested: %r',
            map(common.ExtensionParameter.name,
                self._request.ws_requested_extensions))