24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-20 22:22:09 +02:00

* src/web/ejabberd_http.erl: Include recognized headers in

request_headers as atoms, and others as strings (EJAB-778)

SVN Revision: 1678
This commit is contained in:
Badlop 2008-11-12 09:58:28 +00:00
parent add568169e
commit 9f110a6352
2 changed files with 22 additions and 12 deletions

View File

@ -1,5 +1,8 @@
2008-11-12 Badlop <badlop@process-one.net> 2008-11-12 Badlop <badlop@process-one.net>
* src/web/ejabberd_http.erl: Include recognized headers in
request_headers as atoms, and others as strings (EJAB-778)
* doc/guide.tex: Improve legibility of mod_irc example config * doc/guide.tex: Improve legibility of mod_irc example config
2008-11-10 Alexey Shchepin <alexey@process-one.net> 2008-11-10 Alexey Shchepin <alexey@process-one.net>

View File

@ -201,7 +201,7 @@ process_header(State, Data) ->
request_version = Version, request_version = Version,
request_path = Path, request_path = Path,
request_keepalive = KeepAlive}; request_keepalive = KeepAlive};
{ok, {http_header, _, 'Connection', _, Conn}} -> {ok, {http_header, _, 'Connection'=Name, _, Conn}} ->
KeepAlive1 = case jlib:tolower(Conn) of KeepAlive1 = case jlib:tolower(Conn) of
"keep-alive" -> "keep-alive" ->
true; true;
@ -210,23 +210,27 @@ process_header(State, Data) ->
_ -> _ ->
State#state.request_keepalive State#state.request_keepalive
end, end,
State#state{request_keepalive = KeepAlive1}; State#state{request_keepalive = KeepAlive1,
{ok, {http_header, _, 'Authorization', _, Auth}} -> request_headers=add_header(Name, Conn, State)};
State#state{request_auth = parse_auth(Auth)}; {ok, {http_header, _, 'Authorization'=Name, _, Auth}} ->
{ok, {http_header, _, 'Content-Length', _, SLen}} -> State#state{request_auth = parse_auth(Auth),
request_headers=add_header(Name, Auth, State)};
{ok, {http_header, _, 'Content-Length'=Name, _, SLen}} ->
case catch list_to_integer(SLen) of case catch list_to_integer(SLen) of
Len when is_integer(Len) -> Len when is_integer(Len) ->
State#state{request_content_length = Len}; State#state{request_content_length = Len,
request_headers=add_header(Name, SLen, State)};
_ -> _ ->
State State
end; end;
{ok, {http_header, _, 'Accept-Language', _, Langs}} -> {ok, {http_header, _, 'Accept-Language'=Name, _, Langs}} ->
State#state{request_lang = parse_lang(Langs)}; State#state{request_lang = parse_lang(Langs),
{ok, {http_header, _, 'Host', _, Host}} -> request_headers=add_header(Name, Langs, State)};
State#state{request_host = Host}; {ok, {http_header, _, 'Host'=Name, _, Host}} ->
State#state{request_host = Host,
request_headers=add_header(Name, Host, State)};
{ok, {http_header, _, Name, _, Value}} -> {ok, {http_header, _, Name, _, Value}} ->
Headers = [{Name, Value} | State#state.request_headers], State#state{request_headers=add_header(Name, Value, State)};
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,
@ -262,6 +266,9 @@ process_header(State, Data) ->
request_handlers = State#state.request_handlers} request_handlers = State#state.request_handlers}
end. end.
add_header(Name, Value, State) ->
[{Name, Value} | State#state.request_headers].
%% @spec (SockMod, HostPort) -> {Host::string(), Port::integer(), TP} %% @spec (SockMod, HostPort) -> {Host::string(), Port::integer(), TP}
%% where %% where
%% SockMod = gen_tcp | tls %% SockMod = gen_tcp | tls