diff options
author | Ross Schlaikjer <[email protected]> | 2018-07-02 10:26:15 -0400 |
---|---|---|
committer | Ross Schlaikjer <[email protected]> | 2018-07-06 08:46:11 -0400 |
commit | 9993d349a8abcb7ba07bebcc8cc71ecec291ca68 (patch) | |
tree | 028f642f11ca37d70ea896ee736be0f4252e50f0 /lib/inets/src | |
parent | 2f09a0f78e7d18d8b83ef2696efa940f74222c4e (diff) | |
download | otp-9993d349a8abcb7ba07bebcc8cc71ecec291ca68.tar.gz otp-9993d349a8abcb7ba07bebcc8cc71ecec291ca68.tar.bz2 otp-9993d349a8abcb7ba07bebcc8cc71ecec291ca68.zip |
Do not assert that new URI port is same as old port
When handling 301 redirects from http -> https on Erlang 21.0.1, the
following error is encountered:
```
8> Options = [].
9> httpc:request(head, {"http://rhye.org", []}, Options, []).
{error,{shutdown,{{error,{badmatch,443}},
[{httpc_response,resolve_uri,7,
[{file,"/usr/local/lib/erlang/lib/inets-7.0/src/http_client/httpc_response.erl"},
{line,431}]},
{httpc_response,redirect,2,
[{file,"/usr/local/lib/erlang/lib/inets-7.0/src/http_client/httpc_response.erl"},
{line,396}]},
{httpc_handler,handle_response,1,
[{file,"httpc_handler.erl"},{line,1052}]},
{httpc_handler,handle_info,2,
[{file,"httpc_handler.erl"},{line,283}]},
{gen_server,try_dispatch,4,
[{file,"gen_server.erl"},{line,637}]},
{gen_server,handle_msg,6,
[{file,"gen_server.erl"},{line,711}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,249}]}]}}}
```
This seems to be caused by the following code in `resolve_uri`:
```
resolve_uri(Scheme, Host, Port, Path, Query, URI, Map0) ->
case maps:is_key(scheme, URI) of
true ->
Port = get_port(URI)
```
The value of `Port` passed in to `resolve_uri` here is 80, since the
original URL is http. However, since the redirected URL is https, the
`get_port` call returns 443, which is not equal to 80, and crashes.
Assigning to a new variable seems to fix redirects.
Diffstat (limited to 'lib/inets/src')
-rw-r--r-- | lib/inets/src/http_client/httpc_response.erl | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/inets/src/http_client/httpc_response.erl b/lib/inets/src/http_client/httpc_response.erl index 0f3bd0a06d..0931f0b4d3 100644 --- a/lib/inets/src/http_client/httpc_response.erl +++ b/lib/inets/src/http_client/httpc_response.erl @@ -425,11 +425,11 @@ resolve_uri(Scheme, Host, Port, Path, Query, URI) -> resolve_uri(Scheme, Host, Port, Path, Query, URI, Map0) -> case maps:is_key(scheme, URI) of true -> - Port = get_port(URI), + Port0 = get_port(URI), maybe_add_query( Map0#{scheme => maps:get(scheme, URI), host => maps:get(host, URI), - port => Port, + port => Port0, path => maps:get(path, URI)}, URI); false -> |