diff options
Diffstat (limited to 'lib/inets/src')
-rw-r--r-- | lib/inets/src/http_client/httpc_handler.erl | 2 | ||||
-rw-r--r-- | lib/inets/src/http_client/httpc_manager.erl | 35 | ||||
-rw-r--r-- | lib/inets/src/http_lib/http_uri.erl | 8 | ||||
-rw-r--r-- | lib/inets/src/http_server/httpd.erl | 17 | ||||
-rw-r--r-- | lib/inets/src/http_server/httpd_example.erl | 151 | ||||
-rw-r--r-- | lib/inets/src/http_server/httpd_request.erl | 30 | ||||
-rw-r--r-- | lib/inets/src/http_server/httpd_request_handler.erl | 8 | ||||
-rw-r--r-- | lib/inets/src/http_server/httpd_util.erl | 115 | ||||
-rw-r--r-- | lib/inets/src/http_server/mod_dir.erl | 4 | ||||
-rw-r--r-- | lib/inets/src/http_server/mod_esi.erl | 123 | ||||
-rw-r--r-- | lib/inets/src/inets_app/inets.app.src | 4 |
11 files changed, 183 insertions, 314 deletions
diff --git a/lib/inets/src/http_client/httpc_handler.erl b/lib/inets/src/http_client/httpc_handler.erl index b1c5cf13bb..3f91ae062c 100644 --- a/lib/inets/src/http_client/httpc_handler.erl +++ b/lib/inets/src/http_client/httpc_handler.erl @@ -1637,7 +1637,7 @@ host_header(#http_request_h{host = Host}, _) -> %% Handles headers_as_is host_header(_, URI) -> - {ok, {_, _, Host, _, _, _}} = http_uri:parse(URI), + #{host := Host} = uri_string:parse(URI), Host. tls_upgrade(#state{status = diff --git a/lib/inets/src/http_client/httpc_manager.erl b/lib/inets/src/http_client/httpc_manager.erl index 0dc0483fa9..ba561100a1 100644 --- a/lib/inets/src/http_client/httpc_manager.erl +++ b/lib/inets/src/http_client/httpc_manager.erl @@ -472,10 +472,10 @@ handle_call(which_cookies, _, #state{cookie_db = CookieDb} = State) -> handle_call({which_cookies, Url, Options}, _, #state{cookie_db = CookieDb} = State) -> ?hcrv("which cookies", [{url, Url}, {options, Options}]), - case uri_parse(Url, Options) of - {ok, {Scheme, _, Host, Port, Path, _}} -> + case uri_parse(Url) of + {ok, {Scheme, Host, Port, Path}} -> CookieHeaders = - httpc_cookie:header(CookieDb, Scheme, {Host, Port}, Path), + httpc_cookie:header(CookieDb, erlang:list_to_existing_atom(Scheme), {Host, Port}, Path), {reply, CookieHeaders, State}; {error, _} = ERROR -> {reply, ERROR, State} @@ -948,14 +948,31 @@ make_db_name(ProfileName, Post) -> %%-------------------------------------------------------------------------- %% These functions is just simple wrappers to parse specifically HTTP URIs %%-------------------------------------------------------------------------- +uri_parse(URI) -> + case uri_string:parse(uri_string:normalize(URI)) of + #{scheme := Scheme, + host := Host, + port := Port, + path := Path} -> + {ok, {Scheme, Host, Port, Path}}; + #{scheme := Scheme, + host := Host, + path := Path} -> + {ok, {Scheme, Host, scheme_default_port(Scheme), Path}}; + Other -> + {error, maybe_error(Other)} + end. -scheme_defaults() -> - [{http, 80}, {https, 443}]. - -uri_parse(URI, Opts) -> - http_uri:parse(URI, [{scheme_defaults, scheme_defaults()} | Opts]). - +maybe_error({error, Atom, Term}) -> + {Atom, Term}; +maybe_error(Other) -> + {unexpected, Other}. +scheme_default_port("http") -> + 80; +scheme_default_port("https") -> + 443. + %%-------------------------------------------------------------------------- diff --git a/lib/inets/src/http_lib/http_uri.erl b/lib/inets/src/http_lib/http_uri.erl index 6805b0293d..f9a4c697c1 100644 --- a/lib/inets/src/http_lib/http_uri.erl +++ b/lib/inets/src/http_lib/http_uri.erl @@ -61,6 +61,14 @@ scheme_defaults/0, encode/1, decode/1]). + +-deprecated({parse, 1, next_major_release}). +-deprecated({parse, 2, next_major_release}). +-deprecated({encode, 1, next_major_release}). +-deprecated({decode, 1, next_major_release}). +-deprecated({scheme_defaults, 0, next_major_release}). + + -export_type([uri/0, user_info/0, scheme/0, default_scheme_port_number/0, diff --git a/lib/inets/src/http_server/httpd.erl b/lib/inets/src/http_server/httpd.erl index 66e2c2400d..08f2dfdc16 100644 --- a/lib/inets/src/http_server/httpd.erl +++ b/lib/inets/src/http_server/httpd.erl @@ -44,13 +44,14 @@ info/3 ]). +-deprecated({parse_query, 1, next_major_release}). + %%%======================================================================== %%% API %%%======================================================================== parse_query(String) -> - SplitString = re:split(String,"[&;]", [{return, list}]), - foreach(SplitString). + uri_string:dissect_query(String). reload_config(Config = [Value| _], Mode) when is_tuple(Value) -> do_reload_config(Config, Mode); @@ -252,18 +253,6 @@ unblock(Addr, Port, Profile) when is_integer(Port) -> {error,not_started} end. -foreach([]) -> - []; -foreach([KeyValue|Rest]) -> - Plus2Space = re:replace(KeyValue,"[\+]"," ", [{return,list}, global]), - case re:split(Plus2Space,"=", [{return, list}]) of - [Key|Value] -> - [{http_uri:decode(Key), - http_uri:decode(lists:flatten(Value))}|foreach(Rest)]; - _ -> - foreach(Rest) - end. - make_name(Addr, Port, Profile) -> httpd_util:make_name("httpd", Addr, Port, Profile). diff --git a/lib/inets/src/http_server/httpd_example.erl b/lib/inets/src/http_server/httpd_example.erl index 3c25ca336f..78b781aa96 100644 --- a/lib/inets/src/http_server/httpd_example.erl +++ b/lib/inets/src/http_server/httpd_example.erl @@ -19,13 +19,27 @@ %% %% -module(httpd_example). --export([print/1]). --export([get/2, put/2, post/2, yahoo/2, test1/2, get_bin/2, peer/2,new_status_and_location/2]). --export([newformat/3, post_chunked/3, post_204/3, ignore_invalid_header/3]). -%% These are used by the inets test-suite --export([delay/1, chunk_timeout/3, get_chunks/3]). +-export([print/3, + get/3, + put/3, + post/3, + yahoo/3, + test1/3, + get_bin/3, + peer/3, + new_status_and_location/3, + newformat/3, + post_chunked/3, + post_204/3, + ignore_invalid_header/3, + delay/3, + chunk_timeout/3, + get_chunks/3]). +%% ------------------------------------------------------ +print(SessionID, _Env, Input) -> + mod_esi:deliver(SessionID, print(Input)). print(String) -> [header(), @@ -33,7 +47,11 @@ print(String) -> String++"\n", footer()]. -test1(Env, []) -> +%% ------------------------------------------------------ +test1(SessionID, Env, _Input) -> + mod_esi:deliver(SessionID, test1(Env)). + +test1(Env) -> io:format("Env:~p~n",[Env]), ["<html>", "<head>", @@ -44,9 +62,10 @@ test1(Env, []) -> "<h2>Stuff</h2>", "</body>", "</html>"]. - - -get(_Env,[]) -> +%% ------------------------------------------------------ +get(SessionID, Env, Input) -> + mod_esi:deliver(SessionID, do_get(Env, Input)). +do_get(_Env,[]) -> [header(), top("GET Example"), "<FORM ACTION=\"/cgi-bin/erl/httpd_example:get\" METHOD=GET> @@ -55,24 +74,35 @@ get(_Env,[]) -> <INPUT TYPE=\"submit\"><BR> </FORM>" ++ "\n", footer()]; - -get(Env,Input) -> +do_get(Env,Input) -> default(Env,Input). +%% ------------------------------------------------------ +put(SessionID, Env, Input) -> + mod_esi:deliver(SessionID, do_put(Env, Input)). -put(Env,{Input,_Body}) -> +do_put(Env,{Input,_Body}) -> default(Env,Input); -put(Env,Input) -> +do_put(Env,Input) -> default(Env,Input). +%% ------------------------------------------------------ +get_bin(SessionID, Env, Input) -> + Header = header(), + IoData = get_bin(Env, Input), + Size = erlang:iolist_size(IoData), + mod_esi:deliver(SessionID, ["Content-Length:" ++ erlang:integer_to_list(Size) ++ "\r\n", + Header, IoData]). get_bin(_Env,_Input) -> - [list_to_binary(header()), - list_to_binary(top("GET Example")), + [list_to_binary(top("GET Example")), list_to_binary("<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"), list_to_binary(footer())]. +%% ------------------------------------------------------ +post(SessionID, Env, Input) -> + mod_esi:deliver(SessionID, post(Env, Input)). post(_Env,[]) -> [header(), @@ -86,21 +116,22 @@ post(_Env,[]) -> post(Env,Input) -> default(Env,Input). +%% ------------------------------------------------------ +yahoo(SessionID, Env, Input) -> + mod_esi:deliver(SessionID, yahoo(Env, Input)). yahoo(_Env,_Input) -> "Location: http://www.yahoo.com\r\n\r\n". +%% ------------------------------------------------------ +new_status_and_location(SessionID, Env, Input) -> + mod_esi:deliver(SessionID, new_status_and_location(Env, Input)). new_status_and_location(_Env,_Input) -> "status:201 Created\r\n Location: http://www.yahoo.com\r\n\r\n". +%% ------------------------------------------------------ -default(Env,Input) -> - [header(), - top("Default Example"), - "<B>Environment:</B> ",io_lib:format("~p",[Env]),"<BR>\n", - "<B>Input:</B> ",Input,"<BR>\n", - "<B>Parsed Input:</B> ", - io_lib:format("~p",[httpd:parse_query(Input)]),"\n", - footer()]. +peer(SessionID, Env, Input) -> + mod_esi:deliver(SessionID, peer(Env, Input)). peer(Env, _Input) -> Header = @@ -116,23 +147,7 @@ peer(Env, _Input) -> io_lib:format("~p",[proplists:get_value(peer_cert, Env)]),"\n", footer()]. -header() -> - header("text/html"). -header(MimeType) -> - "Content-type: " ++ MimeType ++ "\r\n\r\n". -header(MimeType, Other) -> - "Content-type: " ++ MimeType ++ "\r\n" ++ Other ++ "\r\n\r\n". - -top(Title) -> - "<HTML> -<HEAD> -<TITLE>" ++ Title ++ "</TITLE> -</HEAD> -<BODY>\n". - -footer() -> - "</BODY> -</HTML>\n". +%% ------------------------------------------------------ post_chunked(_SessionID, _Env, {first, _Body} = _Bodychunk) -> {continue, {state, 1}}; @@ -150,11 +165,13 @@ post_chunked(SessionID, _Env, {last, _Body, undefined} = _Bodychunk) -> mod_esi:deliver(SessionID, footer()); post_chunked(_, _, _Body) -> exit(body_not_chunked). +%% ------------------------------------------------------ post_204(SessionID, _Env, _Input) -> mod_esi:deliver(SessionID, ["Status: 204 No Content" ++ "\r\n\r\n"]), mod_esi:deliver(SessionID, []). +%% ------------------------------------------------------ ignore_invalid_header(SessionID, Env, _Input) -> case proplists:get_value(content_length, Env, undefined) of @@ -165,7 +182,8 @@ ignore_invalid_header(SessionID, Env, _Input) -> mod_esi:deliver(SessionID, ["Status: 500 Internal Server Error" ++ "\r\n\r\n"]) end. - +%% ------------------------------------------------------ + newformat(SessionID,_,_) -> mod_esi:deliver(SessionID, "Content-Type:text/html\r\n\r\n"), mod_esi:deliver(SessionID, top("new esi format test")), @@ -176,28 +194,16 @@ newformat(SessionID,_,_) -> %% ------------------------------------------------------ -delay(Time) when is_integer(Time) -> - i("httpd_example:delay(~p) -> do the delay",[Time]), - sleep(Time), - i("httpd_example:delay(~p) -> done, now reply",[Time]), - delay_reply("delay ok"); -delay(Time) when is_list(Time) -> - delay(list_to_integer(Time)); -delay({error,_Reason}) -> - i("delay -> called with invalid time"), - delay_reply("delay failed: invalid delay time"). +delay(SessionID,_, _) -> + sleep(10000), + Reply = delay_reply("delay ok"), + mod_esi:deliver(SessionID, Reply). delay_reply(Reply) -> [header(), top("delay"), Reply, footer()]. - -i(F) -> i(F,[]). -i(F,A) -> io:format(F ++ "~n",A). - -sleep(T) -> receive after T -> ok end. - %% ------------------------------------------------------ chunk_timeout(SessionID, _, _StrInt) -> @@ -224,3 +230,34 @@ get_chunks(Sid, _Env, In) -> mod_esi:deliver(Sid, io_lib:format("Chunk ~p ms\r\n", [ChunkDelay])), timer:sleep(ChunkDelay + BadChunkDelay), mod_esi:deliver(Sid, "BAD Chunk\r\n"). + +%% ------------------------------------------------------ +default(Env,Input) -> + [header(), + top("Default Example"), + "<B>Environment:</B> ",io_lib:format("~p",[Env]),"<BR>\n", + "<B>Input:</B> ",Input,"<BR>\n", + "<B>Parsed Input:</B> ", + io_lib:format("~p",[uri_string:dissect_query(Input)]),"\n", + footer()]. + +header() -> + header("text/html"). +header(MimeType) -> + "Content-type: " ++ MimeType ++ "\r\n\r\n". +header(MimeType, Other) -> + "Content-type: " ++ MimeType ++ "\r\n" ++ Other ++ "\r\n\r\n". + +top(Title) -> + "<HTML> +<HEAD> +<TITLE>" ++ Title ++ "</TITLE> +</HEAD> +<BODY>\n". + +footer() -> + "</BODY> +</HTML>\n". + +sleep(T) -> receive after T -> ok end. + diff --git a/lib/inets/src/http_server/httpd_request.erl b/lib/inets/src/http_server/httpd_request.erl index 3df55c0f7a..958b122255 100644 --- a/lib/inets/src/http_server/httpd_request.erl +++ b/lib/inets/src/http_server/httpd_request.erl @@ -340,31 +340,13 @@ whole_body(Body, Length) -> %% Prevent people from trying to access directories/files %% relative to the ServerRoot. validate_uri(RequestURI) -> - UriNoQueryNoHex = - case string:str(RequestURI, "?") of - 0 -> - (catch http_uri:decode(RequestURI)); - Ndx -> - (catch http_uri:decode(string:left(RequestURI, Ndx))) - end, - case UriNoQueryNoHex of - {'EXIT', _Reason} -> - {error, {bad_request, {malformed_syntax, RequestURI}}}; - _ -> - Path = format_request_uri(UriNoQueryNoHex), - Path2 = [X||X<-string:tokens(Path, "/"),X=/="."], %% OTP-5938 - validate_path(Path2, 0, RequestURI) + case uri_string:normalize(RequestURI) of + {error, _, _} -> + {error, {bad_request, {malformed_syntax, RequestURI}}}; + URI -> + {ok, URI} end. - -validate_path([], _, _) -> - ok; -validate_path([".." | _], 0, RequestURI) -> - {error, {bad_request, {forbidden, RequestURI}}}; -validate_path([".." | Rest], N, RequestURI) -> - validate_path(Rest, N - 1, RequestURI); -validate_path([_ | Rest], N, RequestURI) -> - validate_path(Rest, N + 1, RequestURI). - + validate_version("HTTP/1.1") -> true; validate_version("HTTP/1.0") -> diff --git a/lib/inets/src/http_server/httpd_request_handler.erl b/lib/inets/src/http_server/httpd_request_handler.erl index e48555f4d7..e82b1c46e9 100644 --- a/lib/inets/src/http_server/httpd_request_handler.erl +++ b/lib/inets/src/http_server/httpd_request_handler.erl @@ -400,9 +400,9 @@ handle_http_msg({_, _, Version, {_, _}, _}, handle_http_msg({Method, Uri, Version, {RecordHeaders, Headers}, Body}, #state{status = accept, mod = ModData} = State) -> case httpd_request:validate(Method, Uri, Version) of - ok -> + {ok, NormalizedURI} -> {ok, NewModData} = - httpd_request:update_mod_data(ModData, Method, Uri, + httpd_request:update_mod_data(ModData, Method, NormalizedURI, Version, Headers), case is_host_specified_if_required(NewModData#mod.absolute_uri, @@ -421,10 +421,6 @@ handle_http_msg({Method, Uri, Version, {RecordHeaders, Headers}, Body}, httpd_response:send_status(ModData#mod{http_version = Version}, 501, {Method, Uri, Version}, {not_sup, What}), {stop, normal, State#state{response_sent = true}}; - {error, {bad_request, {forbidden, URI}}} -> - httpd_response:send_status(ModData#mod{http_version = Version}, - 403, URI), - {stop, normal, State#state{response_sent = true}}; {error, {bad_request, {malformed_syntax, URI}}} -> httpd_response:send_status(ModData#mod{http_version = Version}, 400, URI, {malformed_syntax, URI}), diff --git a/lib/inets/src/http_server/httpd_util.erl b/lib/inets/src/http_server/httpd_util.erl index 6b3b2c9660..05cff30243 100644 --- a/lib/inets/src/http_server/httpd_util.erl +++ b/lib/inets/src/http_server/httpd_util.erl @@ -167,7 +167,7 @@ reason_phrase(_) -> "Internal Server Error". %% message message(301,URL,_) -> - "The document has moved <A HREF=\""++ maybe_encode(URL) ++"\">here</A>."; + "The document has moved <A HREF=\""++ html_encode(uri_string:normalize(URL)) ++"\">here</A>."; message(304, _URL,_) -> "The document has not been changed."; message(400, none, _) -> @@ -184,11 +184,11 @@ browser doesn't understand how to supply the credentials required."; message(403,RequestURI,_) -> "You don't have permission to access " ++ - html_encode(RequestURI) ++ + html_encode(uri_string:normalize(RequestURI)) ++ " on this server."; message(404,RequestURI,_) -> "The requested URL " ++ - html_encode(RequestURI) ++ + html_encode(uri_string:normalize(RequestURI)) ++ " was not found on this server."; message(408, Timeout, _) -> Timeout; @@ -212,7 +212,7 @@ message(501,{Method, RequestURI, HTTPVersion}, _ConfigDB) -> is_atom(Method) -> atom_to_list(Method) ++ " to " ++ - html_encode(RequestURI) ++ + html_encode(uri_string:normalize(RequestURI)) ++ " (" ++ HTTPVersion ++ ") not supported."; is_list(Method) -> Method ++ @@ -225,23 +225,9 @@ message(503, String, _ConfigDB) -> "This service in unavailable due to: " ++ html_encode(String); message(_, ReasonPhrase, _) -> html_encode(ReasonPhrase). - -maybe_encode(URI) -> - Decoded = try http_uri:decode(URI) of - N -> N - catch - error:_ -> URI - end, - http_uri:encode(Decoded). - + html_encode(String) -> - try http_uri:decode(String) of - Decoded when is_list(Decoded) -> - http_util:html_encode(Decoded) - catch - _:_ -> - http_util:html_encode(String) - end. + http_util:html_encode(String). %%convert_rfc_date(Date)->{{YYYY,MM,DD},{HH,MIN,SEC}} @@ -422,21 +408,26 @@ flatlength([],L) -> %% split_path -split_path(Path) -> - case re:run(Path,"[\?].*\$", [{capture, first}]) of - %% A QUERY_STRING exists! - {match,[{Start,Length}]} -> - {http_uri:decode(string:substr(Path,1,Start)), - string:substr(Path,Start+1,Length)}; - %% A possible PATH_INFO exists! - nomatch -> - split_path(Path,[]) +split_path(URI) -> + case uri_string:normalize(URI, [return_map]) of + #{fragment := Fragment, + path := Path, + query := Query} -> + {Path, add_hashmark(Query, Fragment)}; + #{path := Path, + query := Query} -> + {Path, Query}; + #{path := Path} -> + split_path(Path, []) end. +add_hashmark(Query, Fragment) -> + Query ++ "#" ++ Fragment. + split_path([],SoFar) -> - {http_uri:decode(lists:reverse(SoFar)),[]}; + {lists:reverse(SoFar),[]}; split_path([$/|Rest],SoFar) -> - Path=http_uri:decode(lists:reverse(SoFar)), + Path=lists:reverse(SoFar), case file:read_file_info(Path) of {ok,FileInfo} when FileInfo#file_info.type =:= regular -> {Path,[$/|Rest]}; @@ -450,56 +441,20 @@ split_path([C|Rest],SoFar) -> %% split_script_path -split_script_path(Path) -> - case split_script_path(Path, []) of - {Script, AfterPath} -> - {PathInfo, QueryString} = pathinfo_querystring(AfterPath), - {Script, {PathInfo, QueryString}}; - not_a_script -> - not_a_script - end. -pathinfo_querystring(Str) -> - pathinfo_querystring(Str, []). -pathinfo_querystring([], SoFar) -> - {lists:reverse(SoFar), []}; -pathinfo_querystring([$?|Rest], SoFar) -> - {lists:reverse(SoFar), Rest}; -pathinfo_querystring([C|Rest], SoFar) -> - pathinfo_querystring(Rest, [C|SoFar]). - -split_script_path([$?|QueryString], SoFar) -> - Path = http_uri:decode(lists:reverse(SoFar)), - case file:read_file_info(Path) of - {ok,FileInfo} when FileInfo#file_info.type =:= regular -> - {Path, [$?|QueryString]}; - {ok, _FileInfo} -> - not_a_script; - {error, _Reason} -> - not_a_script - end; -split_script_path([], SoFar) -> - Path = http_uri:decode(lists:reverse(SoFar)), - case file:read_file_info(Path) of - {ok,FileInfo} when FileInfo#file_info.type =:= regular -> - {Path, []}; - {ok, _FileInfo} -> - not_a_script; - {error, _Reason} -> - not_a_script - end; -split_script_path([$/|Rest], SoFar) -> - Path = http_uri:decode(lists:reverse(SoFar)), - case file:read_file_info(Path) of - {ok, FileInfo} when FileInfo#file_info.type =:= regular -> - {Path, [$/|Rest]}; - {ok, _FileInfo} -> - split_script_path(Rest, [$/|SoFar]); - {error, _Reason} -> - split_script_path(Rest, [$/|SoFar]) - end; -split_script_path([C|Rest], SoFar) -> - split_script_path(Rest,[C|SoFar]). +split_script_path(URI) -> + case uri_string:normalize(URI, [return_map]) of + #{fragment := _Fragment, + path := _Path, + query := _Query} -> + not_a_script; + #{path := Path, + query := Query} -> + {Script, PathInfo} = split_path(Path, []), + {Script, {PathInfo, Query}}; + #{path := Path} -> + split_path(Path, []) + end. %% suffix diff --git a/lib/inets/src/http_server/mod_dir.erl b/lib/inets/src/http_server/mod_dir.erl index 2a90575e7d..ad2ee1d994 100644 --- a/lib/inets/src/http_server/mod_dir.erl +++ b/lib/inets/src/http_server/mod_dir.erl @@ -57,9 +57,7 @@ do_dir(Info) -> %% Is it a directory? case file:read_file_info(DefaultPath) of {ok,FileInfo} when FileInfo#file_info.type == directory -> - DecodedRequestURI = - http_uri:decode(Info#mod.request_uri), - case dir(DefaultPath,string:strip(DecodedRequestURI,right,$/), + case dir(DefaultPath,string:strip( Info#mod.request_uri,right,$/), Info#mod.config_db) of {ok, Dir} -> LastModified = diff --git a/lib/inets/src/http_server/mod_esi.erl b/lib/inets/src/http_server/mod_esi.erl index 45dacea3e9..00268aefec 100644 --- a/lib/inets/src/http_server/mod_esi.erl +++ b/lib/inets/src/http_server/mod_esi.erl @@ -106,16 +106,6 @@ store({erl_script_alias, {Name, Modules}} = Conf, _) {error, {wrong_type, {erl_script_alias, Error}}} end; -store({eval_script_alias, {Name, Modules}} = Conf, _) - when is_list(Name)-> - try httpd_util:modules_validate(Modules) of - ok -> - {ok, Conf} - catch - throw:Error -> - {error, {wrong_type, {eval_script_alias, Error}}} - end; - store({erl_script_alias, Value}, _) -> {error, {wrong_type, {erl_script_alias, Value}}}; store({erl_script_timeout, TimeoutSec}, _) @@ -135,8 +125,6 @@ store({erl_script_nocache, Value}, _) -> %%%======================================================================== generate_response(ModData) -> case scheme(ModData#mod.request_uri, ModData#mod.config_db) of - {eval, ESIBody, Modules} -> - eval(ModData, ESIBody, Modules); {erl, ESIBody, Modules} -> erl(ModData, ESIBody, Modules); no_scheme -> @@ -146,12 +134,7 @@ generate_response(ModData) -> scheme(RequestURI, ConfigDB) -> case match_script(RequestURI, ConfigDB, erl_script_alias) of no_match -> - case match_script(RequestURI, ConfigDB, eval_script_alias) of - no_match -> - no_scheme; - {EsiBody, ScriptModules} -> - {eval, EsiBody, ScriptModules} - end; + no_scheme; {EsiBody, ScriptModules} -> {erl, EsiBody, ScriptModules} end. @@ -176,10 +159,7 @@ match_esi_script(RequestURI, [{Alias,Modules} | Rest], AliasType) -> end. alias_match_str(Alias, erl_script_alias) -> - "^" ++ Alias ++ "/"; -alias_match_str(Alias, eval_script_alias) -> - "^" ++ Alias ++ "\\?". - + "^" ++ Alias ++ "/". %%------------------------ Erl mechanism -------------------------------- @@ -260,8 +240,8 @@ generate_webpage(ModData, ESIBody, Modules, Module, FunctionName, case erl_scheme_webpage_chunk(Module, Function, Env, Input, ModData) of {error, erl_scheme_webpage_chunk_undefined} -> - erl_scheme_webpage_whole(Module, Function, Env, Input, - ModData); + {proceed, [{status, {404, ModData#mod.request_uri, "Not found"}} + | ModData#mod.data]}; ResponseResult -> ResponseResult end; @@ -271,38 +251,7 @@ generate_webpage(ModData, ESIBody, Modules, Module, FunctionName, ++ ESIBody)}} | ModData#mod.data]} end. -%% Old API that waits for the dymnamic webpage to be totally generated -%% before anythig is sent back to the client. -erl_scheme_webpage_whole(Mod, Func, Env, Input, ModData) -> - case (catch Mod:Func(Env, Input)) of - {'EXIT',{undef, _}} -> - {proceed, [{status, {404, ModData#mod.request_uri, "Not found"}} - | ModData#mod.data]}; - {'EXIT',Reason} -> - {proceed, [{status, {500, none, Reason}} | - ModData#mod.data]}; - Response -> - {Headers, Body} = - httpd_esi:parse_headers(lists:flatten(Response)), - Length = httpd_util:flatlength(Body), - {ok, NewHeaders, StatusCode} = httpd_esi:handle_headers(Headers), - send_headers(ModData, StatusCode, - [{"content-length", - integer_to_list(Length)}| NewHeaders]), - case ModData#mod.method of - "HEAD" -> - {proceed, [{response, {already_sent, StatusCode, 0}} | - ModData#mod.data]}; - _ -> - httpd_response:send_body(ModData, - StatusCode, Body), - {proceed, [{response, {already_sent, StatusCode, - Length}} | - ModData#mod.data]} - end - end. - -%% New API that allows the dynamic wepage to be sent back to the client +%% API that allows the dynamic wepage to be sent back to the client %% in small chunks at the time during generation. erl_scheme_webpage_chunk(Mod, Func, Env, Input, ModData) -> process_flag(trap_exit, true), @@ -314,7 +263,6 @@ erl_scheme_webpage_chunk(Mod, Func, Env, Input, ModData) -> fun() -> case catch Mod:Func(Self, Env, Input) of {'EXIT', {undef,_}} -> - %% Will force fallback on the old API exit(erl_scheme_webpage_chunk_undefined); {continue, _} = Continue -> exit(Continue); @@ -468,64 +416,3 @@ input_type([$?|_Rest]) -> input_type([_First|Rest]) -> input_type(Rest). -%%------------------------ Eval mechanism -------------------------------- - -eval(#mod{request_uri = ReqUri, - method = "PUT", - http_version = Version, - data = Data}, _ESIBody, _Modules) -> - {proceed,[{status,{501,{"PUT", ReqUri, Version}, - ?NICE("Eval mechanism doesn't support method PUT")}}| - Data]}; - -eval(#mod{request_uri = ReqUri, - method = "DELETE", - http_version = Version, - data = Data}, _ESIBody, _Modules) -> - {proceed,[{status,{501,{"DELETE", ReqUri, Version}, - ?NICE("Eval mechanism doesn't support method DELETE")}}| - Data]}; - -eval(#mod{request_uri = ReqUri, - method = "POST", - http_version = Version, - data = Data}, _ESIBody, _Modules) -> - {proceed,[{status,{501,{"POST", ReqUri, Version}, - ?NICE("Eval mechanism doesn't support method POST")}}| - Data]}; - -eval(#mod{method = Method} = ModData, ESIBody, Modules) - when (Method =:= "GET") orelse (Method =:= "HEAD") -> - case is_authorized(ESIBody, Modules) of - true -> - case generate_webpage(ESIBody) of - {error, Reason} -> - {proceed, [{status, {500, none, Reason}} | - ModData#mod.data]}; - {ok, Response} -> - {Headers, _} = - httpd_esi:parse_headers(lists:flatten(Response)), - {ok, _, StatusCode} =httpd_esi:handle_headers(Headers), - {proceed,[{response, {StatusCode, Response}} | - ModData#mod.data]} - end; - false -> - {proceed,[{status, - {403, ModData#mod.request_uri, - ?NICE("Client not authorized to evaluate: " - ++ ESIBody)}} | ModData#mod.data]} - end. - -generate_webpage(ESIBody) -> - (catch erl_eval:eval_str(string:concat(ESIBody,". "))). - -is_authorized(_ESIBody, [all]) -> - true; -is_authorized(ESIBody, Modules) -> - case re:run(ESIBody, "^[^\:(%3A)]*", [{capture, first}]) of - {match, [{Start, Length}]} -> - lists:member(list_to_atom(string:substr(ESIBody, Start+1, Length)), - Modules); - nomatch -> - false - end. diff --git a/lib/inets/src/inets_app/inets.app.src b/lib/inets/src/inets_app/inets.app.src index e5310fd80e..54b60ee1f7 100644 --- a/lib/inets/src/inets_app/inets.app.src +++ b/lib/inets/src/inets_app/inets.app.src @@ -43,14 +43,14 @@ httpc_sup, httpc_cookie, - http_uri, %% Proably will by used by server also in the future - %% HTTP used by both client and server http_chunk, http_request, http_response, http_transport, http_util, + + http_uri, %% Deprecated %% HTTP server: httpd, |