Skip to content

Commit f3febc6

Browse files
committed
feat: default httpc timeout
- fixes #93
1 parent 58fc18c commit f3febc6

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

src/cryptojwt/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@
4141
}
4242

4343
JWT_HEADERS = ["typ", "cty"]
44+
DEFAULT_HTTPC_TIMEOUT = 10

src/cryptojwt/key_bundle.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from cryptojwt.jwk.hmac import new_sym_key
1717
from cryptojwt.jwk.x509 import import_private_key_from_pem_file
1818

19+
from . import DEFAULT_HTTPC_TIMEOUT
1920
from .exception import JWKException
2021
from .exception import UnknownKeyType
2122
from .exception import UnsupportedAlgorithm
@@ -254,6 +255,8 @@ def __init__(
254255
self.httpc = requests.request
255256

256257
self.httpc_params = httpc_params or {}
258+
if not self.httpc_params.get("timeout"):
259+
self.httpc_params["timeout"] = DEFAULT_HTTPC_TIMEOUT
257260

258261
if keys:
259262
self.source = None

src/cryptojwt/key_issuer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from requests import request
88

9+
from . import DEFAULT_HTTPC_TIMEOUT
910
from .jwe.utils import alg2keytype as jwe_alg2keytype
1011
from .jws.utils import alg2keytype as jws_alg2keytype
1112
from .key_bundle import KeyBundle
@@ -58,6 +59,8 @@ def __init__(
5859
self.ca_certs = ca_certs
5960
self.httpc = httpc or request
6061
self.httpc_params = httpc_params or {}
62+
if not self.httpc_params.get("timeout"):
63+
self.httpc_params["timeout"] = DEFAULT_HTTPC_TIMEOUT
6164
self.keybundle_cls = keybundle_cls
6265
self.name = name
6366
self.remove_after = remove_after

src/cryptojwt/key_jar.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from requests import request
77

8+
from . import DEFAULT_HTTPC_TIMEOUT
89
from .exception import IssuerNotFound
910
from .jwe.jwe import alg2keytype as jwe_alg2keytype
1011
from .jws.utils import alg2keytype as jws_alg2keytype
@@ -51,6 +52,9 @@ def __init__(
5152
self.remove_after = remove_after
5253
self.httpc = httpc or request
5354
self.httpc_params = httpc_params or {}
55+
if not self.httpc_params.get("timeout"):
56+
self.httpc_params["timeout"] = DEFAULT_HTTPC_TIMEOUT
57+
5458
# Now part of httpc_params
5559
# self.verify_ssl = verify_ssl
5660
if not self.httpc_params: # backward compatibility

tests/test_04_key_issuer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ def test_localhost_url():
774774

775775
kb = issuer.find(url)
776776
assert len(kb) == 1
777-
assert kb[0].httpc_params == {"verify": False}
777+
assert kb[0].httpc_params == {"timeout": 10, "verify": False}
778778

779779

780780
def test_add_url():

0 commit comments

Comments
 (0)