Merge branch 'feld-Logger' into 'develop'
authorlambda <pleromagit@rogerbraun.net>
Tue, 20 Mar 2018 05:57:47 +0000 (05:57 +0000)
committerlambda <pleromagit@rogerbraun.net>
Tue, 20 Mar 2018 05:57:47 +0000 (05:57 +0000)
Logging cleanup

See merge request pleroma/pleroma!76

lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/federator/federator.ex
lib/pleroma/web/mastodon_api/views/status_view.ex
lib/pleroma/web/media_proxy/controller.ex
lib/pleroma/web/ostatus/ostatus.ex
lib/pleroma/web/salmon/salmon.ex
test/support/httpoison_mock.ex
test/web/mastodon_api/status_view_test.exs

index 6a78a6bee74ed6455826461307917566bab25e9d..7b1207ce274876f8157e6629f446efd63c8a07f8 100644 (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:
@@ -361,7 +361,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
       {:ok, object}
     else
       Logger.info("Fetching #{id} via AP")
-      with {:ok, %{body: body, status_code: code}} when code in 200..299 <- @httpoison.get(id, [Accept: "application/activity+json"], follow_redirect: true, timeout: 10000, recv_timeout: 20000),
+      with true <- String.starts_with?(id, "http"),
+           {:ok, %{body: body, status_code: code}} when code in 200..299 <- @httpoison.get(id, [Accept: "application/activity+json"], follow_redirect: true, timeout: 10000, recv_timeout: 20000),
            {:ok, data} <- Poison.decode(body),
            nil <- Object.get_by_ap_id(data["id"]),
            params <- %{"type" => "Create", "to" => data["to"], "cc" => data["cc"], "actor" => data["attributedTo"], "object" => data},
index 4082773f3683cd0300c8637577827469289b91a5..51d2931960bd3b043f499967aad922371b1fe2c1 100644 (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)
index 4f395d0f7ab0ce9ad0a7e4aa6a9af33bfd098bb3..55675ae1c38b624f71db2e4df5ee76b020a0a0b4 100644 (file)
@@ -16,7 +16,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
     reblogged = Activity.get_create_activity_by_object_ap_id(object)
     reblogged = render("status.json", Map.put(opts, :activity, reblogged))
 
-    mentions = activity.data["to"]
+    mentions = activity.recipients
     |> Enum.map(fn (ap_id) -> User.get_cached_by_ap_id(ap_id) end)
     |> Enum.filter(&(&1))
     |> Enum.map(fn (user) -> AccountView.render("mention.json", %{user: user}) end)
@@ -60,7 +60,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
     tags = object["tag"] || []
     sensitive = object["sensitive"] || Enum.member?(tags, "nsfw")
 
-    mentions = activity.data["to"]
+    mentions = activity.recipients
     |> Enum.map(fn (ap_id) -> User.get_cached_by_ap_id(ap_id) end)
     |> Enum.filter(&(&1))
     |> Enum.map(fn (user) -> AccountView.render("mention.json", %{user: user}) end)
index 9327e7253aa949243d63dd4a1de91c7465238552..b0bbe8b64a8c5ef43c65afe8e5aeb96d11699b94 100644 (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),
index 72f5b8d526f1260b80f283afc0ac58e67beb9a1c..f3ef4d69097782160f6044c1dbb3be9701f27a76 100644 (file)
@@ -297,7 +297,8 @@ defmodule Pleroma.Web.OStatus do
   end
 
   def fetch_activity_from_atom_url(url) do
-    with {:ok, %{body: body, status_code: code}} when code in 200..299 <- @httpoison.get(url, [Accept: "application/atom+xml"], follow_redirect: true, timeout: 10000, recv_timeout: 20000) do
+    with true <- String.starts_with?(url, "http"),
+         {:ok, %{body: body, status_code: code}} when code in 200..299 <- @httpoison.get(url, [Accept: "application/atom+xml"], follow_redirect: true, timeout: 10000, recv_timeout: 20000) do
       Logger.debug("Got document from #{url}, handling...")
       handle_incoming(body)
     else
@@ -309,7 +310,8 @@ defmodule Pleroma.Web.OStatus do
 
   def fetch_activity_from_html_url(url) do
     Logger.debug("Trying to fetch #{url}")
-    with {:ok, %{body: body}} <- @httpoison.get(url, [], follow_redirect: true, timeout: 10000, recv_timeout: 20000),
+    with true <- String.starts_with?(url, "http"),
+         {:ok, %{body: body}} <- @httpoison.get(url, [], follow_redirect: true, timeout: 10000, recv_timeout: 20000),
          {:ok, atom_url} <- get_atom_url(body) do
         fetch_activity_from_atom_url(atom_url)
     else
index caab5d484762fca115341c611c89d5445a4e91c9..ab0f97d5544e10dd059c799fc3871449e3c83a15 100644 (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)
index a8b1a60c04a805b03a1a20eb3c7aab944c8c350f..a45eaf17062b820142c23e8303b266490a4732cb 100644 (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
index 0d396f3b8418a97988b8473631afb3ce96007e24..9e2bc3c185ce8bf4eb2d70b1aaf4b412ed76b604 100644 (file)
@@ -60,6 +60,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
     recipient = "https://pleroma.soykaf.com/users/lain"
     user = User.get_cached_by_ap_id(recipient) || insert(:user, %{ap_id: recipient})
 
+    # invalidate the cache
+    User.invalidate_cache(user)
+
     {:ok, [activity]} = OStatus.handle_incoming(incoming)
 
     status = StatusView.render("status.json", %{activity: activity})