summaryrefslogtreecommitdiff
path: root/lib/inets/src
diff options
context:
space:
mode:
authorJakub Witczak <kuba@erlang.org>2021-09-06 10:10:31 +0200
committerJakub Witczak <kuba@erlang.org>2021-09-06 16:54:11 +0200
commit08f5ac3f83dd30393ae13f393d504d5f686951c3 (patch)
treee084cc78ef189a98e0e1fe7de3aa7b8fada8baa2 /lib/inets/src
parent111b86355fad10659573b1c01aaac85c64a62c81 (diff)
downloaderlang-08f5ac3f83dd30393ae13f393d504d5f686951c3.tar.gz
inets: fix for HTTP headers handling for mod_esi
Diffstat (limited to 'lib/inets/src')
-rw-r--r--lib/inets/src/http_server/httpd_example.erl19
-rw-r--r--lib/inets/src/http_server/httpd_script_env.erl36
2 files changed, 40 insertions, 15 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 aa50538ec2..04ca069f5e 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([]) ->