From bd20ca86ab0144691c17fe36498a3aeb75e5d705 Mon Sep 17 00:00:00 2001 From: kqjy Date: Sun, 22 Mar 2026 11:22:24 +0800 Subject: [PATCH] Further debugging on s3 api issues on Granian --- app/__init__.py | 11 ++++++++--- app/admin_api.py | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 95801e7..359f459 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -47,7 +47,6 @@ _request_counter = itertools.count(1) class _ChunkedTransferMiddleware: - _logger = logging.getLogger("chunked_middleware") def __init__(self, app): self.app = app @@ -72,6 +71,13 @@ class _ChunkedTransferMiddleware: if not is_streaming: return self.app(environ, start_response) + raw = environ.get("wsgi.input") + if raw and hasattr(raw, "seek"): + try: + raw.seek(0) + except Exception: + pass + cl_int = 0 try: cl_int = int(content_length) if content_length else 0 @@ -80,8 +86,7 @@ class _ChunkedTransferMiddleware: if cl_int <= 0: try: - raw = environ["wsgi.input"] - body = raw.read() + body = raw.read() if raw else b"" except Exception: body = b"" if body: diff --git a/app/admin_api.py b/app/admin_api.py index c6738db..faa0fe0 100644 --- a/app/admin_api.py +++ b/app/admin_api.py @@ -1006,6 +1006,32 @@ def debug_upload(): "request.content_length": request.content_length, } + raw = env.get("wsgi.input") + if raw: + try: + info["wsgi_input_pos"] = raw.tell() if hasattr(raw, "tell") else "N/A" + except Exception: + info["wsgi_input_pos"] = "error" + if hasattr(raw, "getvalue"): + try: + full = raw.getvalue() + info["wsgi_input_getvalue_len"] = len(full) + if full: + info["wsgi_input_getvalue_hex"] = full[:200].hex() + except Exception as e: + info["wsgi_input_getvalue_error"] = str(e) + try: + if hasattr(raw, "seek"): + raw.seek(0) + seek_body = raw.read() + info["wsgi_input_after_seek0_len"] = len(seek_body) + if seek_body: + info["wsgi_input_after_seek0_hex"] = seek_body[:200].hex() + if hasattr(raw, "seek"): + raw.seek(0) + except Exception as e: + info["wsgi_input_seek_read_error"] = str(e) + try: body = request.get_data(cache=False) info["body_length"] = len(body)