From 04cc11b938aac3e9225870d4dd2b7f3fc89f20a3 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Tue, 11 Feb 2020 21:34:05 -0800 Subject: [PATCH] py3: stop barfing on message/rfc822 Content-Types Closes-Bug: #1863053 Change-Id: I7493d3e201e26df9f200e16bc081d8a0f30308b9 --- swift/common/bufferedhttp.py | 2 ++ swift/common/wsgi.py | 2 ++ test/unit/proxy/test_server.py | 11 ++++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/swift/common/bufferedhttp.py b/swift/common/bufferedhttp.py index e95b81bf8c..a9633e34c2 100644 --- a/swift/common/bufferedhttp.py +++ b/swift/common/bufferedhttp.py @@ -87,6 +87,8 @@ class BufferedHTTPResponse(HTTPResponse): def begin(self): HTTPResponse.begin(self) header_payload = self.headers.get_payload() + if isinstance(header_payload, list) and len(header_payload) == 1: + header_payload = header_payload[0].get_payload() if header_payload: # This shouldn't be here. We must've bumped up against # https://bugs.python.org/issue37093 diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index d544d9d2c0..6bee626502 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -501,6 +501,8 @@ class SwiftHttpProtocol(wsgi.HttpProtocol): def get_environ(self, *args, **kwargs): environ = wsgi.HttpProtocol.get_environ(self, *args, **kwargs) header_payload = self.headers.get_payload() + if isinstance(header_payload, list) and len(header_payload) == 1: + header_payload = header_payload[0].get_payload() if header_payload: # This shouldn't be here. We must've bumped up against # https://bugs.python.org/issue37093 diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index 0066c87417..5d20f5ede0 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -3276,9 +3276,10 @@ class TestReplicatedObjectController( fd.write(b'PUT /v1/a/c/o.chunked HTTP/1.1\r\n' b'Host: localhost\r\n' b'X-Storage-Token: t\r\n' - b'Content-Type: application/octet-stream\r\n' + b'Content-Type: message/rfc822\r\n' b'Content-Length: 33\r\n' b'X-Object-Meta-\xf0\x9f\x8c\xb4: \xf0\x9f\x91\x8d\r\n' + b'X-Object-Meta-\xe2\x98\x85: \xe2\x98\x85\r\n' b'Expect: 100-continue\r\n' b'Transfer-Encoding: chunked\r\n\r\n') fd.flush() @@ -3317,9 +3318,13 @@ class TestReplicatedObjectController( headers = readuntil2crlfs(fd) exp = b'HTTP/1.1 200' self.assertEqual(headers[:len(exp)], exp) - self.assertIn(b'Content-Length: 33', headers.split(b'\r\n')) + header_lines = headers.split(b'\r\n') + self.assertIn(b'Content-Length: 33', header_lines) + self.assertIn(b'Content-Type: message/rfc822', header_lines) self.assertIn(b'X-Object-Meta-\xf0\x9f\x8c\xb4: \xf0\x9f\x91\x8d', - headers.split(b'\r\n')) + header_lines) + self.assertIn(b'X-Object-Meta-\xe2\x98\x85: \xe2\x98\x85', + header_lines) self.assertEqual(b"oh say can you see by the dawns'\n", fd.read(33)) @unpatch_policies