Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #100: Follow redirects when extended #101

Merged
merged 1 commit into from
Oct 15, 2016
Merged
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
2 changes: 1 addition & 1 deletion lib/httpotion.ex
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ defmodule HTTPotion.Base do
:ibrowse.send_req(args[:url], args[:headers], args[:method], args[:body], args[:ib_options], args[:timeout])
end

if response_ok(response) && is_redirect(response) && options[:follow_redirects] do
if response_ok(response) && is_redirect(response) && args[:follow_redirects] do
location = process_response_location(response)
next_url = normalize_location(location, url)
request(method, next_url, options)
Expand Down
13 changes: 13 additions & 0 deletions test/httpotion_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@ defmodule HTTPotionTest do
assert response.headers[:Location] == nil
end

test "follow relative redirect when specified in options" do
defmodule ExampleWithRedirect do
use HTTPotion.Base
defp process_options(options), do: Keyword.put(options, :follow_redirects, true)
end

response = ExampleWithRedirect.get("http://httpbin.org/relative-redirect/1")

assert_response response
assert response.status_code == 200
assert response.headers[:Location] == nil
end

defp assert_response(response, function \\ nil) do
assert HTTPotion.Response.success?(response, :extra)
assert response.headers[:Connection] == "keep-alive"
Expand Down