summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/signatures.py5
-rw-r--r--docs/index.rst1
-rw-r--r--docs/tuning.rst16
-rw-r--r--takahe/settings.py4
4 files changed, 25 insertions, 1 deletions
diff --git a/core/signatures.py b/core/signatures.py
index e2582c5..ead33da 100644
--- a/core/signatures.py
+++ b/core/signatures.py
@@ -7,9 +7,11 @@ import httpx
from cryptography.exceptions import InvalidSignature
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import padding, rsa
+from django.conf import settings
from django.http import HttpRequest
from django.utils import timezone
from django.utils.http import http_date, parse_http_date
+from httpx._types import TimeoutTypes
from pyld import jsonld
from core.ld import format_ld_date
@@ -173,6 +175,7 @@ class HttpSignature:
key_id: str,
content_type: str = "application/json",
method: Literal["get", "post"] = "post",
+ timeout: TimeoutTypes = settings.SETUP.REMOTE_TIMEOUT,
):
"""
Performs an async request to the given path, with a document, signed
@@ -219,7 +222,7 @@ class HttpSignature:
)
# Send the request with all those headers except the pseudo one
del headers["(request-target)"]
- async with httpx.AsyncClient() as client:
+ async with httpx.AsyncClient(timeout=timeout) as client:
response = await client.request(
method,
uri,
diff --git a/docs/index.rst b/docs/index.rst
index f8fbc13..2c1ff48 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -19,4 +19,5 @@ in alpha. For more information about Takahē, see
contributing
domains
stator
+ tuning
releases/index
diff --git a/docs/tuning.rst b/docs/tuning.rst
new file mode 100644
index 0000000..2b5e5d8
--- /dev/null
+++ b/docs/tuning.rst
@@ -0,0 +1,16 @@
+Tuning
+======
+
+This page contains a collection of tips and settings that can be used to
+tune your server based upon its users and the other servers it federates
+with.
+
+Federating
+----------
+
+Environment Variable:
+
+* ``TAKAHE_REMOTE_TIMEOUT`` is the number of seconds Takahē will allow when
+ making remote requests to other Fediverse instances. This may also be a
+ tuple of four floats to set the timeouts for connect, read, write, and
+ pool. Example ``TAKAHE_REMOTE_TIMEOUT='[0.5, 1.0, 1.0, 0.5]'``
diff --git a/takahe/settings.py b/takahe/settings.py
index 926aac5..856c22c 100644
--- a/takahe/settings.py
+++ b/takahe/settings.py
@@ -90,6 +90,10 @@ class Settings(BaseSettings):
MEDIA_ROOT: str = str(BASE_DIR / "media")
MEDIA_BACKEND: Optional[MediaBackendUrl] = None
+ #: Request timeouts to use when talking to other servers Either
+ #: float or tuple of floats for (connect, read, write, pool)
+ REMOTE_TIMEOUT: float | tuple[float, float, float, float] = 5.0
+
#: If search features like full text search should be enabled.
#: (placeholder setting, no effect)
SEARCH: bool = True