diff options
author | Ao Song <andy@erlang.org> | 2020-05-25 18:23:16 +0200 |
---|---|---|
committer | Ao Song <andy@erlang.org> | 2020-06-03 14:35:42 +0200 |
commit | 848642f50c315e94ef257e2c625b8088e8a3f844 (patch) | |
tree | d9ed68b0d01fceca39e4d17d0075d94201761c04 | |
parent | bd7b9d311bb36ccbd6ebac5e3e7595cd2ff2406f (diff) | |
download | erlang-848642f50c315e94ef257e2c625b8088e8a3f844.tar.gz |
http_request: Fix to handle undefined port in uri
Add match for undefined in function http_request:normalize_host/3
to handle situation when port undefined in uri.
-rw-r--r-- | lib/inets/src/http_lib/http_request.erl | 6 | ||||
-rw-r--r-- | lib/inets/test/httpc_SUITE.erl | 9 |
2 files changed, 12 insertions, 3 deletions
diff --git a/lib/inets/src/http_lib/http_request.erl b/lib/inets/src/http_lib/http_request.erl index c49402cc1f..2510cdede2 100644 --- a/lib/inets/src/http_lib/http_request.erl +++ b/lib/inets/src/http_lib/http_request.erl @@ -103,9 +103,11 @@ is_absolut_uri(_) -> %% Description: returns a normalized Host header value, with the port %% number omitted for well-known ports %%------------------------------------------------------------------------- -normalize_host(https, Host, 443 = _Port) -> +normalize_host(https, Host, Port) when Port =:= 443 orelse + Port =:= undefined -> Host; -normalize_host(http, Host, 80 = _Port) -> +normalize_host(http, Host, Port) when Port =:= 80 orelse + Port =:= undefined -> Host; normalize_host(_Scheme, Host, Port) -> Host ++ ":" ++ integer_to_list(Port). diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl index 8c9bbbe831..a2cb286218 100644 --- a/lib/inets/test/httpc_SUITE.erl +++ b/lib/inets/test/httpc_SUITE.erl @@ -108,7 +108,8 @@ real_requests()-> invalid_headers, invalid_body, no_scheme, - invalid_uri + invalid_uri, + undefined_port ]. real_requests_esi() -> @@ -1252,6 +1253,12 @@ invalid_uri(Config) -> {error, invalid_uri} = httpc:request(URL), ok. +%%------------------------------------------------------------------------- + +undefined_port(_Config) -> + {error, {failed_connect, _Reason}} = httpc:request("http://:"), + ok. + %%------------------------------------------------------------------------- remote_socket_close(Config) when is_list(Config) -> |