* 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:
parent
df39f93b80
commit
e9d62b39ef
|
@ -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>
|
2008-09-02 Badlop <badlop@process-one.net>
|
||||||
|
|
||||||
* doc/guide.tex: Fix mod_proxy configuration example
|
* doc/guide.tex: Fix mod_proxy configuration example
|
||||||
|
|
|
@ -57,6 +57,10 @@
|
||||||
%% {request_handlers, [{["test", "module"], mod_test_web}]}]}
|
%% {request_handlers, [{["test", "module"], mod_test_web}]}]}
|
||||||
%%
|
%%
|
||||||
request_handlers = [],
|
request_handlers = [],
|
||||||
|
request_host,
|
||||||
|
request_port,
|
||||||
|
request_tp,
|
||||||
|
request_headers = [],
|
||||||
end_of_request = false,
|
end_of_request = false,
|
||||||
trail = ""
|
trail = ""
|
||||||
}).
|
}).
|
||||||
|
@ -218,16 +222,24 @@ process_header(State, Data) ->
|
||||||
end;
|
end;
|
||||||
{ok, {http_header, _, 'Accept-Language', _, Langs}} ->
|
{ok, {http_header, _, 'Accept-Language', _, Langs}} ->
|
||||||
State#state{request_lang = parse_lang(Langs)};
|
State#state{request_lang = parse_lang(Langs)};
|
||||||
{ok, {http_header, _, _, _, _}} ->
|
{ok, {http_header, _, 'Host', _, Host}} ->
|
||||||
State;
|
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} ->
|
{ok, http_eoh} ->
|
||||||
?DEBUG("(~w) http query: ~w ~s~n",
|
?DEBUG("(~w) http query: ~w ~s~n",
|
||||||
[State#state.socket,
|
[State#state.socket,
|
||||||
State#state.request_method,
|
State#state.request_method,
|
||||||
element(2, State#state.request_path)]),
|
element(2, State#state.request_path)]),
|
||||||
Out = process_request(State),
|
{Host, Port, TP} = get_transfer_protocol(SockMod,
|
||||||
send_text(State, Out),
|
State#state.request_host),
|
||||||
case State#state.request_keepalive of
|
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 ->
|
true ->
|
||||||
case SockMod of
|
case SockMod of
|
||||||
gen_tcp ->
|
gen_tcp ->
|
||||||
|
@ -250,6 +262,27 @@ process_header(State, Data) ->
|
||||||
request_handlers = State#state.request_handlers}
|
request_handlers = State#state.request_handlers}
|
||||||
end.
|
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
|
%% 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
|
||||||
%% found, answer with HTTP 404.
|
%% found, answer with HTTP 404.
|
||||||
|
@ -276,6 +309,10 @@ process_request(#state{request_method = Method,
|
||||||
request_auth = Auth,
|
request_auth = Auth,
|
||||||
request_lang = Lang,
|
request_lang = Lang,
|
||||||
request_handlers = RequestHandlers,
|
request_handlers = RequestHandlers,
|
||||||
|
request_host = Host,
|
||||||
|
request_port = Port,
|
||||||
|
request_tp = TP,
|
||||||
|
request_headers = RequestHeaders,
|
||||||
sockmod = SockMod,
|
sockmod = SockMod,
|
||||||
socket = Socket} = State)
|
socket = Socket} = State)
|
||||||
when Method=:='GET' orelse Method=:='HEAD' orelse Method=:='DELETE' ->
|
when Method=:='GET' orelse Method=:='HEAD' orelse Method=:='DELETE' ->
|
||||||
|
@ -302,6 +339,10 @@ process_request(#state{request_method = Method,
|
||||||
q = LQuery,
|
q = LQuery,
|
||||||
auth = Auth,
|
auth = Auth,
|
||||||
lang = Lang,
|
lang = Lang,
|
||||||
|
host = Host,
|
||||||
|
port = Port,
|
||||||
|
tp = TP,
|
||||||
|
headers = RequestHeaders,
|
||||||
ip = IP},
|
ip = IP},
|
||||||
%% XXX bard: This previously passed control to
|
%% XXX bard: This previously passed control to
|
||||||
%% ejabberd_web:process_get, now passes it to a local
|
%% ejabberd_web:process_get, now passes it to a local
|
||||||
|
@ -327,6 +368,10 @@ process_request(#state{request_method = Method,
|
||||||
request_lang = Lang,
|
request_lang = Lang,
|
||||||
sockmod = SockMod,
|
sockmod = SockMod,
|
||||||
socket = Socket,
|
socket = Socket,
|
||||||
|
request_host = Host,
|
||||||
|
request_port = Port,
|
||||||
|
request_tp = TP,
|
||||||
|
request_headers = RequestHeaders,
|
||||||
request_handlers = RequestHandlers} = State)
|
request_handlers = RequestHandlers} = State)
|
||||||
when (Method=:='POST' orelse Method=:='PUT') andalso is_integer(Len) ->
|
when (Method=:='POST' orelse Method=:='PUT') andalso is_integer(Len) ->
|
||||||
case SockMod of
|
case SockMod of
|
||||||
|
@ -361,6 +406,10 @@ process_request(#state{request_method = Method,
|
||||||
auth = Auth,
|
auth = Auth,
|
||||||
data = Data,
|
data = Data,
|
||||||
lang = Lang,
|
lang = Lang,
|
||||||
|
host = Host,
|
||||||
|
port = Port,
|
||||||
|
tp = TP,
|
||||||
|
headers = RequestHeaders,
|
||||||
ip = IP},
|
ip = IP},
|
||||||
case process(RequestHandlers, Request) of
|
case process(RequestHandlers, Request) of
|
||||||
El when element(1, El) == xmlelement ->
|
El when element(1, El) == xmlelement ->
|
||||||
|
|
|
@ -26,5 +26,9 @@
|
||||||
auth,
|
auth,
|
||||||
lang = "",
|
lang = "",
|
||||||
data = "",
|
data = "",
|
||||||
ip
|
ip,
|
||||||
|
host, % string()
|
||||||
|
port, % integer()
|
||||||
|
tp, % transfer protocol = http | https
|
||||||
|
headers
|
||||||
}).
|
}).
|
||||||
|
|
Loading…
Reference in New Issue