%% {request_handlers, [{["test", "module"], mod_test_web}]}]}
%%
request_handlers = [],
+ request_host,
+ request_port,
+ request_tp,
+ request_headers = [],
end_of_request = false,
trail = ""
}).
end;
{ok, {http_header, _, 'Accept-Language', _, Langs}} ->
State#state{request_lang = parse_lang(Langs)};
- {ok, {http_header, _, _, _, _}} ->
- State;
+ {ok, {http_header, _, 'Host', _, Host}} ->
+ State#state{request_host = Host};
+ {ok, {http_header, _, Name, _, Value}} ->
+ Headers = [{Name, Value} | State#state.request_headers],
+ State#state{request_headers=Headers};
{ok, http_eoh} ->
?DEBUG("(~w) http query: ~w ~s~n",
- [State#state.socket,
- State#state.request_method,
- element(2, State#state.request_path)]),
- Out = process_request(State),
- send_text(State, Out),
- case State#state.request_keepalive of
+ [State#state.socket,
+ State#state.request_method,
+ element(2, State#state.request_path)]),
+ {Host, Port, TP} = get_transfer_protocol(SockMod,
+ State#state.request_host),
+ State2 = State#state{request_host = Host,
+ request_port = Port,
+ request_tp = TP},
+ Out = process_request(State2),
+ send_text(State2, Out),
+ case State2#state.request_keepalive of
true ->
case SockMod of
gen_tcp ->
request_handlers = State#state.request_handlers}
end.
+%% @spec (SockMod, HostPort) -> {Host::string(), Port::integer(), TP}
+%% where
+%% SockMod = gen_tcp | tls
+%% HostPort = string()
+%% TP = http | https
+%% @doc Given a socket and hostport header, return data of transfer protocol.
+%% Note that HostPort can be a string of a host like "example.org",
+%% or a string of a host and port like "example.org:5280".
+get_transfer_protocol(SockMod, HostPort) ->
+ [Host | PortList] = string:tokens(HostPort, ":"),
+ case {SockMod, PortList} of
+ {gen_tcp, []} ->
+ {Host, 80, http};
+ {gen_tcp, [Port]} ->
+ {Host, Port, http};
+ {tls, []} ->
+ {Host, 443, https};
+ {tls, [Port]} ->
+ {Host, Port, https}
+ end.
+
%% XXX bard: search through request handlers looking for one that
%% matches the requested URL path, and pass control to it. If none is
%% found, answer with HTTP 404.
request_auth = Auth,
request_lang = Lang,
request_handlers = RequestHandlers,
+ request_host = Host,
+ request_port = Port,
+ request_tp = TP,
+ request_headers = RequestHeaders,
sockmod = SockMod,
socket = Socket} = State)
when Method=:='GET' orelse Method=:='HEAD' orelse Method=:='DELETE' ->
q = LQuery,
auth = Auth,
lang = Lang,
+ host = Host,
+ port = Port,
+ tp = TP,
+ headers = RequestHeaders,
ip = IP},
%% XXX bard: This previously passed control to
%% ejabberd_web:process_get, now passes it to a local
request_lang = Lang,
sockmod = SockMod,
socket = Socket,
+ request_host = Host,
+ request_port = Port,
+ request_tp = TP,
+ request_headers = RequestHeaders,
request_handlers = RequestHandlers} = State)
when (Method=:='POST' orelse Method=:='PUT') andalso is_integer(Len) ->
case SockMod of
auth = Auth,
data = Data,
lang = Lang,
+ host = Host,
+ port = Port,
+ tp = TP,
+ headers = RequestHeaders,
ip = IP},
case process(RequestHandlers, Request) of
El when element(1, El) == xmlelement ->