proxyprotocol.v2
¶
- class proxyprotocol.v2.ProxyProtocolV2Header(command, type, protocol, data_len)[source]¶
The 16-byte header that precedes the source and destination address data in PROXY protocol v2.
- Parameters:
command (Optional[str])
type (Optional[ProxyResultType])
protocol (Optional[SocketKind])
data_len (int)
- class proxyprotocol.v2.ProxyProtocolV2[source]¶
Implements version 2 of the PROXY protocol.
- is_valid(signature)[source]¶
Returns True if the signature is valid for this implementation of the PROXY protocol header.
- 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:
ProxyProtocolIncompleteError – The header was incomplete and must be extended with additional bytes or lines to finish parsing.
ProxyProtocolSyntaxError – The header failed to parse due to a syntax error or unsupported format.
ValueError – Malformed or out-of-range data was encountered in the header.
- Return type:
- unpack_header(header_data)[source]¶
Parse the PROXY protocol v2 header.
- Parameters:
header – The header bytestring to parse.
header_data (bytes)
- Return type:
- unpack_data(header, header_data, data)[source]¶
Parse the address information read from the stream after the v2 header.
- Parameters:
header (ProxyProtocolV2Header) – The version 2 header info.
header_data (bytes) – The header bytestring.
data (bytes) – The addresses bytestring to parse.
- Raises:
- Return type:
- 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: