aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPéter Dimitrov <[email protected]>2017-11-27 16:42:14 +0100
committerPéter Dimitrov <[email protected]>2017-11-28 10:42:32 +0100
commit175e1fa414b6609e83da2d4b3ab44bbdca754ede (patch)
tree21c190b493bd1d923dff7f28b2904a6a64758dc0 /lib
parent9dffbcc0e659d2e2ad7afc0bffe622f2e6c81ea4 (diff)
downloadotp-175e1fa414b6609e83da2d4b3ab44bbdca754ede.tar.gz
otp-175e1fa414b6609e83da2d4b3ab44bbdca754ede.tar.bz2
otp-175e1fa414b6609e83da2d4b3ab44bbdca754ede.zip
inets: Fix httpc path handling
Fixed handling of URL paths that contain space (%20) characters. Change-Id: Ic09691e35c70ee005af7637a6ec3ae588097bec1
Diffstat (limited to 'lib')
-rw-r--r--lib/inets/src/http_client/httpc.erl4
-rw-r--r--lib/inets/test/httpc_SUITE.erl31
2 files changed, 26 insertions, 9 deletions
diff --git a/lib/inets/src/http_client/httpc.erl b/lib/inets/src/http_client/httpc.erl
index 2efe2c2858..821eb7f02f 100644
--- a/lib/inets/src/http_client/httpc.erl
+++ b/lib/inets/src/http_client/httpc.erl
@@ -319,7 +319,7 @@ store_cookies(SetCookieHeaders, Url, Profile)
Scheme = scheme_to_atom(maps:get(scheme, URI, '')),
Host = maps:get(host, URI, ""),
Port = maps:get(port, URI, default_port(Scheme)),
- Path = maps:get(path, URI, ""),
+ Path = uri_string:recompose(#{path => maps:get(path, URI, "")}),
%% Since the Address part is not actually used
%% by the manager when storing cookies, we dont
%% care about ipv6-host-with-brackets.
@@ -539,7 +539,7 @@ handle_request(Method, Url,
Host = http_util:maybe_add_brackets(maps:get(host, URI, ""), BracketedHost),
Port = maps:get(port, URI, default_port(Scheme)),
Host2 = http_request:normalize_host(Scheme, Host, Port),
- Path = maps:get(path, URI, ""),
+ Path = uri_string:recompose(#{path => maps:get(path, URI, "")}),
Query = add_question_mark(maps:get(query, URI, "")),
HeadersRecord = header_record(NewHeaders, Host2, HTTPOptions),
diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl
index e0e0c6b6e5..1e912e7640 100644
--- a/lib/inets/test/httpc_SUITE.erl
+++ b/lib/inets/test/httpc_SUITE.erl
@@ -58,6 +58,9 @@ all() ->
groups() ->
[
{http, [], real_requests()},
+ %% process_leak_on_keepalive is depending on stream_fun_server_close
+ %% and it shall be the last test case in the suite otherwise cookie
+ %% will fail.
{sim_http, [], only_simulated() ++ [process_leak_on_keepalive]},
{https, [], real_requests()},
{sim_https, [], only_simulated()},
@@ -133,6 +136,7 @@ only_simulated() ->
redirect_port_in_host_header,
relaxed,
multipart_chunks,
+ get_space,
stream_fun_server_close
].
@@ -254,6 +258,16 @@ get_query_string(Config) when is_list(Config) ->
{ok, {{_,200,_}, [_ | _], Body = [_ | _]}} = httpc:request(get, Request, [], []),
inets_test_lib:check_body(Body).
+
+%%--------------------------------------------------------------------
+get_space() ->
+ [{"Test http get request with '%20' in the path of the URL."}].
+get_space(Config) when is_list(Config) ->
+ Request = {url(group_name(Config), "/space%20.html", Config), []},
+ {ok, {{_,200,_}, [_ | _], Body = [_ | _]}} = httpc:request(get, Request, [], []),
+
+ inets_test_lib:check_body(Body).
+
%%--------------------------------------------------------------------
post() ->
[{"Test http post request against local server. We do in this case "
@@ -1084,8 +1098,6 @@ remote_socket_close_async(Config) when is_list(Config) ->
%%-------------------------------------------------------------------------
process_leak_on_keepalive(Config) ->
- {ok, ClosedSocket} = gen_tcp:listen(6666, [{active, false}]),
- ok = gen_tcp:close(ClosedSocket),
Request = {url(group_name(Config), "/dummy.html", Config), []},
HttpcHandlers0 = supervisor:which_children(httpc_handler_sup),
{ok, {{_, 200, _}, _, Body}} = httpc:request(get, Request, [], []),
@@ -1097,11 +1109,10 @@ process_leak_on_keepalive(Config) ->
ordsets:to_list(
ordsets:subtract(ordsets:from_list(HttpcHandlers1),
ordsets:from_list(HttpcHandlers0))),
- sys:replace_state(
- Pid, fun (State) ->
- Session = element(3, State),
- setelement(3, State, Session#session{socket=ClosedSocket})
- end),
+ State = sys:get_state(Pid),
+ #session{socket=Socket} = element(3, State),
+ gen_tcp:close(Socket),
+
{ok, {{_, 200, _}, _, Body}} = httpc:request(get, Request, [], []),
%% bad handler with the closed socket should get replaced by
%% the new one, so children count should stay the same
@@ -1745,6 +1756,12 @@ content_length([_Head | Tail]) ->
handle_uri("GET","/dummy.html?foo=bar",_,_,_,_) ->
"HTTP/1.0 200 OK\r\n\r\nTEST";
+handle_uri("GET","/space%20.html",_,_,_,_) ->
+ Body = "<HTML><BODY>foobar</BODY></HTML>",
+ "HTTP/1.1 200 OK\r\n" ++
+ "Content-Length:" ++ integer_to_list(length(Body)) ++ "\r\n\r\n" ++
+ Body;
+
handle_uri(_,"/just_close.html",_,_,_,_) ->
close;
handle_uri(_,"/no_content.html",_,_,_,_) ->