Use connection pools.
This commit is contained in:
parent
4d5161b16d
commit
ec83175100
|
@ -351,7 +351,7 @@ def publish_one(%{inbox: inbox, json: json, actor: actor, id: id}) do
|
||||||
Logger.info("Federating #{id} to #{inbox}")
|
Logger.info("Federating #{id} to #{inbox}")
|
||||||
host = URI.parse(inbox).host
|
host = URI.parse(inbox).host
|
||||||
signature = Pleroma.Web.HTTPSignatures.sign(actor, %{host: host, "content-length": byte_size(json)})
|
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
|
end
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
|
|
|
@ -96,7 +96,7 @@ def handle(:publish_single_websub, %{xml: xml, topic: topic, callback: callback,
|
||||||
with {:ok, %{status_code: code}} <- @httpoison.post(callback, xml, [
|
with {:ok, %{status_code: code}} <- @httpoison.post(callback, xml, [
|
||||||
{"Content-Type", "application/atom+xml"},
|
{"Content-Type", "application/atom+xml"},
|
||||||
{"X-Hub-Signature", "sha1=#{signature}"}
|
{"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)
|
Logger.debug(fn -> "Pushed to #{callback}, code #{code}" end)
|
||||||
else e ->
|
else e ->
|
||||||
Logger.debug(fn -> "Couldn't push to #{callback}, #{inspect(e)}" end)
|
Logger.debug(fn -> "Couldn't push to #{callback}, #{inspect(e)}" end)
|
||||||
|
|
|
@ -31,7 +31,7 @@ def remote(conn, %{"sig" => sig, "url" => url}) do
|
||||||
|
|
||||||
defp proxy_request(link) do
|
defp proxy_request(link) do
|
||||||
headers = [{"user-agent", "Pleroma/MediaProxy; #{Pleroma.Web.base_url()} <#{Application.get_env(:pleroma, :instance)[:email]}>"}]
|
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 \
|
with \
|
||||||
{:ok, 200, headers, client} <- :hackney.request(:get, link, headers, "", options),
|
{:ok, 200, headers, client} <- :hackney.request(:get, link, headers, "", options),
|
||||||
headers = Enum.into(headers, Map.new),
|
headers = Enum.into(headers, Map.new),
|
||||||
|
|
|
@ -147,7 +147,7 @@ def remote_users(%{data: %{"to" => to} = data}) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp send_to_user(%{info: %{"salmon" => salmon}}, feed, poster) do
|
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)
|
Logger.debug(fn -> "Pushed to #{salmon}, code #{code}" end)
|
||||||
else
|
else
|
||||||
e -> Logger.debug(fn -> "Pushing salmon to #{salmon} failed, #{inspect(e)}" end)
|
e -> Logger.debug(fn -> "Pushing salmon to #{salmon} failed, #{inspect(e)}" end)
|
||||||
|
|
|
@ -450,4 +450,8 @@ def get(url, body, headers) do
|
||||||
def post(url, body, headers) do
|
def post(url, body, headers) do
|
||||||
{:error, "Not implemented the mock response for post #{inspect(url)}"}
|
{:error, "Not implemented the mock response for post #{inspect(url)}"}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def post(url, body, headers, options) do
|
||||||
|
{:error, "Not implemented the mock response for post #{inspect(url)}"}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue