Collect request body chunks before caching

Commit 0e3f790 · patx · 2026-10-15T19:23:13-04:00

Changeset
0e3f7906d39c87e6d2b4f7ce6b7627b5ddf52be4
Parents
36021ac4e3b1044d269b3a74c1d14dc052ff71e8

View source at this commit

Comments

No comments yet.

Log in to comment

Diff

diff --git a/wred.py b/wred.py
index 002ecc0..b06264f 100644
--- a/wred.py
+++ b/wred.py
@@ -55,14 +55,15 @@ class Request:
     async def body(self) -> bytes:
         """Read the request body from the ASGI receive stream."""
         if self._body is None:
-            self._body = b""
+            chunks = []
             while True:
                 message = await self.receive()
                 if message['type'] != 'http.request':
                     raise WredRequestError("Client disconnected")
-                self._body += message.get('body', b'')
+                chunks.append(message.get('body', b''))
                 if not message.get('more_body', False):
                     break
+            self._body = b''.join(chunks)
         return self._body
 
     async def json(self) -> dict[str, Any]: