diff options
author | Erlang/OTP <[email protected]> | 2019-07-02 13:44:02 +0200 |
---|---|---|
committer | Erlang/OTP <[email protected]> | 2019-07-02 13:44:02 +0200 |
commit | e02ab342939b6fe11090950137966542df82650f (patch) | |
tree | 960238c543ed8288222098aa5ec2c496e7e1ef03 | |
parent | e00aecba6c2060440668b36ac5bae0a380e5fa63 (diff) | |
parent | 4c7bf834f532b682c92c77a4e4fe171002ee9d7a (diff) | |
download | otp-e02ab342939b6fe11090950137966542df82650f.tar.gz otp-e02ab342939b6fe11090950137966542df82650f.tar.bz2 otp-e02ab342939b6fe11090950137966542df82650f.zip |
Merge branch 'peterdmv/inets/httpc-uri-scheme/ERL-969/OTP-15930' into maint-22
* peterdmv/inets/httpc-uri-scheme/ERL-969/OTP-15930:
inets: Return error if URI has no scheme (httpc)
-rw-r--r-- | lib/inets/src/http_client/httpc.erl | 8 | ||||
-rw-r--r-- | lib/inets/test/httpc_SUITE.erl | 13 |
2 files changed, 16 insertions, 5 deletions
diff --git a/lib/inets/src/http_client/httpc.erl b/lib/inets/src/http_client/httpc.erl index 24a205ced9..9967488f61 100644 --- a/lib/inets/src/http_client/httpc.erl +++ b/lib/inets/src/http_client/httpc.erl @@ -317,7 +317,7 @@ store_cookies(SetCookieHeaders, Url, Profile) {error, Bad, _} -> {error, {parse_failed, Bad}}; URI -> - Scheme = scheme_to_atom(maps:get(scheme, URI, '')), + Scheme = scheme_to_atom(maps:get(scheme, URI, undefined)), Host = maps:get(host, URI, ""), Port = maps:get(port, URI, default_port(Scheme)), Path = uri_string:recompose(#{path => maps:get(path, URI, "")}), @@ -536,7 +536,7 @@ handle_request(Method, Url, BracketedHost = proplists:get_value(ipv6_host_with_brackets, Options), - Scheme = scheme_to_atom(maps:get(scheme, URI, '')), + Scheme = scheme_to_atom(maps:get(scheme, URI, undefined)), Userinfo = maps:get(userinfo, URI, ""), Host = http_util:maybe_add_brackets(maps:get(host, URI, ""), BracketedHost), Port = maps:get(port, URI, default_port(Scheme)), @@ -591,8 +591,8 @@ scheme_to_atom("http") -> http; scheme_to_atom("https") -> https; -scheme_to_atom('') -> - ''; +scheme_to_atom(undefined) -> + throw({error, {no_scheme}}); scheme_to_atom(Scheme) -> throw({error, {bad_scheme, Scheme}}). diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl index d4b33ae2c6..1d37e71847 100644 --- a/lib/inets/test/httpc_SUITE.erl +++ b/lib/inets/test/httpc_SUITE.erl @@ -106,7 +106,8 @@ real_requests()-> streaming_error, inet_opts, invalid_headers, - invalid_body + invalid_body, + no_scheme ]. real_requests_esi() -> @@ -1231,6 +1232,16 @@ invalid_body(Config) -> ok end. + +%%------------------------------------------------------------------------- + +no_scheme(_Config) -> + {error,{bad_scheme,"ftp"}} = httpc:request("ftp://foobar"), + {error,{no_scheme}} = httpc:request("//foobar"), + {error,{no_scheme}} = httpc:request("foobar"), + ok. + + %%------------------------------------------------------------------------- remote_socket_close(Config) when is_list(Config) -> URL = url(group_name(Config), "/just_close.html", Config), |