@@ -332,15 +332,21 @@ async def _handle_post_request(self, scope: Scope, request: Request, receive: Re
332
332
await response (scope , receive , send )
333
333
return
334
334
335
- # Parse the body - only read it once
336
- body = await request .body ()
337
- if len (body ) > self ._maximum_message_size :
338
- response = self ._create_error_response (
339
- "Payload Too Large: Message exceeds maximum size" ,
340
- HTTPStatus .REQUEST_ENTITY_TOO_LARGE ,
341
- )
342
- await response (scope , receive , send )
343
- return
335
+ # Parse the body by streaming and joining chunks
336
+ chunks : list [bytes ] = []
337
+ total_message_size = 0
338
+ async for chunk in request .stream ():
339
+ total_message_size += len (chunk )
340
+ # Validate that body is smaller than maximum allowed message size
341
+ if total_message_size > self ._maximum_message_size :
342
+ response = self ._create_error_response (
343
+ "Payload Too Large: Message exceeds maximum size" ,
344
+ HTTPStatus .REQUEST_ENTITY_TOO_LARGE ,
345
+ )
346
+ await response (scope , receive , send )
347
+ return
348
+ chunks .append (chunk )
349
+ body = b"" .join (chunks )
344
350
345
351
try :
346
352
raw_message = json .loads (body )
0 commit comments