Fixed #30567 -- Made WSGIHandler pass FileResponse.block_size to wsgi.file_wrapper.

This commit is contained in:
Piotr Domanski 2019-07-24 19:06:01 +02:00 committed by Mariusz Felisiak
parent 806ba19bbf
commit 4b4e68a7a6
2 changed files with 5 additions and 2 deletions

View File

@ -141,7 +141,7 @@ class WSGIHandler(base.BaseHandler):
]
start_response(status, response_headers)
if getattr(response, 'file_to_stream', None) is not None and environ.get('wsgi.file_wrapper'):
response = environ['wsgi.file_wrapper'](response.file_to_stream)
response = environ['wsgi.file_wrapper'](response.file_to_stream, response.block_size)
return response

View File

@ -3,6 +3,7 @@ from django.core.servers.basehttp import get_internal_wsgi_application
from django.core.signals import request_started
from django.core.wsgi import get_wsgi_application
from django.db import close_old_connections
from django.http import FileResponse
from django.test import SimpleTestCase, override_settings
from django.test.client import RequestFactory
@ -51,7 +52,8 @@ class WSGITest(SimpleTestCase):
FileResponse uses wsgi.file_wrapper.
"""
class FileWrapper:
def __init__(self, filelike, blksize=8192):
def __init__(self, filelike, block_size=None):
self.block_size = block_size
filelike.close()
application = get_wsgi_application()
environ = self.request_factory._base_environ(
@ -67,6 +69,7 @@ class WSGITest(SimpleTestCase):
response = application(environ, start_response)
self.assertEqual(response_data['status'], '200 OK')
self.assertIsInstance(response, FileWrapper)
self.assertEqual(response.block_size, FileResponse.block_size)
class GetInternalWSGIApplicationTest(SimpleTestCase):