read_client_addr

Function read_client_addr 

Source
pub async fn read_client_addr<S>(
    stream: &mut S,
    real: SocketAddr,
    deadline: Duration,
) -> Result<ProxyHeader, ProxyProtoError>
where S: AsyncRead + AsyncWrite + Unpin,
Expand description

Read one PROXY protocol header (v1 or v2) from the stream and decide the connection’s EFFECTIVE client address.

Returns the address the gateway must use as the peer: the header’s source address for a PROXY command with a TCP family, or real for the specification’s own fallback shapes (v2 LOCAL, v1 UNKNOWN). deadline bounds the WHOLE header (not per-read: a partial PROXY line can never be handed to the HTTP parser, so unlike the DW-023 request-head sniff there is no fall-through).

Reads incrementally: ppp’s PartialResult says whether more bytes could complete the header, so at most the header itself is buffered (never the request that follows it on well-behaved senders that coalesce; a sender that pipelines request bytes into the first read has them replayed by the caller’s sniff/prefix stream — see ProxyHeader::consumed).