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