Pleroma.HTTP: permit passing through custom Tesla Middlware for requests
This commit is contained in:
parent
f32a837afa
commit
858fd01c01
@ -68,7 +68,9 @@ defmodule Pleroma.HTTP do
|
|||||||
|
|
||||||
adapter = Application.get_env(:tesla, :adapter)
|
adapter = Application.get_env(:tesla, :adapter)
|
||||||
|
|
||||||
client = Tesla.client(adapter_middlewares(adapter), adapter)
|
extra_middleware = options[:tesla_middleware] || []
|
||||||
|
|
||||||
|
client = Tesla.client(adapter_middlewares(adapter, extra_middleware), adapter)
|
||||||
|
|
||||||
maybe_limit(
|
maybe_limit(
|
||||||
fn ->
|
fn ->
|
||||||
@ -102,20 +104,21 @@ defmodule Pleroma.HTTP do
|
|||||||
fun.()
|
fun.()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp adapter_middlewares(Tesla.Adapter.Gun) do
|
defp adapter_middlewares(Tesla.Adapter.Gun, extra_middleware) do
|
||||||
[Tesla.Middleware.FollowRedirects, Pleroma.Tesla.Middleware.ConnectionPool]
|
[Tesla.Middleware.FollowRedirects, Pleroma.Tesla.Middleware.ConnectionPool] ++
|
||||||
|
extra_middleware
|
||||||
end
|
end
|
||||||
|
|
||||||
defp adapter_middlewares({Tesla.Adapter.Finch, _}) do
|
defp adapter_middlewares({Tesla.Adapter.Finch, _}, extra_middleware) do
|
||||||
[Tesla.Middleware.FollowRedirects]
|
[Tesla.Middleware.FollowRedirects] ++ extra_middleware
|
||||||
end
|
end
|
||||||
|
|
||||||
defp adapter_middlewares(_) do
|
defp adapter_middlewares(_, extra_middleware) do
|
||||||
if Pleroma.Config.get(:env) == :test do
|
if Pleroma.Config.get(:env) == :test do
|
||||||
# Emulate redirects in test env, which are handled by adapters in other environments
|
# Emulate redirects in test env, which are handled by adapters in other environments
|
||||||
[Tesla.Middleware.FollowRedirects]
|
[Tesla.Middleware.FollowRedirects]
|
||||||
else
|
else
|
||||||
[]
|
extra_middleware
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user