From c1a317b957ff55854f579aaa62ad6bb9154b6a6a Mon Sep 17 00:00:00 2001 From: Loic Quertenmont Date: Thu, 16 Jan 2025 09:44:25 +0100 Subject: [PATCH 1/2] Avoid timeout due to too big requests --- silk/views/request_detail.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/silk/views/request_detail.py b/silk/views/request_detail.py index 6baa3adb..db41bf59 100644 --- a/silk/views/request_detail.py +++ b/silk/views/request_detail.py @@ -19,24 +19,28 @@ def get(self, request, request_id): query_params = None if silk_request.query_params: query_params = json.loads(silk_request.query_params) - body = silk_request.raw_body - try: - body = json.loads(body) # Incase encoded as JSON - except (ValueError, TypeError): - pass + context = { 'silk_request': silk_request, - 'curl': curl_cmd(url=request.build_absolute_uri(silk_request.path), + 'query_params': json.dumps(query_params, sort_keys=True, indent=4) if query_params else None, + 'request': request + } + + if len(silk_request.raw_body<20000): # Don't do this for large request + body = silk_request.raw_body + try: + body = json.loads(body) # Incase encoded as JSON + except (ValueError, TypeError): + pass + context['curl'] = curl_cmd(url=request.build_absolute_uri(silk_request.path), method=silk_request.method, query_params=query_params, body=body, content_type=silk_request.content_type), - 'query_params': json.dumps(query_params, sort_keys=True, indent=4) if query_params else None, - 'client': gen(path=silk_request.path, + context['client'] = gen(path=silk_request.path, method=silk_request.method, query_params=query_params, data=body, - content_type=silk_request.content_type), - 'request': request - } + content_type=silk_request.content_type), + return render(request, 'silk/request.html', context) From d5fb3b93cfa877fdcb46dd333eaac6daa86fd980 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 16 Jan 2025 08:46:38 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- silk/views/request_detail.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/silk/views/request_detail.py b/silk/views/request_detail.py index db41bf59..631cd1fa 100644 --- a/silk/views/request_detail.py +++ b/silk/views/request_detail.py @@ -26,21 +26,21 @@ def get(self, request, request_id): 'request': request } - if len(silk_request.raw_body<20000): # Don't do this for large request + if len(silk_request.raw_body < 20000): # Don't do this for large request body = silk_request.raw_body try: body = json.loads(body) # Incase encoded as JSON except (ValueError, TypeError): - pass + pass context['curl'] = curl_cmd(url=request.build_absolute_uri(silk_request.path), - method=silk_request.method, - query_params=query_params, - body=body, - content_type=silk_request.content_type), + method=silk_request.method, + query_params=query_params, + body=body, + content_type=silk_request.content_type), context['client'] = gen(path=silk_request.path, - method=silk_request.method, - query_params=query_params, - data=body, - content_type=silk_request.content_type), - + method=silk_request.method, + query_params=query_params, + data=body, + content_type=silk_request.content_type), + return render(request, 'silk/request.html', context)