From 80bf868963bbb8636a7cb9147b67257304ceff83 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Fri, 21 Aug 2015 14:32:31 +0100 Subject: [PATCH] Use StreamingHttpResponse in image serve view Fixes #1584 This will prevent djangos "UpdateCacheMiddleware" from trying to add the image into the cache. https://github.com/django/django/blob/master/django/middleware/cache.py#L78-L79 --- wagtail/wagtailimages/tests/tests.py | 1 + wagtail/wagtailimages/views/frontend.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/wagtail/wagtailimages/tests/tests.py b/wagtail/wagtailimages/tests/tests.py index bba1e1f9c..d9d5147bd 100644 --- a/wagtail/wagtailimages/tests/tests.py +++ b/wagtail/wagtailimages/tests/tests.py @@ -182,6 +182,7 @@ class TestFrontendServeView(TestCase): # Check response self.assertEqual(response.status_code, 200) + self.assertTrue(response.streaming) self.assertEqual(response['Content-Type'], 'image/png') def test_get_invalid_signature(self): diff --git a/wagtail/wagtailimages/views/frontend.py b/wagtail/wagtailimages/views/frontend.py index 7e78473df..341e5fdd0 100644 --- a/wagtail/wagtailimages/views/frontend.py +++ b/wagtail/wagtailimages/views/frontend.py @@ -2,7 +2,7 @@ from wsgiref.util import FileWrapper import imghdr from django.shortcuts import get_object_or_404 -from django.http import HttpResponse +from django.http import HttpResponse, StreamingHttpResponse from django.core.exceptions import PermissionDenied from wagtail.wagtailimages.models import get_image_model @@ -20,6 +20,6 @@ def serve(request, signature, image_id, filter_spec): rendition = image.get_rendition(filter_spec) rendition.file.open('rb') image_format = imghdr.what(rendition.file) - return HttpResponse(FileWrapper(rendition.file), content_type='image/' + image_format) + return StreamingHttpResponse(FileWrapper(rendition.file), content_type='image/' + image_format) except InvalidFilterSpecError: return HttpResponse("Invalid filter spec: " + filter_spec, content_type='text/plain', status=400)