Skip to content

Commit 91bc7f4

Browse files
committed
chore(httpcat): add max_redirect to request
1 parent 05678bb commit 91bc7f4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lagrange/utils/httpcat.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ async def request(
228228
body: Optional[bytes] = None,
229229
cookies: Optional[dict[str, str]] = None,
230230
follow_redirect=True,
231+
max_redirect=10,
231232
conn_timeout=0,
232233
loop: Optional[asyncio.AbstractEventLoop] = None,
233234
) -> HttpResponse:
@@ -242,9 +243,9 @@ async def request(
242243
address[0], reader, writer, method, path, header, body, cookies, True, loop
243244
)
244245
_logger.debug(f"request({method})[{resp.code}]: {url}")
245-
if resp.code // 100 == 3 and follow_redirect:
246+
if resp.code // 100 == 3 and follow_redirect and max_redirect > 0:
246247
return await cls.request(
247-
method, resp.header["Location"], header, body, cookies
248+
method, resp.header["Location"], header, body, cookies, follow_redirect, max_redirect - 1
248249
)
249250
else:
250251
return resp

0 commit comments

Comments
 (0)