recv_proxy_header(ranch:ref(), timeout())
-> {ok, ranch_proxy_header:proxy_info()}
| {error, Reason :: atom()}
| {error, protocol_error, HumanReadable :: atom()}
ranch:recv_proxy_header - Receive the PROXY protocol header
recv_proxy_header(ranch:ref(), timeout())
-> {ok, ranch_proxy_header:proxy_info()}
| {error, Reason :: atom()}
| {error, protocol_error, HumanReadable :: atom()}
Receive the PROXY protocol header.
This function must be called before ranch:handshake/1,2 on newly accepted connections to read and parse the PROXY protocol header, if any.
The listener name.
Receive timeout in milliseconds.
An ok tuple is returned containing PROXY header information on success.
An error 2-tuple is returned when a socket error occurs.
An error 3-tuple is returned when a protocol error occurs and Ranch was not able to parse the PROXY header information. The third element contains a human-readable description of the error.
start_link(Ref, Transport, Opts) ->
Pid = proc_lib:spawn_link(?MODULE, init,
[Ref, Transport, Opts]),
{ok, Pid}.
init(Ref, Transport, Opts) ->
{ok, ProxyInfo} = ranch:recv_proxy_header(Ref, 1000),
{ok, Socket} = ranch:handshake(Ref),
loop(#state{ref=Ref, socket=Socket, transport=Transport,
proxy_info=ProxyInfo, opts=Opts}).
ranch:start_listener(3), ranch:handshake(3), ranch:remove_connection(3), ranch(3)
Support my work on Cowboy, Ranch, Gun and Erlang.mk via GitHub Sponsors. The funds cover domain names and development tools.