Skip to content
Myr

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

3 files+11 added−7 removed

modified:httpx/_client.py+4 added-5 removed
62 unmodified lines
636465logger = get_logger(__name__)6667KEEPALIVE_EXPIRY = 5.067USER_AGENT = f"python-httpx/{__version__}"68ACCEPT_ENCODING = ", ".join(69 [key for key in SUPPORTED_DECODERS.keys() if key != "identity"]70)
583 unmodified lines
654 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 )661662 def _init_proxy_transport(
13 unmodified lines
676 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 )683684 def _transport_for_url(self, url: URL) -> httpcore.SyncHTTPTransport:
612 unmodified lines
1297 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 )13041305 def _init_proxy_transport(
13 unmodified lines
1319 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 )13261327 def _transport_for_url(self, url: URL) -> httpcore.AsyncHTTPTransport:
529 unmodified lines
modified:httpx/_config.py+5 added-1 removed
292 unmodified lines
293 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_expiry302303 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 )310311 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 )318319320class Proxy:
40 unmodified lines
modified:tests/test_config.py+2 added-1 removed
100 unmodified lines
101102103def 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) == expected107108109def test_limits_eq():110 limits = httpx.Limits(max_connections=100)
122 unmodified lines