Skip to content

Commit 0a84caa

Browse files
Avoid timeout caused by Request with large body (#768)
* Avoid timeout due to too big requests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update request_detail.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 35c8c01 commit 0a84caa

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

silk/views/request_detail.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,28 @@ def get(self, request, request_id):
1919
query_params = None
2020
if silk_request.query_params:
2121
query_params = json.loads(silk_request.query_params)
22-
body = silk_request.raw_body
23-
try:
24-
body = json.loads(body) # Incase encoded as JSON
25-
except (ValueError, TypeError):
26-
pass
22+
2723
context = {
2824
'silk_request': silk_request,
29-
'curl': curl_cmd(url=request.build_absolute_uri(silk_request.path),
30-
method=silk_request.method,
31-
query_params=query_params,
32-
body=body,
33-
content_type=silk_request.content_type),
3425
'query_params': json.dumps(query_params, sort_keys=True, indent=4) if query_params else None,
35-
'client': gen(path=silk_request.path,
36-
method=silk_request.method,
37-
query_params=query_params,
38-
data=body,
39-
content_type=silk_request.content_type),
4026
'request': request
4127
}
28+
29+
if len(silk_request.raw_body) < 20000: # Don't do this for large request
30+
body = silk_request.raw_body
31+
try:
32+
body = json.loads(body) # Incase encoded as JSON
33+
except (ValueError, TypeError):
34+
pass
35+
context['curl'] = curl_cmd(url=request.build_absolute_uri(silk_request.path),
36+
method=silk_request.method,
37+
query_params=query_params,
38+
body=body,
39+
content_type=silk_request.content_type),
40+
context['client'] = gen(path=silk_request.path,
41+
method=silk_request.method,
42+
query_params=query_params,
43+
data=body,
44+
content_type=silk_request.content_type),
45+
4246
return render(request, 'silk/request.html', context)

0 commit comments

Comments
 (0)