mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Option default_host for handling HTTP requests with ambiguous Host (EJAB-1261)
This commit is contained in:
parent
4819738e8f
commit
7d623d5eb4
@ -826,7 +826,7 @@ The available modules, their purpose and the options allowed by each one are:
|
||||
Options: \texttt{certfile}
|
||||
\titem{\texttt{ejabberd\_http}}
|
||||
Handles incoming HTTP connections.\\
|
||||
Options: \texttt{captcha}, \texttt{certfile}, \texttt{http\_bind}, \texttt{http\_poll},
|
||||
Options: \texttt{captcha}, \texttt{certfile}, \texttt{default\_host}, \texttt{http\_bind}, \texttt{http\_poll},
|
||||
\texttt{request\_handlers}, \texttt{tls}, \texttt{trusted\_proxies}, \texttt{web\_admin}\\
|
||||
\end{description}
|
||||
|
||||
@ -847,6 +847,11 @@ This is a detailed description of each option allowed by the listening modules:
|
||||
Simple web page that allows a user to fill a CAPTCHA challenge (see section \ref{captcha}).
|
||||
\titem{\{certfile, Path\}} Full path to a file containing the default SSL certificate.
|
||||
To define a certificate file specific for a given domain, use the global option \term{domain\_certfile}.
|
||||
\titem{\{default\_host, undefined|HostName\}}
|
||||
If the HTTP request received by ejabberd contains the HTTP header \term{Host}
|
||||
with an ambiguous virtual host that doesn't match any one defined in ejabberd (see \ref{hostnames}),
|
||||
then this configured HostName is set as the request Host.
|
||||
The default value of this option is: \term{undefined}.
|
||||
\titem{\{hosts, [Hostname, ...], [HostOption, ...]\}} \ind{options!hosts}
|
||||
The external Jabber component that connects to this \term{ejabberd\_service}
|
||||
can serve one or more hostnames.
|
||||
|
@ -65,6 +65,7 @@
|
||||
request_tp,
|
||||
request_headers = [],
|
||||
end_of_request = false,
|
||||
default_host,
|
||||
trail = ""
|
||||
}).
|
||||
|
||||
@ -140,9 +141,12 @@ init({SockMod, Socket}, Opts) ->
|
||||
end,
|
||||
?DEBUG("S: ~p~n", [RequestHandlers]),
|
||||
|
||||
DefaultHost = gen_mod:get_opt(default_host, Opts, undefined),
|
||||
|
||||
?INFO_MSG("started: ~p", [{SockMod1, Socket1}]),
|
||||
State = #state{sockmod = SockMod1,
|
||||
socket = Socket1,
|
||||
default_host = DefaultHost,
|
||||
request_handlers = RequestHandlers},
|
||||
receive_headers(State).
|
||||
|
||||
@ -261,8 +265,9 @@ process_header(State, Data) ->
|
||||
[State#state.socket,
|
||||
State#state.request_method,
|
||||
element(2, State#state.request_path)]),
|
||||
{Host, Port, TP} = get_transfer_protocol(SockMod,
|
||||
{HostProvided, Port, TP} = get_transfer_protocol(SockMod,
|
||||
State#state.request_host),
|
||||
Host = get_host_really_served(State#state.default_host, HostProvided),
|
||||
State2 = State#state{request_host = Host,
|
||||
request_port = Port,
|
||||
request_tp = TP},
|
||||
@ -294,6 +299,14 @@ process_header(State, Data) ->
|
||||
add_header(Name, Value, State) ->
|
||||
[{Name, Value} | State#state.request_headers].
|
||||
|
||||
get_host_really_served(undefined, Provided) ->
|
||||
Provided;
|
||||
get_host_really_served(Default, Provided) ->
|
||||
case lists:member(Provided, ?MYHOSTS) of
|
||||
true -> Provided;
|
||||
false -> Default
|
||||
end.
|
||||
|
||||
%% @spec (SockMod, HostPort) -> {Host::string(), Port::integer(), TP}
|
||||
%% where
|
||||
%% SockMod = gen_tcp | tls
|
||||
|
Loading…
Reference in New Issue
Block a user