Fixed bug with ?_trace=1 and large responses, closes #2404

This commit is contained in:
Simon Willison 2024-08-21 10:58:17 -07:00
commit 34a6b2ac84
3 changed files with 23 additions and 1 deletions

View file

@ -90,6 +90,7 @@ class AsgiTracer:
async def wrapped_send(message):
nonlocal accumulated_body, size_limit_exceeded, response_headers
if message["type"] == "http.response.start":
response_headers = message["headers"]
await send(message)
@ -102,11 +103,12 @@ class AsgiTracer:
# Accumulate body until the end or until size is exceeded
accumulated_body += message["body"]
if len(accumulated_body) > self.max_body_bytes:
# Send what we have accumulated so far
await send(
{
"type": "http.response.body",
"body": accumulated_body,
"more_body": True,
"more_body": bool(message.get("more_body")),
}
)
size_limit_exceeded = True

View file

@ -62,10 +62,13 @@ class TestClient:
follow_redirects=False,
redirect_count=0,
method="GET",
params=None,
cookies=None,
if_none_match=None,
headers=None,
):
if params:
path += "?" + urlencode(params, doseq=True)
return await self._request(
path=path,
follow_redirects=follow_redirects,