Skip to content

Commit 4808ca7

Browse files
fix: add httpx timeout (#31)
1 parent 149906c commit 4808ca7

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

authcaptureproxy/auth_capture_proxy.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,15 @@ def __init__(
6666
"""
6767
self._preserve_headers = preserve_headers
6868
self.session_factory: Callable[[], httpx.AsyncClient] = session_factory or (
69-
lambda: httpx.AsyncClient(verify=ssl_context)
69+
lambda: httpx.AsyncClient(
70+
verify=ssl_context,
71+
timeout=httpx.Timeout(
72+
connect=10.0,
73+
read=30.0,
74+
write=10.0,
75+
pool=10.0,
76+
),
77+
)
7078
)
7179
self.session: httpx.AsyncClient = session if session else self.session_factory()
7280
self._proxy_url: URL = proxy_url
@@ -462,6 +470,20 @@ async def _process_multipart(reader: MultipartReader, writer: MultipartWriter) -
462470
return await self._build_response(
463471
text=f"Error connecting to {site}; too may redirects: {ex}"
464472
)
473+
except httpx.TimeoutException as ex:
474+
_LOGGER.warning(
475+
"Timeout during proxy request to %s: %s",
476+
site,
477+
ex.__class__.__name__,
478+
)
479+
return await self._build_response(
480+
text=(
481+
"Timed out while contacting the service during login.\n\n"
482+
"This is usually caused by slow or blocked network access. "
483+
"Please retry, or check DNS resolution, firewall rules, proxy/VPN settings, "
484+
"and that the service endpoint is reachable from this host."
485+
)
486+
)
465487
if resp is None:
466488
return await self._build_response(text=f"Error connecting to {site}; please retry")
467489
self.last_resp = resp

0 commit comments

Comments
 (0)