diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py index 1bca7173048..cb740e5c505 100644 --- a/django/core/handlers/wsgi.py +++ b/django/core/handlers/wsgi.py @@ -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 diff --git a/tests/wsgi/tests.py b/tests/wsgi/tests.py index f8ee08e3876..8ae6296bd19 100644 --- a/tests/wsgi/tests.py +++ b/tests/wsgi/tests.py @@ -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):