How to use the hpack.exceptions.HPACKError function in hpack

To help you get started, we’ve selected a few hpack examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github web-platform-tests / wpt / tools / third_party / h2 / h2 / connection.py View on Github external
def _decode_headers(decoder, encoded_header_block):
    """
    Decode a HPACK-encoded header block, translating HPACK exceptions into
    sensible hyper-h2 errors.

    This only ever returns bytestring headers: hyper-h2 may emit them as
    unicode later, but internally it processes them as bytestrings only.
    """
    try:
        return decoder.decode(encoded_header_block, raw=True)
    except OversizedHeaderListError as e:
        # This is a symptom of a HPACK bomb attack: the user has
        # disregarded our requirements on how large a header block we'll
        # accept.
        raise DenialOfServiceError("Oversized header block: %s" % e)
    except (HPACKError, IndexError, TypeError, UnicodeDecodeError) as e:
        # We should only need HPACKError here, but versions of HPACK older
        # than 2.1.0 throw all three others as well. For maximum
        # compatibility, catch all of them.
        raise ProtocolError("Error decoding header block: %s" % e)
github python-hyper / hyper-h2 / h2 / connection.py View on Github external
def _decode_headers(decoder, encoded_header_block):
    """
    Decode a HPACK-encoded header block, translating HPACK exceptions into
    sensible hyper-h2 errors.

    This only ever returns bytestring headers: hyper-h2 may emit them as
    unicode later, but internally it processes them as bytestrings only.
    """
    try:
        return decoder.decode(encoded_header_block, raw=True)
    except OversizedHeaderListError as e:
        # This is a symptom of a HPACK bomb attack: the user has
        # disregarded our requirements on how large a header block we'll
        # accept.
        raise DenialOfServiceError("Oversized header block: %s" % e)
    except (HPACKError, IndexError, TypeError, UnicodeDecodeError) as e:
        # We should only need HPACKError here, but versions of HPACK older
        # than 2.1.0 throw all three others as well. For maximum
        # compatibility, catch all of them.
        raise ProtocolError("Error decoding header block: %s" % e)
github opensvc / opensvc / opensvc / foreign / h2 / connection.py View on Github external
def _decode_headers(decoder, encoded_header_block):
    """
    Decode a HPACK-encoded header block, translating HPACK exceptions into
    sensible hyper-h2 errors.

    This only ever returns bytestring headers: hyper-h2 may emit them as
    unicode later, but internally it processes them as bytestrings only.
    """
    try:
        return decoder.decode(encoded_header_block, raw=True)
    except OversizedHeaderListError as e:
        # This is a symptom of a HPACK bomb attack: the user has
        # disregarded our requirements on how large a header block we'll
        # accept.
        raise DenialOfServiceError("Oversized header block: %s" % e)
    except (HPACKError, IndexError, TypeError, UnicodeDecodeError) as e:
        # We should only need HPACKError here, but versions of HPACK older
        # than 2.1.0 throw all three others as well. For maximum
        # compatibility, catch all of them.
        raise ProtocolError("Error decoding header block: %s" % e)