Debian Codegraph @

doc/src/manual/cowboy_req.peer.asciidoc

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