proxyprotocol.detect

class proxyprotocol.detect.ProxyProtocolDetect(*versions)[source]

A PROXY protocol implementation that detects the version based on the first 8 bytes from the stream and passes it on to the version parser. This adds minimal overhead and should be used instead of a specific version.

Parameters:

versions (ProxyProtocol) – Override the default set of PROXY protocol implementations.

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

choose_version(signature)[source]

Choose the PROXY protocol version based on the 8-byte signature.

Parameters:

signature (bytes) – The signature bytestring.

Return type:

ProxyProtocol

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

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