From ec831751004e024aeff48f2afdbd4b90bc43e8e8 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 19 Mar 2018 17:42:09 +0100 Subject: [PATCH] Use connection pools. --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- lib/pleroma/web/federator/federator.ex | 2 +- lib/pleroma/web/media_proxy/controller.ex | 4 ++-- lib/pleroma/web/salmon/salmon.ex | 2 +- test/support/httpoison_mock.ex | 4 ++++ 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 414b09291..d51a22742 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -351,7 +351,7 @@ def publish_one(%{inbox: inbox, json: json, actor: actor, id: id}) 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: diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index 57e11b4fb..88475397a 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -96,7 +96,7 @@ def handle(:publish_single_websub, %{xml: xml, topic: topic, callback: callback, 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) diff --git a/lib/pleroma/web/media_proxy/controller.ex b/lib/pleroma/web/media_proxy/controller.ex index 9327e7253..b0bbe8b64 100644 --- a/lib/pleroma/web/media_proxy/controller.ex +++ b/lib/pleroma/web/media_proxy/controller.ex @@ -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 @@ def remote(conn, %{"sig" => sig, "url" => url}) 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), diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index 46ca645d1..db1429c5e 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -147,7 +147,7 @@ def remote_users(%{data: %{"to" => to} = data}) 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) diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index a8b1a60c0..a45eaf170 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -450,4 +450,8 @@ def get(url, body, headers) 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