2020-10-12 17:00:50 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-10-12 17:00:50 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-03-03 15:53:44 +00:00
|
|
|
defmodule Pleroma.HTTP.AdapterHelper.Hackney do
|
|
|
|
@behaviour Pleroma.HTTP.AdapterHelper
|
2020-02-11 07:12:57 +00:00
|
|
|
|
|
|
|
@defaults [
|
|
|
|
follow_redirect: true,
|
2020-09-04 16:05:08 +00:00
|
|
|
force_redirect: true
|
2020-02-11 07:12:57 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
@spec options(keyword(), URI.t()) :: keyword()
|
|
|
|
def options(connection_opts \\ [], %URI{} = uri) do
|
2020-03-13 06:37:57 +00:00
|
|
|
proxy = Pleroma.Config.get([:http, :proxy_url])
|
2020-02-11 07:12:57 +00:00
|
|
|
|
2020-03-06 18:24:19 +00:00
|
|
|
config_opts = Pleroma.Config.get([:http, :adapter], [])
|
|
|
|
|
2020-02-11 07:12:57 +00:00
|
|
|
@defaults
|
2020-03-06 18:24:19 +00:00
|
|
|
|> Keyword.merge(config_opts)
|
2020-02-11 07:12:57 +00:00
|
|
|
|> Keyword.merge(connection_opts)
|
|
|
|
|> add_scheme_opts(uri)
|
2020-09-04 16:05:08 +00:00
|
|
|
|> maybe_add_with_body()
|
2020-03-03 15:53:44 +00:00
|
|
|
|> Pleroma.HTTP.AdapterHelper.maybe_add_proxy(proxy)
|
2020-02-11 07:12:57 +00:00
|
|
|
end
|
|
|
|
|
2020-05-30 10:59:04 +00:00
|
|
|
defp add_scheme_opts(opts, _), do: opts
|
2020-09-04 16:05:08 +00:00
|
|
|
|
|
|
|
defp maybe_add_with_body(opts) do
|
|
|
|
if opts[:max_body] do
|
|
|
|
Keyword.put(opts, :with_body, true)
|
|
|
|
else
|
|
|
|
opts
|
|
|
|
end
|
|
|
|
end
|
2020-02-11 07:12:57 +00:00
|
|
|
end
|