From 1a0bec8bdcd10b6c4f88861d4ffdc52a8f1f1e55 Mon Sep 17 00:00:00 2001 From: Steve Bradshaw Date: Tue, 22 Mar 2016 10:38:27 +0000 Subject: [PATCH] Allow renderers to supply boundaries --- rest_framework/response.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/rest_framework/response.py b/rest_framework/response.py index 0e97668eb..70bd8741f 100644 --- a/rest_framework/response.py +++ b/rest_framework/response.py @@ -62,12 +62,6 @@ class Response(SimpleTemplateResponse): charset = renderer.charset content_type = self.content_type - if content_type is None and charset is not None: - content_type = "{0}; charset={1}".format(media_type, charset) - elif content_type is None: - content_type = media_type - self['Content-Type'] = content_type - ret = renderer.render(self.data, media_type, context) if isinstance(ret, six.text_type): assert charset, ( @@ -76,6 +70,15 @@ class Response(SimpleTemplateResponse): ) return bytes(ret.encode(charset)) + boundary = renderer.boundary if hasattr(renderer, "boundary") else None + if not content_type: + content_type = "{0}".format(media_type) + if charset is not None: + content_type += "; charset={0}".format(charset) + if boundary is not None: + content_type += "; boundary={0}".format(boundary) + + self['Content-Type'] = content_type if not ret: del self['Content-Type']