示例#1
0
def _get_permessage_deflate_framer(extension_response):
    """Validate the response and return a framer object using the parameters in
    the response. This method doesn't accept the s2c_.* parameters.
    """

    c2s_max_window_bits = None
    c2s_no_context_takeover = None

    c2s_max_window_bits_name = PerMessageDeflateExtensionProcessor._C2S_MAX_WINDOW_BITS_PARAM
    c2s_no_context_takeover_name = PerMessageDeflateExtensionProcessor._C2S_NO_CONTEXT_TAKEOVER_PARAM

    # We didn't send any s2c_.* parameter. Handle those parameters as invalid
    # if found in the response.

    for param_name, param_value in extension_response.get_parameters():
        if param_name == c2s_max_window_bits_name:
            if c2s_max_window_bits is not None:
                raise ClientHandshakeError("Multiple %s found" % c2s_max_window_bits_name)

            parsed_value = _parse_window_bits(param_value)
            if parsed_value is None:
                raise ClientHandshakeError("Bad %s: %r" % (c2s_max_window_bits_name, param_value))
            c2s_max_window_bits = parsed_value
        elif param_name == c2s_no_context_takeover_name:
            if c2s_no_context_takeover is not None:
                raise ClientHandshakeError("Multiple %s found" % c2s_no_context_takeover_name)

            if param_value is not None:
                raise ClientHandshakeError("Bad %s: Has value %r" % (c2s_no_context_takeover_name, param_value))
            c2s_no_context_takeover = True

    if c2s_no_context_takeover is None:
        c2s_no_context_takeover = False

    return _PerMessageDeflateFramer(c2s_max_window_bits, c2s_no_context_takeover)
示例#2
0
def _get_permessage_deflate_framer(extension_response):
    """Validate the response and return a framer object using the parameters in
    the response. This method doesn't accept the server_.* parameters.
    """

    client_max_window_bits = None
    client_no_context_takeover = None

    client_max_window_bits_name = (
            PerMessageDeflateExtensionProcessor.
                    _CLIENT_MAX_WINDOW_BITS_PARAM)
    client_no_context_takeover_name = (
            PerMessageDeflateExtensionProcessor.
                    _CLIENT_NO_CONTEXT_TAKEOVER_PARAM)

    # We didn't send any server_.* parameter.
    # Handle those parameters as invalid if found in the response.

    for param_name, param_value in extension_response.get_parameters():
        if param_name == client_max_window_bits_name:
            if client_max_window_bits is not None:
                raise ClientHandshakeError(
                        'Multiple %s found' % client_max_window_bits_name)

            parsed_value = _parse_window_bits(param_value)
            if parsed_value is None:
                raise ClientHandshakeError(
                        'Bad %s: %r' %
                        (client_max_window_bits_name, param_value))
            client_max_window_bits = parsed_value
        elif param_name == client_no_context_takeover_name:
            if client_no_context_takeover is not None:
                raise ClientHandshakeError(
                        'Multiple %s found' % client_no_context_takeover_name)

            if param_value is not None:
                raise ClientHandshakeError(
                        'Bad %s: Has value %r' %
                        (client_no_context_takeover_name, param_value))
            client_no_context_takeover = True

    if client_no_context_takeover is None:
        client_no_context_takeover = False

    return _PerMessageDeflateFramer(client_max_window_bits,
                                    client_no_context_takeover)