mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
Make host header parser work correctly with ipv6 literal addresses
This commit is contained in:
parent
67d6ca9f10
commit
f310d7bb12
@ -68,7 +68,8 @@
|
|||||||
end_of_request = false,
|
end_of_request = false,
|
||||||
options = [],
|
options = [],
|
||||||
default_host,
|
default_host,
|
||||||
trail = <<>>
|
trail = <<>>,
|
||||||
|
addr_re
|
||||||
}).
|
}).
|
||||||
|
|
||||||
-define(XHTML_DOCTYPE,
|
-define(XHTML_DOCTYPE,
|
||||||
@ -164,13 +165,15 @@ init({SockMod, Socket}, Opts) ->
|
|||||||
?DEBUG("S: ~p~n", [RequestHandlers]),
|
?DEBUG("S: ~p~n", [RequestHandlers]),
|
||||||
|
|
||||||
DefaultHost = gen_mod:get_opt(default_host, Opts, fun(A) -> A end, undefined),
|
DefaultHost = gen_mod:get_opt(default_host, Opts, fun(A) -> A end, undefined),
|
||||||
|
{ok, RE} = re:compile(<<"^(?:\\[(.*?)\\]|(.*?))(?::(\\d+))?$">>),
|
||||||
|
|
||||||
?INFO_MSG("started: ~p", [{SockMod1, Socket1}]),
|
?INFO_MSG("started: ~p", [{SockMod1, Socket1}]),
|
||||||
State = #state{sockmod = SockMod1,
|
State = #state{sockmod = SockMod1,
|
||||||
socket = Socket1,
|
socket = Socket1,
|
||||||
default_host = DefaultHost,
|
default_host = DefaultHost,
|
||||||
options = Opts,
|
options = Opts,
|
||||||
request_handlers = RequestHandlers},
|
request_handlers = RequestHandlers,
|
||||||
|
addr_re = RE},
|
||||||
try receive_headers(State) of
|
try receive_headers(State) of
|
||||||
V -> V
|
V -> V
|
||||||
catch
|
catch
|
||||||
@ -292,7 +295,7 @@ process_header(State, Data) ->
|
|||||||
[State#state.socket, State#state.request_method,
|
[State#state.socket, State#state.request_method,
|
||||||
element(2, State#state.request_path)]),
|
element(2, State#state.request_path)]),
|
||||||
{HostProvided, Port, TP} =
|
{HostProvided, Port, TP} =
|
||||||
get_transfer_protocol(SockMod,
|
get_transfer_protocol(State#state.addr_re, SockMod,
|
||||||
State#state.request_host),
|
State#state.request_host),
|
||||||
Host = get_host_really_served(State#state.default_host,
|
Host = get_host_really_served(State#state.default_host,
|
||||||
HostProvided),
|
HostProvided),
|
||||||
@ -332,16 +335,25 @@ get_host_really_served(Default, Provided) ->
|
|||||||
false -> Default
|
false -> Default
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_transfer_protocol(SockMod, HostPort) ->
|
get_transfer_protocol(RE, SockMod, HostPort) ->
|
||||||
[Host | PortList] = str:tokens(HostPort, <<":">>),
|
{Proto, DefPort} = case SockMod of
|
||||||
case {SockMod, PortList} of
|
gen_tcp -> {http, 80};
|
||||||
{gen_tcp, []} -> {Host, 80, http};
|
fast_tls -> {https, 443}
|
||||||
{gen_tcp, [Port]} ->
|
end,
|
||||||
{Host, binary_to_integer(Port), http};
|
{Host, Port} = case re:run(HostPort, RE, [{capture,[1,2,3],binary}]) of
|
||||||
{fast_tls, []} -> {Host, 443, https};
|
nomatch ->
|
||||||
{fast_tls, [Port]} ->
|
{<<"0.0.0.0">>, DefPort};
|
||||||
{Host, binary_to_integer(Port), https}
|
{match, [<<>>, H, <<>>]} ->
|
||||||
end.
|
{H, DefPort};
|
||||||
|
{match, [H, <<>>, <<>>]} ->
|
||||||
|
{H, DefPort};
|
||||||
|
{match, [<<>>, H, PortStr]} ->
|
||||||
|
{H, binary_to_integer(PortStr)};
|
||||||
|
{match, [H, <<>>, PortStr]} ->
|
||||||
|
{H, binary_to_integer(PortStr)}
|
||||||
|
end,
|
||||||
|
|
||||||
|
{Host, Port, Proto}.
|
||||||
|
|
||||||
%% XXX bard: search through request handlers looking for one that
|
%% XXX bard: search through request handlers looking for one that
|
||||||
%% matches the requested URL path, and pass control to it. If none is
|
%% matches the requested URL path, and pass control to it. If none is
|
||||||
|
Loading…
Reference in New Issue
Block a user