http timeout config #307

Merged
floatingghost merged 3 commits from http-timeout-config into develop 2022-11-24 12:27:17 +00:00
5 changed files with 47 additions and 3 deletions
Showing only changes of commit b33b785a56 - Show all commits

View file

@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## Unreleased
## Added
- Config: HTTP timeout options, :pool\_timeout and :receive\_timeout
## Changed
- MastoAPI: Accept BooleanLike input on `/api/v1/accounts/:id/follow` (fixes follows with mastodon.py)

View file

@ -180,6 +180,8 @@
# Configures http settings, upstream proxy etc.
config :pleroma, :http,
pool_timeout: :timer.seconds(5),
receive_timeout: :timer.seconds(15),
proxy_url: nil,
user_agent: :default,
adapter: []

View file

@ -2658,6 +2658,20 @@
type: :group,
description: "HTTP settings",
children: [
%{
key: :pool_timeout,
label: "HTTP Pool Request Timeout",
type: :integer,
description: "Timeout for initiating HTTP requests (in ms, default 5000)",
suggestions: [5000]
},
%{
key: :receive_timeout,
label: "HTTP Receive Timeout",
type: :integer,
description: "Timeout for waiting on remote servers to respond to HTTP requests (in ms, default 15000)",
suggestions: [15000]
},
%{
key: :proxy_url,
label: "Proxy URL",

View file

@ -10,7 +10,13 @@ defmodule Pleroma.HTTP.AdapterHelper.Default do
@spec options(keyword(), URI.t()) :: keyword()
def options(opts, _uri) do
proxy = Pleroma.Config.get([:http, :proxy_url])
AdapterHelper.maybe_add_proxy(opts, AdapterHelper.format_proxy(proxy))
pool_timeout = Pleroma.Config.get([:http, :pool_timeout], 5000)
receive_timeout = Pleroma.Config.get([:http, :receive_timeout], 15_000)
opts
|> AdapterHelper.maybe_add_proxy(AdapterHelper.format_proxy(proxy))
|> Keyword.put(:pool_timeout, pool_timeout)
|> Keyword.put(:receive_timeout, receive_timeout)
end
@spec get_conn(URI.t(), keyword()) :: {:ok, keyword()}

View file

@ -3,8 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.HTTP.AdapterHelperTest do
use ExUnit.Case, async: true
use Pleroma.DataCase, async: true
alias Pleroma.HTTP.AdapterHelper
describe "format_proxy/1" do
@ -47,4 +46,24 @@ test "should not override conn_opts if set" do
]
end
end
describe "timeout settings" do
test "should default to 5000/15000" do
options = AdapterHelper.options(%URI{host: 'somewhere'})
assert options[:pool_timeout] == 5000
assert options[:receive_timeout] == 15_000
end
test "pool_timeout should be overridden by :http, :pool_timeout" do
clear_config([:http, :pool_timeout], 10_000)
options = AdapterHelper.options(%URI{host: 'somewhere'})
assert options[:pool_timeout] == 10_000
end
test "receive_timeout should be overridden by :http, :receive_timeout" do
clear_config([:http, :receive_timeout], 20_000)
options = AdapterHelper.options(%URI{host: 'somewhere'})
assert options[:receive_timeout] == 20_000
end
end
end