Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F140684
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/tesla/middleware/follow_redirects.ex b/lib/tesla/middleware/follow_redirects.ex
index 7f7efd5..409f734 100644
--- a/lib/tesla/middleware/follow_redirects.ex
+++ b/lib/tesla/middleware/follow_redirects.ex
@@ -1,34 +1,39 @@
defmodule Tesla.Middleware.FollowRedirects do
@doc """
Follow 301/302 redirects
Example:
defmodule MyClient do
use Tesla
plug Tesla.Middleware.FollowRedirects, max_redirects: 3 # defaults to 5
end
"""
@max_redirects 5
@redirect_statuses [301, 302, 307, 308]
def call(env, next, opts \\ []) do
max = Keyword.get(opts || [], :max_redirects, @max_redirects)
redirect(env, next, max)
end
- defp redirect(env, next, left) when left <= 0 do
- raise Tesla.Error, "too many redirects"
+ defp redirect(env, next, left) when left == 0 do
+ case Tesla.run(env, next) do
+ %{status: status} = env when not status in @redirect_statuses ->
+ env
+ _ ->
+ raise Tesla.Error, "too many redirects"
+ end
end
defp redirect(env, next, left) do
case Tesla.run(env, next) do
%{status: status, headers: %{"location" => location}} when status in @redirect_statuses ->
redirect(%{env | url: location}, next, left - 1)
env ->
env
end
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Jan 21, 2:44 AM (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55643
Default Alt Text
(1 KB)
Attached To
Mode
R28 tesla
Attached
Detach File
Event Timeline
Log In to Comment