* src/web/ejabberd_http.hrl: Provide Host, Port, Headers and

Transfer Protocol in request (thanks to Eric Cestari)(EJAB-560)
* src/web/ejabberd_http.erl: Likewise

SVN Revision: 1561
This commit is contained in:
Badlop 2008-09-12 11:45:16 +00:00
parent df39f93b80
commit e9d62b39ef
3 changed files with 68 additions and 9 deletions

View File

@ -1,3 +1,9 @@
2008-09-12 Badlop <badlop@process-one.net>
* src/web/ejabberd_http.hrl: Provide Host, Port, Headers and
Transfer Protocol in request (thanks to Eric Cestari)(EJAB-560)
* src/web/ejabberd_http.erl: Likewise
2008-09-02 Badlop <badlop@process-one.net>
* doc/guide.tex: Fix mod_proxy configuration example

View File

@ -57,6 +57,10 @@
%% {request_handlers, [{["test", "module"], mod_test_web}]}]}
%%
request_handlers = [],
request_host,
request_port,
request_tp,
request_headers = [],
end_of_request = false,
trail = ""
}).
@ -218,16 +222,24 @@ process_header(State, Data) ->
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 ->
@ -250,6 +262,27 @@ process_header(State, Data) ->
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.
@ -276,6 +309,10 @@ process_request(#state{request_method = Method,
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' ->
@ -302,6 +339,10 @@ process_request(#state{request_method = Method,
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
@ -327,6 +368,10 @@ process_request(#state{request_method = Method,
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
@ -361,6 +406,10 @@ process_request(#state{request_method = Method,
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 ->

View File

@ -26,5 +26,9 @@
auth,
lang = "",
data = "",
ip
ip,
host, % string()
port, % integer()
tp, % transfer protocol = http | https
headers
}).