Use connection pools.

This commit is contained in:
lain 2018-03-19 17:42:09 +01:00
parent 4d5161b16d
commit ec83175100
5 changed files with 9 additions and 5 deletions

View file

@ -351,7 +351,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
Logger.info("Federating #{id} to #{inbox}")
host = URI.parse(inbox).host
signature = Pleroma.Web.HTTPSignatures.sign(actor, %{host: host, "content-length": byte_size(json)})
@httpoison.post(inbox, json, [{"Content-Type", "application/activity+json"}, {"signature", signature}])
@httpoison.post(inbox, json, [{"Content-Type", "application/activity+json"}, {"signature", signature}], hackney: [pool: :default])
end
# TODO:

View file

@ -96,7 +96,7 @@ defmodule Pleroma.Web.Federator do
with {:ok, %{status_code: code}} <- @httpoison.post(callback, xml, [
{"Content-Type", "application/atom+xml"},
{"X-Hub-Signature", "sha1=#{signature}"}
], timeout: 10000, recv_timeout: 20000) do
], timeout: 10000, recv_timeout: 20000, hackney: [pool: :default]) do
Logger.debug(fn -> "Pushed to #{callback}, code #{code}" end)
else e ->
Logger.debug(fn -> "Couldn't push to #{callback}, #{inspect(e)}" end)

View file

@ -3,7 +3,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
require Logger
@httpoison Application.get_env(:pleroma, :httpoison)
@max_body_length 25 * 1048576
@cache_control %{
@ -31,7 +31,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
defp proxy_request(link) do
headers = [{"user-agent", "Pleroma/MediaProxy; #{Pleroma.Web.base_url()} <#{Application.get_env(:pleroma, :instance)[:email]}>"}]
options = @httpoison.process_request_options([:insecure, {:follow_redirect, true}])
options = @httpoison.process_request_options([:insecure, {:follow_redirect, true}]) ++ [{:pool, :default}]
with \
{:ok, 200, headers, client} <- :hackney.request(:get, link, headers, "", options),
headers = Enum.into(headers, Map.new),

View file

@ -147,7 +147,7 @@ defmodule Pleroma.Web.Salmon do
end
defp send_to_user(%{info: %{"salmon" => salmon}}, feed, poster) do
with {:ok, %{status_code: code}} <- poster.(salmon, feed, [{"Content-Type", "application/magic-envelope+xml"}], timeout: 10000, recv_timeout: 20000) do
with {:ok, %{status_code: code}} <- poster.(salmon, feed, [{"Content-Type", "application/magic-envelope+xml"}], timeout: 10000, recv_timeout: 20000, hackney: [pool: :default]) do
Logger.debug(fn -> "Pushed to #{salmon}, code #{code}" end)
else
e -> Logger.debug(fn -> "Pushing salmon to #{salmon} failed, #{inspect(e)}" end)

View file

@ -450,4 +450,8 @@ defmodule HTTPoisonMock do
def post(url, body, headers) do
{:error, "Not implemented the mock response for post #{inspect(url)}"}
end
def post(url, body, headers, options) do
{:error, "Not implemented the mock response for post #{inspect(url)}"}
end
end