mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Fixed bug with ?_trace=1 and large responses, closes #2404
This commit is contained in:
parent
9028d7f805
commit
34a6b2ac84
3 changed files with 23 additions and 1 deletions
|
|
@ -90,6 +90,7 @@ class AsgiTracer:
|
||||||
|
|
||||||
async def wrapped_send(message):
|
async def wrapped_send(message):
|
||||||
nonlocal accumulated_body, size_limit_exceeded, response_headers
|
nonlocal accumulated_body, size_limit_exceeded, response_headers
|
||||||
|
|
||||||
if message["type"] == "http.response.start":
|
if message["type"] == "http.response.start":
|
||||||
response_headers = message["headers"]
|
response_headers = message["headers"]
|
||||||
await send(message)
|
await send(message)
|
||||||
|
|
@ -102,11 +103,12 @@ class AsgiTracer:
|
||||||
# Accumulate body until the end or until size is exceeded
|
# Accumulate body until the end or until size is exceeded
|
||||||
accumulated_body += message["body"]
|
accumulated_body += message["body"]
|
||||||
if len(accumulated_body) > self.max_body_bytes:
|
if len(accumulated_body) > self.max_body_bytes:
|
||||||
|
# Send what we have accumulated so far
|
||||||
await send(
|
await send(
|
||||||
{
|
{
|
||||||
"type": "http.response.body",
|
"type": "http.response.body",
|
||||||
"body": accumulated_body,
|
"body": accumulated_body,
|
||||||
"more_body": True,
|
"more_body": bool(message.get("more_body")),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
size_limit_exceeded = True
|
size_limit_exceeded = True
|
||||||
|
|
|
||||||
|
|
@ -62,10 +62,13 @@ class TestClient:
|
||||||
follow_redirects=False,
|
follow_redirects=False,
|
||||||
redirect_count=0,
|
redirect_count=0,
|
||||||
method="GET",
|
method="GET",
|
||||||
|
params=None,
|
||||||
cookies=None,
|
cookies=None,
|
||||||
if_none_match=None,
|
if_none_match=None,
|
||||||
headers=None,
|
headers=None,
|
||||||
):
|
):
|
||||||
|
if params:
|
||||||
|
path += "?" + urlencode(params, doseq=True)
|
||||||
return await self._request(
|
return await self._request(
|
||||||
path=path,
|
path=path,
|
||||||
follow_redirects=follow_redirects,
|
follow_redirects=follow_redirects,
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,23 @@ def test_trace(trace_debug):
|
||||||
assert all(isinstance(trace["count"], int) for trace in execute_manys)
|
assert all(isinstance(trace["count"], int) for trace in execute_manys)
|
||||||
|
|
||||||
|
|
||||||
|
def test_trace_silently_fails_for_large_page():
|
||||||
|
# Max HTML size is 256KB
|
||||||
|
with make_app_client(settings={"trace_debug": True}) as client:
|
||||||
|
# Small response should have trace
|
||||||
|
small_response = client.get("/fixtures/simple_primary_key.json?_trace=1")
|
||||||
|
assert small_response.status == 200
|
||||||
|
assert "_trace" in small_response.json
|
||||||
|
|
||||||
|
# Big response should not
|
||||||
|
big_response = client.get(
|
||||||
|
"/fixtures/-/query.json",
|
||||||
|
params={"_trace": 1, "sql": "select zeroblob(1024 * 256)"},
|
||||||
|
)
|
||||||
|
assert big_response.status == 200
|
||||||
|
assert "_trace" not in big_response.json
|
||||||
|
|
||||||
|
|
||||||
def test_trace_parallel_queries():
|
def test_trace_parallel_queries():
|
||||||
with make_app_client(settings={"trace_debug": True}) as client:
|
with make_app_client(settings={"trace_debug": True}) as client:
|
||||||
response = client.get("/parallel-queries?_trace=1")
|
response = client.get("/parallel-queries?_trace=1")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue