]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Add keepalive_expiry to Limits config (#1398)
authorTom Christie <tom@tomchristie.com>
Wed, 25 Nov 2020 15:32:37 +0000 (15:32 +0000)
committerGitHub <noreply@github.com>
Wed, 25 Nov 2020 15:32:37 +0000 (15:32 +0000)
* Add keepalive_expiry to Limits config

* keepalive_expiry should be optional. In line with httpcore.

httpx/_client.py
httpx/_config.py
tests/test_config.py

index 2d764b0229f51b42f80da49abc9c3290f7d6f048..18e45137bd017fb4381ee8e173c3f07e75c358a9 100644 (file)
@@ -64,7 +64,6 @@ U = typing.TypeVar("U", bound="AsyncClient")
 
 logger = get_logger(__name__)
 
-KEEPALIVE_EXPIRY = 5.0
 USER_AGENT = f"python-httpx/{__version__}"
 ACCEPT_ENCODING = ", ".join(
     [key for key in SUPPORTED_DECODERS.keys() if key != "identity"]
@@ -656,7 +655,7 @@ class Client(BaseClient):
             ssl_context=ssl_context,
             max_connections=limits.max_connections,
             max_keepalive_connections=limits.max_keepalive_connections,
-            keepalive_expiry=KEEPALIVE_EXPIRY,
+            keepalive_expiry=limits.keepalive_expiry,
             http2=http2,
         )
 
@@ -678,7 +677,7 @@ class Client(BaseClient):
             ssl_context=ssl_context,
             max_connections=limits.max_connections,
             max_keepalive_connections=limits.max_keepalive_connections,
-            keepalive_expiry=KEEPALIVE_EXPIRY,
+            keepalive_expiry=limits.keepalive_expiry,
             http2=http2,
         )
 
@@ -1299,7 +1298,7 @@ class AsyncClient(BaseClient):
             ssl_context=ssl_context,
             max_connections=limits.max_connections,
             max_keepalive_connections=limits.max_keepalive_connections,
-            keepalive_expiry=KEEPALIVE_EXPIRY,
+            keepalive_expiry=limits.keepalive_expiry,
             http2=http2,
         )
 
@@ -1321,7 +1320,7 @@ class AsyncClient(BaseClient):
             ssl_context=ssl_context,
             max_connections=limits.max_connections,
             max_keepalive_connections=limits.max_keepalive_connections,
-            keepalive_expiry=KEEPALIVE_EXPIRY,
+            keepalive_expiry=limits.keepalive_expiry,
             http2=http2,
         )
 
index 623392f47e09a88654d503625ca4e2b4ae9d5f53..45e93a99646425b0586b4772024461bc5eb9524f 100644 (file)
@@ -294,22 +294,26 @@ class Limits:
         *,
         max_connections: int = None,
         max_keepalive_connections: int = None,
+        keepalive_expiry: typing.Optional[float] = 5.0,
     ):
         self.max_connections = max_connections
         self.max_keepalive_connections = max_keepalive_connections
+        self.keepalive_expiry = keepalive_expiry
 
     def __eq__(self, other: typing.Any) -> bool:
         return (
             isinstance(other, self.__class__)
             and self.max_connections == other.max_connections
             and self.max_keepalive_connections == other.max_keepalive_connections
+            and self.keepalive_expiry == other.keepalive_expiry
         )
 
     def __repr__(self) -> str:
         class_name = self.__class__.__name__
         return (
             f"{class_name}(max_connections={self.max_connections}, "
-            f"max_keepalive_connections={self.max_keepalive_connections})"
+            f"max_keepalive_connections={self.max_keepalive_connections}, "
+            f"keepalive_expiry={self.keepalive_expiry})"
         )
 
 
index 23f29e00c6678269950a2097539f25068f04f307..f218f8f2082f7024959f2b258590cb3e534e87fa 100644 (file)
@@ -102,7 +102,8 @@ def test_create_ssl_context_with_get_request(server, cert_pem_file):
 
 def test_limits_repr():
     limits = httpx.Limits(max_connections=100)
-    assert repr(limits) == "Limits(max_connections=100, max_keepalive_connections=None)"
+    expected = "Limits(max_connections=100, max_keepalive_connections=None, keepalive_expiry=5.0)"
+    assert repr(limits) == expected
 
 
 def test_limits_eq():