ranch.recv_proxy_header.asciidoc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. = ranch:recv_proxy_header(3)
  2. == Name
  3. ranch:recv_proxy_header - Receive the PROXY protocol header
  4. == Description
  5. [source,erlang]
  6. ----
  7. recv_proxy_header(ranch:ref(), timeout())
  8. -> {ok, ranch_proxy_header:proxy_info()}
  9. | {error, Reason :: atom()}
  10. | {error, protocol_error, HumanReadable :: atom()}
  11. ----
  12. Receive the PROXY protocol header.
  13. This function must be called before `ranch:handshake/1,2`
  14. on newly accepted connections to read and parse the PROXY
  15. protocol header, if any.
  16. == Arguments
  17. Ref::
  18. The listener name.
  19. Timeout::
  20. Receive timeout in milliseconds.
  21. == Return value
  22. An `ok` tuple is returned containing PROXY header information
  23. on success.
  24. An `error` 2-tuple is returned when a socket error occurs.
  25. An `error` 3-tuple is returned when a protocol error occurs
  26. and Ranch was not able to parse the PROXY header information.
  27. The third element contains a human-readable description of
  28. the error.
  29. == Changelog
  30. * *1.7*: Function introduced.
  31. == Examples
  32. .Receive the PROXY protocol header
  33. [source,erlang]
  34. ----
  35. start_link(Ref, Transport, Opts) ->
  36. Pid = proc_lib:spawn_link(?MODULE, init,
  37. [Ref, Transport, Opts]),
  38. {ok, Pid}.
  39. init(Ref, Transport, Opts) ->
  40. {ok, ProxyInfo} = ranch:recv_proxy_header(Ref, 1000),
  41. {ok, Socket} = ranch:handshake(Ref),
  42. loop(#state{ref=Ref, socket=Socket, transport=Transport,
  43. proxy_info=ProxyInfo, opts=Opts}).
  44. ----
  45. == See also
  46. link:man:ranch:start_listener(3)[ranch:start_listener(3)],
  47. link:man:ranch:handshake(3)[ranch:handshake(3)],
  48. link:man:ranch:remove_connection(3)[ranch:remove_connection(3)],
  49. link:man:ranch(3)[ranch(3)]