aboutsummaryrefslogtreecommitdiffstats
path: root/lib/inets
diff options
context:
space:
mode:
authorJosé Valim <[email protected]>2018-06-30 19:03:19 +0200
committerGitHub <[email protected]>2018-06-30 19:03:19 +0200
commit3292db3fdb6cf50852301b337999bafd17d41816 (patch)
tree23f3beb8de4258a0bc4be1c7be555755740a64bd /lib/inets
parentbc22321f10c1ad71fb7e28275a8e6ed26a34d4ab (diff)
downloadotp-3292db3fdb6cf50852301b337999bafd17d41816.tar.gz
otp-3292db3fdb6cf50852301b337999bafd17d41816.tar.bz2
otp-3292db3fdb6cf50852301b337999bafd17d41816.zip
Include question mark in query string on redirect
According to the code in httpc.erl, the pquery parameter in the #request record should start with a question mark. However, when a server returned a 403 response, the Location header was parsed and the question mark was not added to the beginning of the query string. This ultimately causes the redirect to fail, as instead of redirecting to "/path?query", httpc redirected to "/pathquery".
Diffstat (limited to 'lib/inets')
-rw-r--r--lib/inets/src/http_client/httpc_response.erl10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/inets/src/http_client/httpc_response.erl b/lib/inets/src/http_client/httpc_response.erl
index 0f3bd0a06d..1af85f8fe0 100644
--- a/lib/inets/src/http_client/httpc_response.erl
+++ b/lib/inets/src/http_client/httpc_response.erl
@@ -398,7 +398,7 @@ redirect(Response = {_, Headers, _}, Request) ->
THost = http_util:maybe_add_brackets(maps:get(host, URIMap), Brackets),
TPort = maps:get(port, URIMap),
TPath = maps:get(path, URIMap),
- TQuery = maps:get(query, URIMap, ""),
+ TQuery = add_question_mark(maps:get(query, URIMap, "")),
NewURI = uri_string:normalize(
uri_string:recompose(URIMap)),
HostPort = http_request:normalize_host(TScheme, THost, TPort),
@@ -417,6 +417,14 @@ redirect(Response = {_, Headers, _}, Request) ->
end
end.
+add_question_mark(<<>>) ->
+ <<>>;
+add_question_mark([]) ->
+ [];
+add_question_mark(Comp) when is_binary(Comp) ->
+ <<$?, Comp/binary>>;
+add_question_mark(Comp) when is_list(Comp) ->
+ [$?|Comp].
%% RFC3986 - 5.2.2. Transform References
resolve_uri(Scheme, Host, Port, Path, Query, URI) ->