diff --git a/swiftclient/client.py b/swiftclient/client.py index 8dc4b716..d7349f33 100644 --- a/swiftclient/client.py +++ b/swiftclient/client.py @@ -97,7 +97,9 @@ def quote(value, safe='/'): def validate_headers(headers): if headers: - for key, value in headers.iteritems(): + for key, raw_value in headers.iteritems(): + value = str(encode_utf8(raw_value)) + if '\n' in value: raise InvalidHeadersException("%r header contained a " "newline" % key) diff --git a/tests/test_swiftclient.py b/tests/test_swiftclient.py index 1c6d3e96..7d589382 100644 --- a/tests/test_swiftclient.py +++ b/tests/test_swiftclient.py @@ -190,6 +190,11 @@ class TestHttpHelpers(MockHttpTest): self.assertRaises(c.InvalidHeadersException, c.validate_headers, headers) + def test_validate_headers_with_other_than_str(self): + for t in (None, 1, 1.0, 1L, u"A"): + self.assertEqual(c.validate_headers({'key': t}), + None) + # TODO: following tests are placeholders, need more tests, better coverage