Refs #30669 -- Removed incorrect branch in ASGIHander.read_body().

None is not valid for settings.FILE_UPLOAD_MAX_MEMORY_SIZE.
Always use SpooledTemporaryFile.
This commit is contained in:
Carlton Gibson 2019-07-31 13:33:01 +02:00 committed by Mariusz Felisiak
parent 5f24e7158e
commit eea0bf7bd5
1 changed files with 2 additions and 7 deletions

View File

@ -3,7 +3,6 @@ import logging
import sys import sys
import tempfile import tempfile
import traceback import traceback
from io import BytesIO
from asgiref.sync import sync_to_async from asgiref.sync import sync_to_async
@ -175,12 +174,8 @@ class ASGIHandler(base.BaseHandler):
async def read_body(self, receive): async def read_body(self, receive):
"""Reads a HTTP body from an ASGI connection.""" """Reads a HTTP body from an ASGI connection."""
# Use the tempfile that auto rolls-over to a disk file as it fills up, # Use the tempfile that auto rolls-over to a disk file as it fills up.
# if a maximum in-memory size is set. Otherwise use a BytesIO object. body_file = tempfile.SpooledTemporaryFile(max_size=settings.FILE_UPLOAD_MAX_MEMORY_SIZE, mode='w+b')
if settings.FILE_UPLOAD_MAX_MEMORY_SIZE is None:
body_file = BytesIO()
else:
body_file = tempfile.SpooledTemporaryFile(max_size=settings.FILE_UPLOAD_MAX_MEMORY_SIZE, mode='w+b')
while True: while True:
message = await receive() message = await receive()
if message['type'] == 'http.disconnect': if message['type'] == 'http.disconnect':