Fixed content type header of frontend serve view

This commit is contained in:
Karl Hobley 2015-04-01 16:38:44 +01:00
parent 269cb95ed6
commit f81385da31
2 changed files with 4 additions and 2 deletions

View file

@ -171,7 +171,7 @@ class TestFrontendServeView(TestCase):
# Check response
self.assertEqual(response.status_code, 200)
self.assertEqual(response['Content-Type'], 'image/jpeg')
self.assertEqual(response['Content-Type'], 'image/png')
def test_get_invalid_signature(self):
"""

View file

@ -1,4 +1,5 @@
from wsgiref.util import FileWrapper
import imghdr
from django.shortcuts import get_object_or_404
from django.http import HttpResponse
@ -18,6 +19,7 @@ def serve(request, signature, image_id, filter_spec):
try:
rendition = image.get_rendition(filter_spec)
rendition.file.open('rb')
return HttpResponse(FileWrapper(rendition.file), content_type='image/jpeg')
image_format = imghdr.what(rendition.file)
return HttpResponse(FileWrapper(rendition.file), content_type='image/' + image_format)
except InvalidFilterSpecError:
return HttpResponse("Invalid filter spec: " + filter_spec, content_type='text/plain', status=400)