Skip to content

Commit

Permalink
feat: add a default timeout to the session
Browse files Browse the repository at this point in the history
Close #80

Signed-off-by: Frost Ming <me@frostming.com>
  • Loading branch information
frostming committed Jan 4, 2024
1 parent c777db5 commit 1d9a2dc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/unearth/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def __init__(
retries: int = DEFAULT_MAX_RETRIES,
trusted_hosts: Iterable[str] = (),
ca_certificates: Path | None = None,
timeout: float | tuple[float, float] | urllib3.Timeout = 10,
) -> None:
super().__init__()

Expand All @@ -130,6 +131,7 @@ def __init__(
self.mount("http://", self._insecure_adapter)
self.mount("file://", LocalFSAdapter())

self.timeout = timeout
self._trusted_host_ports: set[tuple[str, int | None]] = set()

for host in trusted_hosts:
Expand All @@ -139,6 +141,11 @@ def __init__(
if ca_certificates is not None:
self.set_ca_certificates(ca_certificates)

def send(self, request: PreparedRequest, **kwargs: Any) -> Response:
if kwargs.get("timeout") is None:
kwargs["timeout"] = self.timeout
return super().send(request, **kwargs)

def set_ca_certificates(self, cert_file: Path):
"""
Set one or multiple certificate authorities which sign the
Expand Down

0 comments on commit 1d9a2dc

Please sign in to comment.