Add keepalive_expiry to Limits config (#1398)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* Add keepalive_expiry to Limits config * keepalive_expiry should be optional. In line with httpcore.
authored by Tom Christie · committed by GitHub · parent 27df5e4 · Browse files · 3 files·+11 added−7 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+11 added−7 removed
- tests:+2 added−1 removed
- other:+9 added−6 removed
Provenance
- Commit
d0835da- Tree
698f737- Author
Tom Christie <tom@tomchristie.com>- Committer
GitHub <noreply@github.com>- Parent
27df5e4
3 files changed+11 added−7 removed
modified:httpx/_client.py+4 added-5 removed
62 unmodified lines63 64 65 logger = get_logger(__name__)66 67-KEEPALIVE_EXPIRY = 5.067 USER_AGENT = f"python-httpx/{__version__}"68 ACCEPT_ENCODING = ", ".join(69 [key for key in SUPPORTED_DECODERS.keys() if key != "identity"]70 )583 unmodified lines654 return httpcore.SyncConnectionPool(655 ssl_context=ssl_context,656 max_connections=limits.max_connections,657 max_keepalive_connections=limits.max_keepalive_connections,659- keepalive_expiry=KEEPALIVE_EXPIRY,658+ keepalive_expiry=limits.keepalive_expiry,659 http2=http2,660 )661 662 def _init_proxy_transport(13 unmodified lines676 proxy_mode=proxy.mode,677 ssl_context=ssl_context,678 max_connections=limits.max_connections,679 max_keepalive_connections=limits.max_keepalive_connections,681- keepalive_expiry=KEEPALIVE_EXPIRY,680+ keepalive_expiry=limits.keepalive_expiry,681 http2=http2,682 )683 684 def _transport_for_url(self, url: URL) -> httpcore.SyncHTTPTransport:612 unmodified lines1297 return httpcore.AsyncConnectionPool(1298 ssl_context=ssl_context,1299 max_connections=limits.max_connections,1300 max_keepalive_connections=limits.max_keepalive_connections,1302- keepalive_expiry=KEEPALIVE_EXPIRY,1301+ keepalive_expiry=limits.keepalive_expiry,1302 http2=http2,1303 )1304 1305 def _init_proxy_transport(13 unmodified lines1319 proxy_mode=proxy.mode,1320 ssl_context=ssl_context,1321 max_connections=limits.max_connections,1322 max_keepalive_connections=limits.max_keepalive_connections,1324- keepalive_expiry=KEEPALIVE_EXPIRY,1323+ keepalive_expiry=limits.keepalive_expiry,1324 http2=http2,1325 )1326 1327 def _transport_for_url(self, url: URL) -> httpcore.AsyncHTTPTransport:529 unmodified linesmodified:httpx/_config.py+5 added-1 removed
292 unmodified lines293 self,294 *,295 max_connections: int = None,296 max_keepalive_connections: int = None,297+ keepalive_expiry: typing.Optional[float] = 5.0,298 ):299 self.max_connections = max_connections300 self.max_keepalive_connections = max_keepalive_connections301+ self.keepalive_expiry = keepalive_expiry302 303 def __eq__(self, other: typing.Any) -> bool:304 return (305 isinstance(other, self.__class__)306 and self.max_connections == other.max_connections307 and self.max_keepalive_connections == other.max_keepalive_connections308+ and self.keepalive_expiry == other.keepalive_expiry309 )310 311 def __repr__(self) -> str:312 class_name = self.__class__.__name__313 return (314 f"{class_name}(max_connections={self.max_connections}, "312- f"max_keepalive_connections={self.max_keepalive_connections})"315+ f"max_keepalive_connections={self.max_keepalive_connections}, "316+ f"keepalive_expiry={self.keepalive_expiry})"317 )318 319 320 class Proxy:40 unmodified linesmodified:tests/test_config.py+2 added-1 removed
100 unmodified lines101 102 103 def test_limits_repr():104 limits = httpx.Limits(max_connections=100)105- assert repr(limits) == "Limits(max_connections=100, max_keepalive_connections=None)"105+ expected = "Limits(max_connections=100, max_keepalive_connections=None, keepalive_expiry=5.0)"106+ assert repr(limits) == expected107 108 109 def test_limits_eq():110 limits = httpx.Limits(max_connections=100)122 unmodified lines