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 [
|
@options [
|
||||||
connect_timeout: 10_000,
|
connect_timeout: 10_000,
|
||||||
timeout: 20_000,
|
timeout: 20_000
|
||||||
protocols: [:http]
|
|
||||||
]
|
]
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
@ -24,8 +23,7 @@ defmodule Pleroma.HTTP.Connection do
|
|||||||
def new(opts \\ []) do
|
def new(opts \\ []) do
|
||||||
middleware = [Tesla.Middleware.FollowRedirects]
|
middleware = [Tesla.Middleware.FollowRedirects]
|
||||||
adapter = Application.get_env(:tesla, :adapter)
|
adapter = Application.get_env(:tesla, :adapter)
|
||||||
options = options(opts)
|
Tesla.client(middleware, {adapter, options(opts)})
|
||||||
Tesla.client(middleware, {adapter, options})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# fetch http options
|
# fetch http options
|
||||||
|
@ -45,9 +45,9 @@ defmodule Pleroma.HTTP do
|
|||||||
|
|
||||||
%{}
|
%{}
|
||||||
|> Builder.method(method)
|
|> Builder.method(method)
|
||||||
|
|> Builder.url(url)
|
||||||
|> Builder.headers(headers)
|
|> Builder.headers(headers)
|
||||||
|> Builder.opts(options)
|
|> Builder.opts(options)
|
||||||
|> Builder.url(url)
|
|
||||||
|> Builder.add_param(:body, :body, body)
|
|> Builder.add_param(:body, :body, body)
|
||||||
|> Builder.add_param(:query, :query, params)
|
|> Builder.add_param(:query, :query, params)
|
||||||
|> Enum.into([])
|
|> Enum.into([])
|
||||||
|
@ -53,6 +53,15 @@ defmodule Pleroma.HTTP.RequestBuilder do
|
|||||||
header_list
|
header_list
|
||||||
end
|
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)
|
Map.put_new(request, :headers, header_list)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.HTTP.RequestBuilderTest do
|
defmodule Pleroma.HTTP.RequestBuilderTest do
|
||||||
use ExUnit.Case, async: true
|
use ExUnit.Case
|
||||||
use Pleroma.Tests.Helpers
|
use Pleroma.Tests.Helpers
|
||||||
alias Pleroma.HTTP.RequestBuilder
|
alias Pleroma.HTTP.RequestBuilder
|
||||||
|
|
||||||
@ -21,6 +21,17 @@ defmodule Pleroma.HTTP.RequestBuilderTest do
|
|||||||
headers: [{"user-agent", Pleroma.Application.user_agent()}]
|
headers: [{"user-agent", Pleroma.Application.user_agent()}]
|
||||||
}
|
}
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "add_optional_params/3" do
|
describe "add_optional_params/3" do
|
||||||
|
Loading…
Reference in New Issue
Block a user