logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

http.ex (1126B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.MediaProxy.Invalidation.Http do
  5. @moduledoc false
  6. @behaviour Pleroma.Web.MediaProxy.Invalidation
  7. require Logger
  8. @impl Pleroma.Web.MediaProxy.Invalidation
  9. def purge(urls, opts \\ []) do
  10. method = Keyword.get(opts, :method, :purge)
  11. headers = Keyword.get(opts, :headers, [])
  12. options = Keyword.get(opts, :options, [])
  13. Logger.debug("Running cache purge: #{inspect(urls)}")
  14. Enum.each(urls, fn url ->
  15. with {:error, error} <- do_purge(method, url, headers, options) do
  16. Logger.error("Error while cache purge: url - #{url}, error: #{inspect(error)}")
  17. end
  18. end)
  19. {:ok, urls}
  20. end
  21. defp do_purge(method, url, headers, options) do
  22. case Pleroma.HTTP.request(method, url, "", headers, options) do
  23. {:ok, %{status: status} = env} when 400 <= status and status < 500 ->
  24. {:error, env}
  25. {:error, _} = error ->
  26. error
  27. _ ->
  28. {:ok, "success"}
  29. end
  30. end
  31. end