diff options
author | Loïc Hoguin <[email protected]> | 2013-01-30 23:38:51 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2013-01-30 23:38:51 +0100 |
commit | 855e9652fa40673d8f1ff40fd262963941e28fef (patch) | |
tree | 47781c0100c63206bed540ff5d5b9f243d8b734b /src | |
parent | f96e20aef7cce6d47535ab63c36452f6c9e1c444 (diff) | |
download | cowboy-855e9652fa40673d8f1ff40fd262963941e28fef.tar.gz cowboy-855e9652fa40673d8f1ff40fd262963941e28fef.tar.bz2 cowboy-855e9652fa40673d8f1ff40fd262963941e28fef.zip |
Make sure the peer name is always available
Diffstat (limited to 'src')
-rw-r--r-- | src/cowboy_req.erl | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl index 5cb7aa3..0745192 100644 --- a/src/cowboy_req.erl +++ b/src/cowboy_req.erl @@ -187,7 +187,8 @@ new(Socket, Transport, Method, Path, Query, Fragment, Version, Headers, Host, Port, Buffer, CanKeepalive, Compress, OnResponse) -> - Req = #http_req{socket=Socket, transport=Transport, pid=self(), + {ok, Peer} = Transport:peername(Socket), + Req = #http_req{socket=Socket, transport=Transport, pid=self(), peer=Peer, method=Method, path=Path, qs=Query, fragment=Fragment, version=Version, headers=Headers, host=Host, port=Port, buffer=Buffer, resp_compress=Compress, onresponse=OnResponse}, @@ -219,9 +220,6 @@ version(Req) -> %% @doc Return the peer address and port number of the remote host. -spec peer(Req) -> {{inet:ip_address(), inet:port_number()}, Req} when Req::req(). -peer(Req=#http_req{socket=Socket, transport=Transport, peer=undefined}) -> - {ok, Peer} = Transport:peername(Socket), - {Peer, Req#http_req{peer=Peer}}; peer(Req) -> {Req#http_req.peer, Req}. |