namings
This commit is contained in:
parent
ca16ea0540
commit
33d04c1874
@ -7,8 +7,10 @@ defmodule Pleroma.HTTP.Connection do
|
||||
Connection for http-requests.
|
||||
"""
|
||||
|
||||
@hackney_options [
|
||||
@options [
|
||||
connect_timeout: 10_000,
|
||||
protocols: [:http],
|
||||
timeout: 20_000,
|
||||
recv_timeout: 20_000,
|
||||
follow_redirect: true,
|
||||
force_redirect: true,
|
||||
@ -25,17 +27,18 @@ defmodule Pleroma.HTTP.Connection do
|
||||
"""
|
||||
@spec new(Keyword.t()) :: Tesla.Env.client()
|
||||
def new(opts \\ []) do
|
||||
Tesla.client([], {@adapter, hackney_options(opts)})
|
||||
middleware = [Tesla.Middleware.FollowRedirects]
|
||||
Tesla.client(middleware, {@adapter, options(opts)})
|
||||
end
|
||||
|
||||
# fetch Hackney options
|
||||
# fetch http options
|
||||
#
|
||||
def hackney_options(opts) do
|
||||
def options(opts) do
|
||||
options = Keyword.get(opts, :adapter, [])
|
||||
adapter_options = Pleroma.Config.get([:http, :adapter], [])
|
||||
proxy_url = Pleroma.Config.get([:http, :proxy_url], nil)
|
||||
|
||||
@hackney_options
|
||||
@options
|
||||
|> Keyword.merge(adapter_options)
|
||||
|> Keyword.merge(options)
|
||||
|> Keyword.merge(proxy: proxy_url)
|
||||
|
@ -65,7 +65,7 @@ defmodule Pleroma.HTTP do
|
||||
end
|
||||
|
||||
def process_request_options(options) do
|
||||
Keyword.merge(Pleroma.HTTP.Connection.hackney_options([]), options)
|
||||
Keyword.merge(Pleroma.HTTP.Connection.options([]), options)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
@ -94,7 +94,7 @@ defmodule Pleroma.ReverseProxy do
|
||||
|
||||
def call(conn = %{method: method}, url, opts) when method in @methods do
|
||||
hackney_opts =
|
||||
Pleroma.HTTP.Connection.hackney_options([])
|
||||
Pleroma.HTTP.Connection.options([])
|
||||
|> Keyword.merge(@default_hackney_options)
|
||||
|> Keyword.merge(Keyword.get(opts, :http, []))
|
||||
|> HTTP.process_request_options()
|
||||
|
@ -11,7 +11,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy do
|
||||
|
||||
require Logger
|
||||
|
||||
@hackney_options [
|
||||
@options [
|
||||
pool: :media,
|
||||
recv_timeout: 10_000
|
||||
]
|
||||
@ -21,7 +21,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy do
|
||||
|
||||
url
|
||||
|> MediaProxy.url()
|
||||
|> HTTP.get([], adapter: @hackney_options)
|
||||
|> HTTP.get([], adapter: @options)
|
||||
end
|
||||
|
||||
def perform(:preload, %{"object" => %{"attachment" => attachments}} = _message) do
|
||||
|
@ -3,7 +3,7 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.RelMe do
|
||||
@hackney_options [
|
||||
@options [
|
||||
pool: :media,
|
||||
recv_timeout: 2_000,
|
||||
max_body: 2_000_000,
|
||||
@ -25,7 +25,7 @@ defmodule Pleroma.Web.RelMe do
|
||||
def parse(_), do: {:error, "No URL provided"}
|
||||
|
||||
defp parse_url(url) do
|
||||
{:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], adapter: @hackney_options)
|
||||
{:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], adapter: @options)
|
||||
|
||||
data =
|
||||
Floki.attribute(html, "link[rel~=me]", "href") ++
|
||||
|
@ -3,7 +3,7 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.RichMedia.Parser do
|
||||
@hackney_options [
|
||||
@options [
|
||||
pool: :media,
|
||||
recv_timeout: 2_000,
|
||||
max_body: 2_000_000,
|
||||
@ -78,7 +78,7 @@ defmodule Pleroma.Web.RichMedia.Parser do
|
||||
|
||||
defp parse_url(url) do
|
||||
try do
|
||||
{:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], adapter: @hackney_options)
|
||||
{:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], adapter: @options)
|
||||
|
||||
html
|
||||
|> maybe_parse()
|
||||
|
4
mix.exs
4
mix.exs
@ -112,7 +112,9 @@ defmodule Pleroma.Mixfile do
|
||||
{:cachex, "~> 3.0.2"},
|
||||
{:poison, "~> 3.0", override: true},
|
||||
{:tesla,
|
||||
github: "teamon/tesla", ref: "97950754a77cde4e162ada31fb9d8cf4fd6ab822", override: true},
|
||||
github: "alex-strizhakov/tesla",
|
||||
ref: "9ad792fb630bdfc2266ed13b830c28b6552fb3f9",
|
||||
override: true},
|
||||
{:cowlib, "~> 2.6.0", override: true},
|
||||
{:gun, "~> 1.3"},
|
||||
{:jason, "~> 1.0"},
|
||||
|
2
mix.lock
2
mix.lock
@ -85,7 +85,7 @@
|
||||
"swoosh": {:hex, :swoosh, "0.23.2", "7dda95ff0bf54a2298328d6899c74dae1223777b43563ccebebb4b5d2b61df38", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}], "hexpm"},
|
||||
"syslog": {:git, "https://github.com/Vagabond/erlang-syslog.git", "4a6c6f2c996483e86c1320e9553f91d337bcb6aa", [tag: "1.0.5"]},
|
||||
"telemetry": {:hex, :telemetry, "0.4.0", "8339bee3fa8b91cb84d14c2935f8ecf399ccd87301ad6da6b71c09553834b2ab", [:rebar3], [], "hexpm"},
|
||||
"tesla": {:git, "https://github.com/teamon/tesla.git", "97950754a77cde4e162ada31fb9d8cf4fd6ab822", [ref: "97950754a77cde4e162ada31fb9d8cf4fd6ab822"]},
|
||||
"tesla": {:git, "https://github.com/alex-strizhakov/tesla.git", "9ad792fb630bdfc2266ed13b830c28b6552fb3f9", [ref: "9ad792fb630bdfc2266ed13b830c28b6552fb3f9"]},
|
||||
"timex": {:hex, :timex, "3.6.1", "efdf56d0e67a6b956cc57774353b0329c8ab7726766a11547e529357ffdc1d56", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5 or ~> 1.0.0", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"trailing_format_plug": {:hex, :trailing_format_plug, "0.0.7", "64b877f912cf7273bed03379936df39894149e35137ac9509117e59866e10e45", [:mix], [{:plug, "> 0.12.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"tzdata": {:hex, :tzdata, "0.5.21", "8cbf3607fcce69636c672d5be2bbb08687fe26639a62bdcc283d267277db7cf0", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
|
Loading…
Reference in New Issue
Block a user