From ad722b3ed3ff1b92ebee829db3c289040960b24d Mon Sep 17 00:00:00 2001 From: Alistair Coles Date: Wed, 25 Nov 2015 18:49:39 +0000 Subject: [PATCH] Include params in multipart message part content-type The content-type header inserted into a multipart message part is missing any params such as charset because its value is being fetched via the swob.Response content_type property, which conforms to webob spec and strips off all params. This was noticed in work on feature/crypto branch because the crypto meta param was being stripped off content-type in multipart messages, preventing the content-type being decrypted. But in general there is no suggestion in the multipart message spec [1] that params should not be included. In fact examples in [1] show the charset param included in the content-type value. To ensure that the multipart message part content-type includes the original content-type params, fetch it directly from the response headers. [1] http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html Change-Id: Iff7274aa631a92cd7332212ed8b4378c27da4a1f --- swift/common/swob.py | 2 +- test/unit/common/test_swob.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/swift/common/swob.py b/swift/common/swob.py index 1a02740031..a64c4cf6d1 100644 --- a/swift/common/swob.py +++ b/swift/common/swob.py @@ -1184,7 +1184,7 @@ class Response(object): """ content_size = self.content_length - content_type = self.content_type + content_type = self.headers.get('content-type') self.content_type = ''.join(['multipart/byteranges;', 'boundary=', self.boundary]) diff --git a/test/unit/common/test_swob.py b/test/unit/common/test_swob.py index 489fa1dd28..8a0b21fd25 100644 --- a/test/unit/common/test_swob.py +++ b/test/unit/common/test_swob.py @@ -1228,21 +1228,21 @@ class TestResponse(unittest.TestCase): resp.conditional_response = True resp.content_length = 100 - resp.content_type = 'text/plain' + resp.content_type = 'text/plain; charset=utf8' content = ''.join(resp._response_iter(None, ('0123456789112345678' '92123456789'))) self.assertTrue(re.match(('--[a-f0-9]{32}\r\n' - 'Content-Type: text/plain\r\n' + 'Content-Type: text/plain; charset=utf8\r\n' 'Content-Range: bytes ' '0-9/100\r\n\r\n0123456789\r\n' '--[a-f0-9]{32}\r\n' - 'Content-Type: text/plain\r\n' + 'Content-Type: text/plain; charset=utf8\r\n' 'Content-Range: bytes ' '10-19/100\r\n\r\n1123456789\r\n' '--[a-f0-9]{32}\r\n' - 'Content-Type: text/plain\r\n' + 'Content-Type: text/plain; charset=utf8\r\n' 'Content-Range: bytes ' '20-29/100\r\n\r\n2123456789\r\n' '--[a-f0-9]{32}--'), content))