diff options
author | Péter Dimitrov <[email protected]> | 2017-12-01 11:14:23 +0100 |
---|---|---|
committer | Péter Dimitrov <[email protected]> | 2017-12-01 11:14:23 +0100 |
commit | 2973263a033b0e20123f8a316935e052695da1de (patch) | |
tree | 904ef17efad4f17574fc2e3e80421b03ae15481d /lib | |
parent | 76c4821cff1e91c26dd2f812fc8cb40aa7d48e57 (diff) | |
parent | 175e1fa414b6609e83da2d4b3ab44bbdca754ede (diff) | |
download | otp-2973263a033b0e20123f8a316935e052695da1de.tar.gz otp-2973263a033b0e20123f8a316935e052695da1de.tar.bz2 otp-2973263a033b0e20123f8a316935e052695da1de.zip |
Merge branch 'peterdmv/inets/fix-httpc/OTP-14799'
* peterdmv/inets/fix-httpc/OTP-14799:
inets: Fix httpc path handling
Diffstat (limited to 'lib')
-rw-r--r-- | lib/inets/src/http_client/httpc.erl | 4 | ||||
-rw-r--r-- | lib/inets/test/httpc_SUITE.erl | 31 |
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",_,_,_,_) -> |