proxyprotocol.reader

class proxyprotocol.reader.ProxyProtocolReader(pp)[source]

Read a PROXY protocol header from a stream.

Parameters:

pp (ProxyProtocol) – The PROXY protocol implementation.

async read(reader)[source]

Read a complete PROXY protocol header from the input stream and return the result.

Parameters:

reader (StreamReaderProtocol) – The input stream.

Return type:

ProxyResult

get_callback(callback, timeout=3)[source]

Get a callback object for use as the client_connected_cb argument to asyncio.start_server().

The returned callback will first read the PROXY protocol header before starting the provided callback as a Task. The callback argument is similar to client_connected_cb but with an additional positional argument – the SocketInfo read from the header.

Parameters:
  • callback (Callable[[StreamReader, StreamWriter, SocketInfo], Coroutine[Any, Any, None]]) – Async function with arguments (reader, writer, sock_info) called after successfully reading the header.

  • timeout (None | int | float) – A timeout in seconds to allow for reading the header.

Return type:

Callable[[StreamReader, StreamWriter], Awaitable[None]]