logo

pleroma

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

hackney.ex (1063B)


  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.HTTP.AdapterHelper.Hackney do
  5. @behaviour Pleroma.HTTP.AdapterHelper
  6. @defaults [
  7. follow_redirect: true,
  8. force_redirect: true
  9. ]
  10. @spec options(keyword(), URI.t()) :: keyword()
  11. def options(connection_opts \\ [], %URI{} = uri) do
  12. proxy = Pleroma.Config.get([:http, :proxy_url])
  13. config_opts = Pleroma.Config.get([:http, :adapter], [])
  14. url_encoding =
  15. Keyword.new()
  16. |> Keyword.put(:path_encode_fun, fn path -> path end)
  17. @defaults
  18. |> Keyword.merge(url_encoding)
  19. |> Keyword.merge(config_opts)
  20. |> Keyword.merge(connection_opts)
  21. |> add_scheme_opts(uri)
  22. |> maybe_add_with_body()
  23. |> Pleroma.HTTP.AdapterHelper.maybe_add_proxy(proxy)
  24. end
  25. defp add_scheme_opts(opts, _), do: opts
  26. defp maybe_add_with_body(opts) do
  27. if opts[:max_body] do
  28. Keyword.put(opts, :with_body, true)
  29. else
  30. opts
  31. end
  32. end
  33. end