cowboy_req.peer.asciidoc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. = cowboy_req:peer(3)
  2. == Name
  3. cowboy_req:peer - Peer address and port
  4. == Description
  5. [source,erlang]
  6. ----
  7. peer(Req :: cowboy_req:req()) -> Info
  8. Info :: {inet:ip_address(), inet:port_number()}
  9. ----
  10. Return the peer's IP address and port number.
  11. The peer information can also be obtained using pattern matching:
  12. [source,erlang]
  13. ----
  14. #{peer := {IP, Port}} = Req.
  15. ----
  16. == Arguments
  17. Req::
  18. The Req object.
  19. == Return value
  20. The peer's IP address and port number.
  21. The peer is not necessarily the client's IP address and port.
  22. It is the IP address of the endpoint connecting directly to
  23. the server, which may be a gateway or a proxy.
  24. The forwarded header can be used to get better information
  25. about the different endpoints from the client to the server.
  26. Note however that it is only informative; there is no reliable
  27. way of determining the source of an HTTP request.
  28. == Changelog
  29. * *2.0*: Only the peer is returned, it is no longer wrapped in a tuple.
  30. * *1.0*: Function introduced.
  31. == Examples
  32. .Get the peer IP address and port number.
  33. [source,erlang]
  34. ----
  35. {IP, Port} = cowboy_req:peer(Req).
  36. ----
  37. == See also
  38. link:man:cowboy_req(3)[cowboy_req(3)],
  39. link:man:cowboy_req:sock(3)[cowboy_req:sock(3)],
  40. link:man:cowboy_req:cert(3)[cowboy_req:cert(3)]