aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/http/http.ex
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2020-05-17 22:16:02 +0300
committerrinpatch <rinpatch@sdf.org>2020-07-15 15:26:35 +0300
commit4128e3a84a2b6d75a8f92759e65ee673b47cec01 (patch)
treeb2202efe95dbb008bdbfda6e879bacaf7c116d0d /lib/pleroma/http/http.ex
parent94c8f3cfafb92c6d092549b24bb69f3870e1c0d8 (diff)
downloadpleroma-4128e3a84a2b6d75a8f92759e65ee673b47cec01.tar.gz
HTTP: Implement max request limits
Diffstat (limited to 'lib/pleroma/http/http.ex')
-rw-r--r--lib/pleroma/http/http.ex17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/pleroma/http/http.ex b/lib/pleroma/http/http.ex
index afcb4d738..6128bc4cf 100644
--- a/lib/pleroma/http/http.ex
+++ b/lib/pleroma/http/http.ex
@@ -71,7 +71,13 @@ defmodule Pleroma.HTTP do
adapter = Application.get_env(:tesla, :adapter)
client = Tesla.client([Pleroma.HTTP.Middleware.FollowRedirects], adapter)
- request(client, request)
+ maybe_limit(
+ fn ->
+ request(client, request)
+ end,
+ adapter,
+ adapter_opts
+ )
# Connection release is handled in a custom FollowRedirects middleware
err ->
@@ -92,4 +98,13 @@ defmodule Pleroma.HTTP do
|> Builder.add_param(:query, :query, params)
|> Builder.convert_to_keyword()
end
+
+ @prefix Pleroma.Gun.ConnectionPool
+ defp maybe_limit(fun, Tesla.Adapter.Gun, opts) do
+ ConcurrentLimiter.limit(:"#{@prefix}.#{opts[:pool] || :default}", fun)
+ end
+
+ defp maybe_limit(fun, _, _) do
+ fun.()
+ end
end