diff --git a/CHANGELOG b/CHANGELOG index 02eb8c5296..e9ed2bc2fa 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,3 +8,5 @@ swift (x.x.x) (X-Trans-ID). Setting the transaction id has moved from the proxy server to the catch_errors middleware. Additionally, the internal header has changed from X-CF-Trans-ID to X-Trans-ID. + + * Fixed Python 2.7 httplib compatibility problem. diff --git a/swift/common/bufferedhttp.py b/swift/common/bufferedhttp.py index cf74dbe8fa..966b153616 100644 --- a/swift/common/bufferedhttp.py +++ b/swift/common/bufferedhttp.py @@ -131,7 +131,7 @@ def http_connect(ipaddr, port, device, partition, method, path, conn.putrequest(method, path) if headers: for header, value in headers.iteritems(): - conn.putheader(header, value) + conn.putheader(header, str(value)) conn.endheaders() return conn @@ -164,6 +164,6 @@ def http_connect_raw(ipaddr, port, method, path, headers=None, conn.putrequest(method, path) if headers: for header, value in headers.iteritems(): - conn.putheader(header, value) + conn.putheader(header, str(value)) conn.endheaders() return conn diff --git a/test/unit/common/test_bufferedhttp.py b/test/unit/common/test_bufferedhttp.py index fbaa83f403..0239c6531d 100644 --- a/test/unit/common/test_bufferedhttp.py +++ b/test/unit/common/test_bufferedhttp.py @@ -68,6 +68,31 @@ class TestBufferedHTTP(unittest.TestCase): if err: raise Exception(err) + def test_nonstr_header_values(self): + + class MockHTTPSConnection(object): + + def __init__(self, hostport): + pass + + def putrequest(self, method, path): + pass + + def putheader(self, header, *values): + # Essentially what Python 2.7 does that caused us problems. + '\r\n\t'.join(values) + + def endheaders(self): + pass + + bufferedhttp.HTTPSConnection = MockHTTPSConnection + bufferedhttp.http_connect('127.0.0.1', 8080, 'sda', 1, 'GET', '/', + headers={'x-one': '1', 'x-two': 2, 'x-three': 3.0, + 'x-four': {'crazy': 'value'}}, ssl=True) + bufferedhttp.http_connect_raw('127.0.0.1', 8080, 'GET', '/', + headers={'x-one': '1', 'x-two': 2, 'x-three': 3.0, + 'x-four': {'crazy': 'value'}}, ssl=True) + if __name__ == '__main__': unittest.main()