MyFSIO v0.4.0 Release #33

Merged
kqjy merged 19 commits from next into main 2026-03-22 05:06:47 +00:00
Showing only changes of commit 366f8ce60d - Show all commits

View File

@@ -51,21 +51,26 @@ class _ChunkedTransferMiddleware:
self.app = app
def __call__(self, environ, start_response):
has_content_length = environ.get("CONTENT_LENGTH")
if not has_content_length and environ.get("REQUEST_METHOD") in ("PUT", "POST"):
transfer_chunked = "chunked" in environ.get("HTTP_TRANSFER_ENCODING", "").lower()
has_body_hint = bool(environ.get("HTTP_X_AMZ_DECODED_CONTENT_LENGTH"))
content_encoding = environ.get("HTTP_CONTENT_ENCODING", "")
has_aws_chunked = "aws-chunked" in content_encoding.lower()
if transfer_chunked or has_body_hint or has_aws_chunked:
try:
raw = environ["wsgi.input"]
body = raw.read()
except Exception:
body = b""
if body:
environ["wsgi.input"] = io.BytesIO(body)
environ["CONTENT_LENGTH"] = str(len(body))
if environ.get("REQUEST_METHOD") not in ("PUT", "POST"):
return self.app(environ, start_response)
content_length = environ.get("CONTENT_LENGTH")
body_expected = (
environ.get("HTTP_X_AMZ_DECODED_CONTENT_LENGTH")
or "chunked" in environ.get("HTTP_TRANSFER_ENCODING", "").lower()
or "aws-chunked" in environ.get("HTTP_CONTENT_ENCODING", "").lower()
)
if body_expected and (not content_length or content_length == "0"):
try:
raw = environ["wsgi.input"]
body = raw.read()
except Exception:
body = b""
if body:
environ["wsgi.input"] = io.BytesIO(body)
environ["CONTENT_LENGTH"] = str(len(body))
return self.app(environ, start_response)