proxyprotocol

exception proxyprotocol.ProxyProtocolSyntaxError[source]

Indicates a failure in parsing the PROXY protocol header. This indicates a syntax issue in the header, not simply bad data.

Warning

It is possible that the entire PROXY protocol header was not yet read from the stream before failure. The stream should be considered invalid and closed.

exception proxyprotocol.ProxyProtocolChecksumError(result)[source]

The PROXY protocol header was parsed but contained a CRC32C checksum that did not match the expected value.

Parameters:

result (ProxyResult) – The PROXY protocol result.

Return type:

None

exception proxyprotocol.ProxyProtocolIncompleteError(want_read)[source]

Thrown when the PROXY protocol header cannot be parsed because the provided data is not enough to be parsed. The want_read conditions should be satisfied before trying to parse again.

Parameters:

want_read (ProxyProtocolWantRead) – Specifies what data is needed for parsing to continue.

Return type:

None

class proxyprotocol.ProxyProtocolWantRead(want_bytes=None, *, want_line=False)[source]

Specifies how much additional data must be read before PROXY protocol header parsing may be completed. Either want_bytes or want_line must be given, but not both.

Parameters:
  • want_bytes (Optional[int]) – Number of bytes needed before parsing may proceed.

  • want_line (bool) – Additional data should be read until the end of a line.

class proxyprotocol.ProxyProtocol[source]

The base class for PROXY protocol implementations.

abstract is_valid(signature)[source]

Returns True if the signature is valid for this implementation of the PROXY protocol header.

Parameters:

signature (bytes) – The signature bytestring to check.

Return type:

bool

abstract unpack(data)[source]

Parse a PROXY protocol header from the given bytestring and return information about the original connection.

Parameters:

data (bytes) – The bytestring read for the header thus far.

Raises:
Return type:

ProxyResult

abstract pack(result)[source]

Builds a PROXY protocol header that may be sent at the beginning of an outbound, client-side connection to indicate the original information about the connection.

Parameters:

result (ProxyResult) – The PROXY protocol result to build into a header.

Raises:
  • KeyError – This PROXY protocol header format does not support the socket information.

  • ValueError – The address data could not be written to the PROXY protocol header format.

Return type:

bytes