diff options
author | Jakub Witczak <kuba@erlang.org> | 2021-09-06 14:59:15 +0200 |
---|---|---|
committer | Jakub Witczak <kuba@erlang.org> | 2021-09-06 15:17:51 +0200 |
commit | 9f43ff620a2d308f51962487e025dc5c7c2e457f (patch) | |
tree | 495ac38279d612220cfa4cfe08be9f63eac58415 /lib/inets | |
parent | 163593593441984f8446f513bdc7684ac5fe067e (diff) | |
download | erlang-9f43ff620a2d308f51962487e025dc5c7c2e457f.tar.gz |
inets: fix for HTTP headers handling for mod_esi
Diffstat (limited to 'lib/inets')
-rw-r--r-- | lib/inets/src/http_server/httpd_example.erl | 19 | ||||
-rw-r--r-- | lib/inets/src/http_server/httpd_script_env.erl | 36 | ||||
-rw-r--r-- | lib/inets/test/httpd_SUITE.erl | 13 |
3 files changed, 52 insertions, 16 deletions
diff --git a/lib/inets/src/http_server/httpd_example.erl b/lib/inets/src/http_server/httpd_example.erl index bb048e2410..6e0ad68f45 100644 --- a/lib/inets/src/http_server/httpd_example.erl +++ b/lib/inets/src/http_server/httpd_example.erl @@ -22,6 +22,7 @@ -export([print/3, get/3, + get_reply_headers/3, put/3, patch/3, post/3, @@ -78,6 +79,24 @@ do_get(_Env,[]) -> do_get(Env,Input) -> default(Env,Input). %% ------------------------------------------------------ +get_reply_headers(SessionID, Env, Input) -> + mod_esi:deliver(SessionID, do_get_reply_headers(Env, Input)). +do_get_reply_headers(Env,[]) -> + EncodingVal = proplists:get_value(http_accept_encoding, Env), + Other = proplists:get_value(http_other, Env), + NotExistingVal = proplists:get_value("notexistingheader_1", Other), + [header("text/html", "Accept-Encoding: " ++ EncodingVal ++ " \r\n" ++ + "NotExistingheader_1: " ++ NotExistingVal ++ " \r\n"), + top("GET Example"), + "<FORM ACTION=\"/cgi-bin/erl/httpd_example:get\" METHOD=GET> +<B>Input:</B> <INPUT TYPE=\"text\" NAME=\"input1\"> +<INPUT TYPE=\"text\" NAME=\"input2\"> +<INPUT TYPE=\"submit\"><BR> +</FORM>" ++ "\n", + footer()]; +do_get_reply_headers(Env,Input) -> + default(Env,Input). +%% ------------------------------------------------------ put(SessionID, Env, Input) -> mod_esi:deliver(SessionID, do_put(Env, Input)). diff --git a/lib/inets/src/http_server/httpd_script_env.erl b/lib/inets/src/http_server/httpd_script_env.erl index bb81b93bc0..d3c7b5e1c6 100644 --- a/lib/inets/src/http_server/httpd_script_env.erl +++ b/lib/inets/src/http_server/httpd_script_env.erl @@ -111,37 +111,43 @@ create_basic_elements(cgi, ModData) -> {"SCRIPT_NAME", which_request_uri(ModData)}]. create_http_header_elements(ScriptType, Headers) -> - create_http_header_elements(ScriptType, Headers, []). + create_http_header_elements(ScriptType, Headers, [], []). -create_http_header_elements(_, [], Acc) -> +create_http_header_elements(esi, [], Acc, OtherAcc) -> + [{http_other, OtherAcc} | Acc]; +create_http_header_elements(_, [], Acc, _OtherAcc) -> Acc; create_http_header_elements(ScriptType, [{Name, [Value | _] = Values } | - Headers], Acc) + Headers], Acc, OtherAcc) when is_list(Value) -> - NewName = lists:map(fun(X) -> if X == $- -> $_; true -> X end end, Name), - try http_env_element(ScriptType, NewName, multi_value(Values)) of + try http_env_element(ScriptType, Name, multi_value(Values)) of Element -> - create_http_header_elements(ScriptType, Headers, [Element | Acc]) + create_http_header_elements(ScriptType, Headers, [Element | Acc], + OtherAcc) catch _:_ -> - create_http_header_elements(ScriptType, Headers, Acc) + create_http_header_elements(ScriptType, Headers, Acc, + [{Name, Values} | OtherAcc]) end; -create_http_header_elements(ScriptType, [{Name, Value} | Headers], Acc) +create_http_header_elements(ScriptType, [{Name, Value} | Headers], Acc, OtherAcc) when is_list(Value) -> - NewName = re:replace(Name,"-","_", [{return,list}, global]), - try http_env_element(ScriptType, NewName, Value) of + try http_env_element(ScriptType, Name, Value) of Element -> - create_http_header_elements(ScriptType, Headers, [Element | Acc]) + create_http_header_elements(ScriptType, Headers, [Element | Acc], + OtherAcc) catch _:_ -> - create_http_header_elements(ScriptType, Headers, Acc) + create_http_header_elements(ScriptType, Headers, Acc, + [{Name, Value} | OtherAcc]) end. -http_env_element(cgi, VarName, Value) -> +http_env_element(cgi, VarName0, Value) -> + VarName = re:replace(VarName0,"-","_", [{return,list}, global]), {"HTTP_"++ http_util:to_upper(VarName), Value}; -http_env_element(esi, VarName, Value) -> +http_env_element(esi, VarName0, Value) -> + list_to_existing_atom(VarName0), + VarName = re:replace(VarName0,"-","_", [{return,list}, global]), HeaderName = http_util:to_lower(VarName), - list_to_existing_atom(HeaderName), {list_to_atom("http_"++ HeaderName), Value}. multi_value([]) -> diff --git a/lib/inets/test/httpd_SUITE.erl b/lib/inets/test/httpd_SUITE.erl index 7c4d4b65e6..c1fe1fdae2 100644 --- a/lib/inets/test/httpd_SUITE.erl +++ b/lib/inets/test/httpd_SUITE.erl @@ -132,7 +132,8 @@ groups() -> {http_1_1, [], [host, chunked, expect, cgi, cgi_chunked_encoding_test, trace, range, if_modified_since, mod_esi_chunk_timeout, - esi_put, esi_patch, esi_post, esi_proagate, esi_atom_leak] ++ http_head() ++ http_get() ++ load()}, + esi_put, esi_patch, esi_post, esi_proagate, esi_atom_leak, esi_headers] + ++ http_head() ++ http_get() ++ load()}, {http_1_0, [], [host, cgi, trace] ++ http_head() ++ http_get() ++ load()}, {http_rel_path_script_alias, [], [cgi]}, {not_sup, [], [put_not_sup]} @@ -992,6 +993,16 @@ esi_atom_leak(Config) when is_list(Config) -> true = IsStable(AtomCount3). %%------------------------------------------------------------------------- +esi_headers() -> + [{doc, "Test mod_esi HTTP headers support"}]. + +esi_headers(Config) when is_list(Config) -> + ok = http_status("GET /cgi-bin/erl/httpd_example:get_reply_headers ", + {"Accept-Encoding: gzip \r\nNotExistingHeader_1: 100 \r\n", ""}, + Config, [{statuscode, 200}, {header, "notexistingheader_1", "100"}, + {header, "accept-encoding", "gzip"}]). + +%%------------------------------------------------------------------------- cgi() -> [{doc, "Test mod_cgi"}]. |