adding host header for gun adapter
This commit is contained in:
parent
59336f1448
commit
916aeb934f
@ -9,8 +9,7 @@ defmodule Pleroma.HTTP.Connection do
|
||||
|
||||
@options [
|
||||
connect_timeout: 10_000,
|
||||
timeout: 20_000,
|
||||
protocols: [:http]
|
||||
timeout: 20_000
|
||||
]
|
||||
|
||||
@doc """
|
||||
@ -24,8 +23,7 @@ defmodule Pleroma.HTTP.Connection do
|
||||
def new(opts \\ []) do
|
||||
middleware = [Tesla.Middleware.FollowRedirects]
|
||||
adapter = Application.get_env(:tesla, :adapter)
|
||||
options = options(opts)
|
||||
Tesla.client(middleware, {adapter, options})
|
||||
Tesla.client(middleware, {adapter, options(opts)})
|
||||
end
|
||||
|
||||
# fetch http options
|
||||
|
@ -45,9 +45,9 @@ defmodule Pleroma.HTTP do
|
||||
|
||||
%{}
|
||||
|> Builder.method(method)
|
||||
|> Builder.url(url)
|
||||
|> Builder.headers(headers)
|
||||
|> Builder.opts(options)
|
||||
|> Builder.url(url)
|
||||
|> Builder.add_param(:body, :body, body)
|
||||
|> Builder.add_param(:query, :query, params)
|
||||
|> Enum.into([])
|
||||
|
@ -53,6 +53,15 @@ defmodule Pleroma.HTTP.RequestBuilder do
|
||||
header_list
|
||||
end
|
||||
|
||||
# TODO: maybe we need this header for all adapters, so we won't fail on adapter change
|
||||
header_list =
|
||||
if Application.get_env(:tesla, :adapter) == Tesla.Adapter.Gun do
|
||||
%{host: host} = URI.parse(request.url)
|
||||
header_list ++ [{"host", host}]
|
||||
else
|
||||
header_list
|
||||
end
|
||||
|
||||
Map.put_new(request, :headers, header_list)
|
||||
end
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.HTTP.RequestBuilderTest do
|
||||
use ExUnit.Case, async: true
|
||||
use ExUnit.Case
|
||||
use Pleroma.Tests.Helpers
|
||||
alias Pleroma.HTTP.RequestBuilder
|
||||
|
||||
@ -21,6 +21,17 @@ defmodule Pleroma.HTTP.RequestBuilderTest do
|
||||
headers: [{"user-agent", Pleroma.Application.user_agent()}]
|
||||
}
|
||||
end
|
||||
|
||||
test "it adds host header for gun adapter" do
|
||||
adapter = Application.get_env(:tesla, :adapter)
|
||||
Application.put_env(:tesla, :adapter, Tesla.Adapter.Gun)
|
||||
on_exit(fn -> Application.put_env(:tesla, :adapter, adapter) end)
|
||||
|
||||
assert RequestBuilder.headers(%{url: "https://example.com"}, []) == %{
|
||||
headers: [{"host", "example.com"}],
|
||||
url: "https://example.com"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe "add_optional_params/3" do
|
||||
|
Loading…
Reference in New Issue
Block a user