2016-11-05 14:17:30 +02:00
|
|
|
= cowboy_req:peer(3)
|
|
|
|
|
|
|
|
== Name
|
|
|
|
|
|
|
|
cowboy_req:peer - Peer address and port
|
|
|
|
|
|
|
|
== Description
|
|
|
|
|
|
|
|
[source,erlang]
|
|
|
|
----
|
2017-10-25 20:17:21 +01:00
|
|
|
peer(Req :: cowboy_req:req()) -> Info
|
2016-11-05 14:17:30 +02:00
|
|
|
|
2017-10-25 20:17:21 +01:00
|
|
|
Info :: {inet:ip_address(), inet:port_number()}
|
2016-11-05 14:17:30 +02:00
|
|
|
----
|
|
|
|
|
|
|
|
Return the peer's IP address and port number.
|
|
|
|
|
2017-10-25 20:17:21 +01:00
|
|
|
The peer information can also be obtained using pattern matching:
|
2016-11-05 14:17:30 +02:00
|
|
|
|
|
|
|
[source,erlang]
|
|
|
|
----
|
|
|
|
#{peer := {IP, Port}} = Req.
|
|
|
|
----
|
|
|
|
|
|
|
|
== Arguments
|
|
|
|
|
|
|
|
Req::
|
|
|
|
|
|
|
|
The Req object.
|
|
|
|
|
|
|
|
== Return value
|
|
|
|
|
|
|
|
The peer's IP address and port number.
|
|
|
|
|
|
|
|
The peer is not necessarily the client's IP address and port.
|
|
|
|
It is the IP address of the endpoint connecting directly to
|
|
|
|
the server, which may be a gateway or a proxy.
|
|
|
|
|
|
|
|
The forwarded header can be used to get better information
|
|
|
|
about the different endpoints from the client to the server.
|
|
|
|
Note however that it is only informative; there is no reliable
|
|
|
|
way of determining the source of an HTTP request.
|
|
|
|
|
|
|
|
== Changelog
|
|
|
|
|
|
|
|
* *2.0*: Only the peer is returned, it is no longer wrapped in a tuple.
|
|
|
|
* *1.0*: Function introduced.
|
|
|
|
|
|
|
|
== Examples
|
|
|
|
|
|
|
|
.Get the peer IP address and port number.
|
|
|
|
[source,erlang]
|
|
|
|
----
|
|
|
|
{IP, Port} = cowboy_req:peer(Req).
|
|
|
|
----
|
|
|
|
|
|
|
|
== See also
|
|
|
|
|
2017-10-25 20:17:21 +01:00
|
|
|
link:man:cowboy_req(3)[cowboy_req(3)],
|
|
|
|
link:man:cowboy_req:sock(3)[cowboy_req:sock(3)],
|
|
|
|
link:man:cowboy_req:cert(3)[cowboy_req:cert(3)]
|