Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/hackney.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,9 @@ parse_path_qs(PathLike) ->
end.

%% @private Merge a relative path with a base path per RFC 3986 Section 5.2.3
merge_paths(BasePath, <<>>) ->
%% Empty reference path ("?q=1") keeps the base path (RFC 3986 Section 5.2.2)
BasePath;
merge_paths(BasePath, RelPath) when is_binary(BasePath), is_binary(RelPath) ->
case BasePath of
<<>> ->
Expand Down
7 changes: 7 additions & 0 deletions test/hackney_redirect_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ redirect_integration_test_() ->
%% Issue #711: relative redirect without slash
{"relative redirect without slash",
fun test_relative_redirect_without_slash/0},
{"query-only redirect keeps the path",
fun test_query_only_redirect/0},
%% Issue #693: redirect to non-standard port preserves Host header
{"redirect preserves port in Host header",
fun test_redirect_port_in_host/0},
Expand Down Expand Up @@ -238,6 +240,11 @@ test_relative_redirect_without_slash() ->
io:format("Relative redirect result: status=~p~n", [Status]),
?assertEqual(200, Status).

test_query_only_redirect() ->
URL = url(<<"/redirect-to?url=", (hackney_url:urlencode(<<"?url=/get">>))/binary>>),
{ok, Status, _Headers, _Body} = hackney:request(get, URL, [], <<>>, [{follow_redirect, true}]),
?assertEqual(200, Status).

test_redirect_port_in_host() ->
%% This tests issue #693
%% When redirecting to a URL with non-standard port, Host header should include port
Expand Down