Skip to content

Commit

Permalink
Catch errors when calling inet:peername in ejabberd_http
Browse files Browse the repository at this point in the history
  • Loading branch information
prefiks committed Aug 17, 2015
1 parent 6d16029 commit f89db30
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/ejabberd_http.erl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ init({SockMod, Socket}, Opts) ->
default_host = DefaultHost,
options = Opts,
request_handlers = RequestHandlers},
receive_headers(State).
try receive_headers(State) of
V -> V
catch
{error, _} -> State
end.

become_controller(_Pid) -> ok.

Expand Down Expand Up @@ -427,13 +431,17 @@ process_request(#state{request_method = Method,
false ->
make_bad_request(State);
{LPath, LQuery, Data} ->
{ok, IPHere} =
PeerName =
case SockMod of
gen_tcp ->
inet:peername(Socket);
_ ->
SockMod:peername(Socket)
end,
IPHere = case PeerName of
{ok, V} -> V;
{error, _} = E -> throw(E)
end,
XFF = proplists:get_value('X-Forwarded-For', RequestHeaders, []),
IP = analyze_ip_xff(IPHere, XFF, Host),
Request = #request{method = Method,
Expand Down

0 comments on commit f89db30

Please sign in to comment.