Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keepalive_expiry to Limits config #1398

Merged
merged 3 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions httpx/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@

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"]
Expand Down Expand Up @@ -656,7 +655,7 @@ def _init_transport(
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,
)

Expand All @@ -678,7 +677,7 @@ def _init_proxy_transport(
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,
)

Expand Down Expand Up @@ -1299,7 +1298,7 @@ def _init_transport(
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,
)

Expand All @@ -1321,7 +1320,7 @@ def _init_proxy_transport(
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,
)

Expand Down
6 changes: 5 additions & 1 deletion httpx/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,22 +294,26 @@ def __init__(
*,
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})"
)


Expand Down
3 changes: 2 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down