| CODENOTIFIER | HelpYou are not signed inSign in |
Project: ejabberd
Revision: 1561
Author: badlop
Date: 12 Sep 2008 07:45:16
Changes: * 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
| ... | ...@@ -57,6 +57,10 @@ | |
| 57 | 57 | %% {request_handlers, [{["test", "module"], mod_test_web}]}]} |
| 58 | 58 | %% |
| 59 | 59 | request_handlers = [], |
| 60 | request_host, | |
| 61 | request_port, | |
| 62 | request_tp, | |
| 63 | request_headers = [], | |
| 60 | 64 | end_of_request = false, |
| 61 | 65 | trail = "" |
| 62 | 66 | }). |
| ... | ...@@ -218,16 +222,24 @@ | |
| 218 | 222 | end; |
| 219 | 223 | {ok, {http_header, _, 'Accept-Language', _, Langs}} -> |
| 220 | 224 | State#state{request_lang = parse_lang(Langs)}; |
| 221 | {ok, {http_header, _, _, _, _}} -> | |
| 222 | State; | |
| 225 | {ok, {http_header, _, 'Host', _, Host}} -> | |
| 226 | State#state{request_host = Host}; | |
| 227 | {ok, {http_header, _, Name, _, Value}} -> | |
| 228 | Headers = [{Name, Value} | State#state.request_headers], | |
| 229 | State#state{request_headers=Headers}; | |
| 223 | 230 | {ok, http_eoh} -> |
| 224 | 231 | ?DEBUG("(~w) http query: ~w ~s~n", |
| 225 | [State#state.socket, | |
| 226 | State#state.request_method, | |
| 227 | element(2, State#state.request_path)]), | |
| 228 | Out = process_request(State), | |
| 229 | send_text(State, Out), | |
| 230 | case State#state.request_keepalive of | |
| 232 | [State#state.socket, | |
| 233 | State#state.request_method, | |
| 234 | element(2, State#state.request_path)]), | |
| 235 | {Host, Port, TP} = get_transfer_protocol(SockMod, | |
| 236 | State#state.request_host), | |
| 237 | State2 = State#state{request_host = Host, | |
| 238 | request_port = Port, | |
| 239 | request_tp = TP}, | |
| 240 | Out = process_request(State2), | |
| 241 | send_text(State2, Out), | |
| 242 | case State2#state.request_keepalive of | |
| 231 | 243 | true -> |
| 232 | 244 | case SockMod of |
| 233 | 245 | gen_tcp -> |
| ... | ...@@ -250,6 +262,27 @@ | |
| 250 | 262 | request_handlers = State#state.request_handlers} |
| 251 | 263 | end. |
| 252 | 264 | |
| 265 | %% @spec (SockMod, HostPort) -> {Host::string(), Port::integer(), TP} | |
| 266 | %% where | |
| 267 | %% SockMod = gen_tcp | tls | |
| 268 | %% HostPort = string() | |
| 269 | %% TP = http | https | |
| 270 | %% @doc Given a socket and hostport header, return data of transfer protocol. | |
| 271 | %% Note that HostPort can be a string of a host like "example.org", | |
| 272 | %% or a string of a host and port like "example.org:5280". | |
| 273 | get_transfer_protocol(SockMod, HostPort) -> | |
| 274 | [Host | PortList] = string:tokens(HostPort, ":"), | |
| 275 | case {SockMod, PortList} of | |
| 276 | {gen_tcp, []} -> | |
| 277 | {Host, 80, http}; | |
| 278 | {gen_tcp, [Port]} -> | |
| 279 | {Host, Port, http}; | |
| 280 | {tls, []} -> | |
| 281 | {Host, 443, https}; | |
| 282 | {tls, [Port]} -> | |
| 283 | {Host, Port, https} | |
| 284 | end. | |
| 285 | ||
| 253 | 286 | %% XXX bard: search through request handlers looking for one that |
| 254 | 287 | %% matches the requested URL path, and pass control to it. If none is |
| 255 | 288 | %% found, answer with HTTP 404. |
| ... | ...@@ -276,6 +309,10 @@ | |
| 276 | 309 | request_auth = Auth, |
| 277 | 310 | request_lang = Lang, |
| 278 | 311 | request_handlers = RequestHandlers, |
| 312 | request_host = Host, | |
| 313 | request_port = Port, | |
| 314 | request_tp = TP, | |
| 315 | request_headers = RequestHeaders, | |
| 279 | 316 | sockmod = SockMod, |
| 280 | 317 | socket = Socket} = State) |
| 281 | 318 | when Method=:='GET' orelse Method=:='HEAD' orelse Method=:='DELETE' -> |
| ... | ...@@ -302,6 +339,10 @@ | |
| 302 | 339 | q = LQuery, |
| 303 | 340 | auth = Auth, |
| 304 | 341 | lang = Lang, |
| 342 | host = Host, | |
| 343 | port = Port, | |
| 344 | tp = TP, | |
| 345 | headers = RequestHeaders, | |
| 305 | 346 | ip = IP}, |
| 306 | 347 | %% XXX bard: This previously passed control to |
| 307 | 348 | %% ejabberd_web:process_get, now passes it to a local |
| ... | ...@@ -327,6 +368,10 @@ | |
| 327 | 368 | request_lang = Lang, |
| 328 | 369 | sockmod = SockMod, |
| 329 | 370 | socket = Socket, |
| 371 | request_host = Host, | |
| 372 | request_port = Port, | |
| 373 | request_tp = TP, | |
| 374 | request_headers = RequestHeaders, | |
| 330 | 375 | request_handlers = RequestHandlers} = State) |
| 331 | 376 | when (Method=:='POST' orelse Method=:='PUT') andalso is_integer(Len) -> |
| 332 | 377 | case SockMod of |
| ... | ...@@ -361,6 +406,10 @@ | |
| 361 | 406 | auth = Auth, |
| 362 | 407 | data = Data, |
| 363 | 408 | lang = Lang, |
| 409 | host = Host, | |
| 410 | port = Port, | |
| 411 | tp = TP, | |
| 412 | headers = RequestHeaders, | |
| 364 | 413 | ip = IP}, |
| 365 | 414 | case process(RequestHandlers, Request) of |
| 366 | 415 | El when element(1, El) == xmlelement -> |
| ... | ...@@ -26,5 +26,9 @@ | |
| 26 | 26 | auth, |
| 27 | 27 | lang = "", |
| 28 | 28 | data = "", |
| 29 | ip | |
| 29 | ip, | |
| 30 | host, % string() | |
| 31 | port, % integer() | |
| 32 | tp, % transfer protocol = http | https | |
| 33 | headers | |
| 30 | 34 | }). |
| ... | ...@@ -1,3 +1,9 @@ | |
| 1 | 2008-09-12 Badlop <badlop@process-one.net> | |
| 2 | ||
| 3 | * src/web/ejabberd_http.hrl: Provide Host, Port, Headers and | |
| 4 | Transfer Protocol in request (thanks to Eric Cestari)(EJAB-560) | |
| 5 | * src/web/ejabberd_http.erl: Likewise | |
| 6 | ||
| 1 | 7 | 2008-09-02 Badlop <badlop@process-one.net> |
| 2 | 8 | |
| 3 | 9 | * doc/guide.tex: Fix mod_proxy configuration example |