http: do not mix and duplicate Tesla opts into adapter opts
This commit is contained in:
parent
271d7d14d4
commit
c607387b4a
9 changed files with 14 additions and 13 deletions
|
|
@ -580,7 +580,7 @@ defp get_filename(pack, shortcode) do
|
|||
defp http_get(%URI{} = url), do: url |> to_string() |> http_get()
|
||||
|
||||
defp http_get(url) do
|
||||
with {:ok, %{body: body}} <- Pleroma.HTTP.get(url, [], []) do
|
||||
with {:ok, %{body: body}} <- Pleroma.HTTP.get(url) do
|
||||
Jason.decode(body)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ defp download_build(frontend_info, dest) do
|
|||
url = String.replace(frontend_info["build_url"], "${ref}", frontend_info["ref"])
|
||||
|
||||
with {:ok, %{status: 200, body: zip_body}} <-
|
||||
Pleroma.HTTP.get(url, [], receive_timeout: 120_000) do
|
||||
Pleroma.HTTP.get(url, [], adapter: [receive_timeout: 120_000]) do
|
||||
unzip(zip_body, dest)
|
||||
else
|
||||
{:error, e} -> {:error, e}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ def missing_dependencies do
|
|||
def image_resize(url, options) do
|
||||
with executable when is_binary(executable) <- System.find_executable("convert"),
|
||||
{:ok, args} <- prepare_image_resize_args(options),
|
||||
{:ok, env} <- HTTP.get(url, [], []),
|
||||
{:ok, env} <- HTTP.get(url),
|
||||
{:ok, fifo_path} <- mkfifo() do
|
||||
args = List.flatten([fifo_path, args])
|
||||
run_fifo(fifo_path, env, executable, args)
|
||||
|
|
@ -73,7 +73,7 @@ defp prepare_image_resize_args(_), do: {:error, :missing_options}
|
|||
# Note: video thumbnail is intentionally not resized (always has original dimensions)
|
||||
def video_framegrab(url) do
|
||||
with executable when is_binary(executable) <- System.find_executable("ffmpeg"),
|
||||
{:ok, env} <- HTTP.get(url, [], []),
|
||||
{:ok, env} <- HTTP.get(url),
|
||||
{:ok, fifo_path} <- mkfifo(),
|
||||
args = [
|
||||
"-y",
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ def post(url, body, headers \\ [], options \\ []),
|
|||
{:ok, Env.t()} | {:error, any()}
|
||||
def request(method, url, body, headers, options) when is_binary(url) do
|
||||
uri = URI.parse(url)
|
||||
adapter_opts = AdapterHelper.options(options || [])
|
||||
adapter_opts = AdapterHelper.options(options[:adapter] || [])
|
||||
|
||||
adapter_opts =
|
||||
if uri.scheme == :https do
|
||||
|
|
@ -71,6 +71,7 @@ def request(method, url, body, headers, options) when is_binary(url) do
|
|||
|
||||
options = put_in(options[:adapter], adapter_opts)
|
||||
params = options[:params] || []
|
||||
options = options |> Keyword.delete(:params)
|
||||
request = build_request(method, headers, options, url, body, params)
|
||||
|
||||
client =
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ defp scrape_nodeinfo(%URI{} = instance_uri) do
|
|||
{:ok,
|
||||
Enum.find(links, &(&1["rel"] == "http://nodeinfo.diaspora.software/ns/schema/2.0"))},
|
||||
{:ok, %Tesla.Env{body: data}} <-
|
||||
Pleroma.HTTP.get(href, [{"accept", "application/json"}], []),
|
||||
Pleroma.HTTP.get(href, [{"accept", "application/json"}]),
|
||||
{:length, true} <- {:length, String.length(data) < 50_000},
|
||||
{:ok, nodeinfo} <- Jason.decode(data) do
|
||||
nodeinfo
|
||||
|
|
@ -270,7 +270,7 @@ defp scrape_favicon(%URI{} = instance_uri) do
|
|||
with true <- Pleroma.Config.get([:instances_favicons, :enabled]),
|
||||
{_, true} <- {:reachable, reachable?(instance_uri.host)},
|
||||
{:ok, %Tesla.Env{body: html}} <-
|
||||
Pleroma.HTTP.get(to_string(instance_uri), [{"accept", "text/html"}], []),
|
||||
Pleroma.HTTP.get(to_string(instance_uri), [{"accept", "text/html"}]),
|
||||
{_, [favicon_rel | _]} when is_binary(favicon_rel) <-
|
||||
{:parse, html |> Floki.parse_document!() |> Floki.attribute("link[rel=icon]", "href")},
|
||||
{_, favicon} when is_binary(favicon) <-
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy do
|
|||
|
||||
require Logger
|
||||
|
||||
@adapter_options [
|
||||
receive_timeout: 10_000
|
||||
@http_options [
|
||||
adapter: [receive_timeout: 10_000]
|
||||
]
|
||||
|
||||
@impl true
|
||||
|
|
@ -36,7 +36,7 @@ defp prefetch(url) do
|
|||
end
|
||||
end
|
||||
|
||||
defp fetch(url), do: HTTP.get(url, [], @adapter_options)
|
||||
defp fetch(url), do: HTTP.get(url, [], @http_options)
|
||||
|
||||
defp preload(%{"object" => %{"attachment" => attachments}} = _message) do
|
||||
Enum.each(attachments, fn
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ defp get_int_header(headers, header_name, default \\ nil) do
|
|||
|
||||
defp is_remote_size_within_limit?(url) do
|
||||
with {:ok, %{status: status, headers: headers} = _response} when status in 200..299 <-
|
||||
Pleroma.HTTP.request(:head, url, nil, [], []) do
|
||||
Pleroma.HTTP.head(url) do
|
||||
content_length = get_int_header(headers, "content-length")
|
||||
size_limit = Config.get([:mrf_steal_emoji, :size_limit], @size_limit)
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ defp handle_preview(conn, url) do
|
|||
media_proxy_url = MediaProxy.url(url)
|
||||
|
||||
with {:ok, %{status: status} = head_response} when status in 200..299 <-
|
||||
Pleroma.HTTP.request(:head, media_proxy_url, [], [], name: MyFinch) do
|
||||
Pleroma.HTTP.head(media_proxy_url) do
|
||||
content_type = Tesla.get_header(head_response, "content-type")
|
||||
content_length = Tesla.get_header(head_response, "content-length")
|
||||
content_length = content_length && String.to_integer(content_length)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
defmodule Pleroma.Web.RelMe do
|
||||
@options [
|
||||
receive_timeout: 2_000
|
||||
adapter: [receive_timeout: 2_000]
|
||||
]
|
||||
|
||||
if Pleroma.Config.get(:env) == :test do
|
||||
|
|
|
|||
Loading…
Reference in a new issue