From 61c1058d67ae5621687a95fbc1f6dcc71fbc42a7 Mon Sep 17 00:00:00 2001 From: Michael Manfre Date: Sun, 4 Dec 2022 11:32:25 -0500 Subject: Add TAKAHE_DEFAULT_TIMEOUT with default of 5.0 (#99) --- core/signatures.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'core') 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, -- cgit v1.2.3