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

Follow redirects improvement #55

Merged
merged 4 commits into from
Feb 6, 2017

Conversation

amatalai
Copy link
Collaborator

Previously redirect(env, next, 0) raised error immediately when if fact I would expect it to check this last location and raise only if it return another redirect

@teamon
Copy link
Member

teamon commented Jan 29, 2017

Hmm, isn't this the same as changing left <= 0 to left <0, so that left == 0 case goes into the second redirect(..) clause?

@amatalai
Copy link
Collaborator Author

Technically yes, but for me it seems to be more clear to have 0 remaining redirects than -1 remaining redirects.

@amatalai
Copy link
Collaborator Author

Added note about httpc, because this middleware won't work for httpc default config

defmodule RedirectTest.Hackney do
  use Tesla

  adapter :hackney

  plug Tesla.Middleware.FollowRedirects, max_redirects: 0
end

defmodule RedirectTest.Ibrowse do
  use Tesla

  adapter :ibrowse

  plug Tesla.Middleware.FollowRedirects, max_redirects: 0
end

defmodule RedirectTest.Httpc do
  use Tesla

  adapter :httpc

  plug Tesla.Middleware.FollowRedirects, max_redirects: 0
end

defmodule RedirectTest.FixedHttpc do
  use Tesla

  adapter :httpc, autoredirect: false

  plug Tesla.Middleware.FollowRedirects, max_redirects: 0
end

iex(1)> RedirectTest.Hackney.get("http://yahoo.pl")
** (Tesla.Error) too many redirects

iex(2)> RedirectTest.Ibrowse.get("http://yahoo.pl")
** (Tesla.Error) too many redirects

iex(3)> RedirectTest.Httpc.get("http://yahoo.pl")
%Tesla.Env{status: 200}

iex(4)> RedirectTest.FixedHttpc.get("http://yahoo.pl")
** (Tesla.Error) too many redirects

@teamon teamon merged commit 74f3aa5 into elixir-tesla:master Feb 6, 2017
@aphillipo
Copy link

Shouldn't the default for httpc be the same as all the other http clients, i.e. autoredirect: false and then if people want this functionality they can enable Tesla.Middleware.FollowRedirects?

Seems like strange behaviour that changing the http client changes this and exactly the sort of thing something like Tesla should be hiding from the user?

@teamon
Copy link
Member

teamon commented Feb 6, 2017

I think you're right @aphillipo, we should make the httpc adapter have default opts with autoredirect: false

@amatalai amatalai deleted the follow-redirects-improvement branch January 24, 2019 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants