From a418547bdfc95b72497faa0eb5da69b04f6a8566 Mon Sep 17 00:00:00 2001 From: hakabahitoyo Date: Wed, 5 Dec 2018 16:08:34 +0900 Subject: [PATCH 1/4] debug /api/v1/suggestions --- .../web/mastodon_api/mastodon_api_controller.ex | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index ea64f163d..f9007a808 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1169,7 +1169,15 @@ def suggestions(%{assigns: %{user: user}} = conn, _) do url = String.replace(api, "{{host}}", host) |> String.replace("{{user}}", user) with {:ok, %{status: 200, body: body}} <- - @httpoison.get(url, [], timeout: timeout, recv_timeout: timeout), + @httpoison.get( + url, + [], + follow_redirect: true, + adapter: [ + timeout: timeout, + recv_timeout: timeout + ] + ), {:ok, data} <- Jason.decode(body) do data2 = Enum.slice(data, 0, limit) From 27792b2d77564717e7d4063ab3524ab9e1cb1fb6 Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Thu, 6 Dec 2018 11:23:15 +0900 Subject: [PATCH 2/4] remove pool and timeout options which duplicate with the default --- lib/pleroma/http/connection.ex | 6 +++++- lib/pleroma/web/activity_pub/activity_pub.ex | 4 +--- lib/pleroma/web/ostatus/ostatus.ex | 9 ++------- lib/pleroma/web/salmon/salmon.ex | 7 +------ lib/pleroma/web/websub/websub.ex | 5 ----- 5 files changed, 9 insertions(+), 22 deletions(-) diff --git a/lib/pleroma/http/connection.ex b/lib/pleroma/http/connection.ex index 5e8f2aabd..66e0d0568 100644 --- a/lib/pleroma/http/connection.ex +++ b/lib/pleroma/http/connection.ex @@ -3,7 +3,11 @@ defmodule Pleroma.HTTP.Connection do Connection for http-requests. """ - @hackney_options [pool: :default] + @hackney_options [ + pool: :default, + timeout: 10000, + recv_timeout: 20000 + ] @adapter Application.get_env(:tesla, :adapter) @doc """ diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 60253a715..03a607f83 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -766,9 +766,7 @@ def fetch_and_contain_remote_object_from_id(id) do @httpoison.get( id, [Accept: "application/activity+json"], - follow_redirect: true, - timeout: 10000, - recv_timeout: 20000 + follow_redirect: true ), {:ok, data} <- Jason.decode(body), :ok <- Transmogrifier.contain_origin_from_id(id, data) do diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index 67df354db..bc14b8785 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -350,11 +350,7 @@ def fetch_activity_from_atom_url(url) do @httpoison.get( url, [Accept: "application/atom+xml"], - follow_redirect: true, - adapter: [ - timeout: 10000, - recv_timeout: 20000 - ] + follow_redirect: true ) do Logger.debug("Got document from #{url}, handling...") handle_incoming(body) @@ -369,8 +365,7 @@ def fetch_activity_from_html_url(url) do Logger.debug("Trying to fetch #{url}") with true <- String.starts_with?(url, "http"), - {:ok, %{body: body}} <- - @httpoison.get(url, [], follow_redirect: true, timeout: 10000, recv_timeout: 20000), + {:ok, %{body: body}} <- @httpoison.get(url, [], follow_redirect: true), {:ok, atom_url} <- get_atom_url(body) do fetch_activity_from_atom_url(atom_url) else diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index 97251c05e..0e2cfddd0 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -162,12 +162,7 @@ defp send_to_user(%{info: %{salmon: salmon}}, feed, poster) do poster.( salmon, feed, - [{"Content-Type", "application/magic-envelope+xml"}], - adapter: [ - timeout: 10000, - recv_timeout: 20000, - pool: :default - ] + [{"Content-Type", "application/magic-envelope+xml"}] ) do Logger.debug(fn -> "Pushed to #{salmon}, code #{code}" end) else diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index 0761b5475..8cb07006f 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -264,11 +264,6 @@ def publish_one(%{xml: xml, topic: topic, callback: callback, secret: secret}) d [ {"Content-Type", "application/atom+xml"}, {"X-Hub-Signature", "sha1=#{signature}"} - ], - adapter: [ - timeout: 10000, - recv_timeout: 20000, - pool: :default ] ) do Logger.info(fn -> "Pushed to #{callback}, code #{code}" end) From 96ba95df2e6690c1c6a58cf087c91eab7af728b4 Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Thu, 6 Dec 2018 11:38:33 +0900 Subject: [PATCH 3/4] remove follow_redirect options --- lib/pleroma/http/connection.ex | 3 ++- lib/pleroma/reverse_proxy.ex | 2 +- lib/pleroma/web/activity_pub/activity_pub.ex | 3 +-- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 1 - lib/pleroma/web/ostatus/ostatus.ex | 5 ++--- lib/pleroma/web/web_finger/web_finger.ex | 2 +- 6 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/pleroma/http/connection.ex b/lib/pleroma/http/connection.ex index 66e0d0568..db46f9e55 100644 --- a/lib/pleroma/http/connection.ex +++ b/lib/pleroma/http/connection.ex @@ -6,7 +6,8 @@ defmodule Pleroma.HTTP.Connection do @hackney_options [ pool: :default, timeout: 10000, - recv_timeout: 20000 + recv_timeout: 20000, + follow_redirect: true ] @adapter Application.get_env(:tesla, :adapter) diff --git a/lib/pleroma/reverse_proxy.ex b/lib/pleroma/reverse_proxy.ex index ad9dc82fe..4ca84152a 100644 --- a/lib/pleroma/reverse_proxy.ex +++ b/lib/pleroma/reverse_proxy.ex @@ -56,7 +56,7 @@ defmodule Pleroma.ReverseProxy do @hackney Application.get_env(:pleroma, :hackney, :hackney) @httpoison Application.get_env(:pleroma, :httpoison, HTTPoison) - @default_hackney_options [{:follow_redirect, true}] + @default_hackney_options [] @inline_content_types [ "image/gif", diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 03a607f83..922ffb946 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -765,8 +765,7 @@ def fetch_and_contain_remote_object_from_id(id) do {:ok, %{body: body, status: code}} when code in 200..299 <- @httpoison.get( id, - [Accept: "application/activity+json"], - follow_redirect: true + Accept: "application/activity+json" ), {:ok, data} <- Jason.decode(body), :ok <- Transmogrifier.contain_origin_from_id(id, data) do diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 300bdc04a..fc4f3fdc7 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1185,7 +1185,6 @@ def suggestions(%{assigns: %{user: user}} = conn, _) do @httpoison.get( url, [], - follow_redirect: true, adapter: [ timeout: timeout, recv_timeout: timeout diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index bc14b8785..9f33cd5cd 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -349,8 +349,7 @@ def fetch_activity_from_atom_url(url) do {:ok, %{body: body, status: code}} when code in 200..299 <- @httpoison.get( url, - [Accept: "application/atom+xml"], - follow_redirect: true + Accept: "application/atom+xml" ) do Logger.debug("Got document from #{url}, handling...") handle_incoming(body) @@ -365,7 +364,7 @@ def fetch_activity_from_html_url(url) do Logger.debug("Trying to fetch #{url}") with true <- String.starts_with?(url, "http"), - {:ok, %{body: body}} <- @httpoison.get(url, [], follow_redirect: true), + {:ok, %{body: body}} <- @httpoison.get(url, []), {:ok, atom_url} <- get_atom_url(body) do fetch_activity_from_atom_url(atom_url) else diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 99c65a6bf..0ff3b8b5f 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -221,7 +221,7 @@ def get_template_from_xml(body) do def find_lrdd_template(domain) do with {:ok, %{status: status, body: body}} when status in 200..299 <- - @httpoison.get("http://#{domain}/.well-known/host-meta", [], follow_redirect: true) do + @httpoison.get("http://#{domain}/.well-known/host-meta", []) do get_template_from_xml(body) else _ -> From a09ed0f5afe6336763b47edab0c0d9a629a74ad0 Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Thu, 6 Dec 2018 18:41:29 +0900 Subject: [PATCH 4/4] avoid mix format bug --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- lib/pleroma/web/ostatus/ostatus.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 922ffb946..a1637ccad 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -765,7 +765,7 @@ def fetch_and_contain_remote_object_from_id(id) do {:ok, %{body: body, status: code}} when code in 200..299 <- @httpoison.get( id, - Accept: "application/activity+json" + [{:Accept, "application/activity+json"}] ), {:ok, data} <- Jason.decode(body), :ok <- Transmogrifier.contain_origin_from_id(id, data) do diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index 9f33cd5cd..53d71440e 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -349,7 +349,7 @@ def fetch_activity_from_atom_url(url) do {:ok, %{body: body, status: code}} when code in 200..299 <- @httpoison.get( url, - Accept: "application/atom+xml" + [{:Accept, "application/atom+xml"}] ) do Logger.debug("Got document from #{url}, handling...") handle_incoming(body)