Don't crash when header is value of None
Before commit 7d88d14d (http://git.io/hhJWdQ) swifclient used to accept header value with the type None : {'Headers': None} It would just be happy with it with those None headers and not process them, reinstate the old behavior. Closes-Bug: 1256441 Change-Id: Ic7f80c38ef2ce9ef1687ed0d6d65521f2e754905
This commit is contained in:
parent
0ef054585a
commit
983988093f
@ -97,7 +97,9 @@ def quote(value, safe='/'):
|
|||||||
|
|
||||||
def validate_headers(headers):
|
def validate_headers(headers):
|
||||||
if 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:
|
if '\n' in value:
|
||||||
raise InvalidHeadersException("%r header contained a "
|
raise InvalidHeadersException("%r header contained a "
|
||||||
"newline" % key)
|
"newline" % key)
|
||||||
|
@ -190,6 +190,11 @@ class TestHttpHelpers(MockHttpTest):
|
|||||||
self.assertRaises(c.InvalidHeadersException, c.validate_headers,
|
self.assertRaises(c.InvalidHeadersException, c.validate_headers,
|
||||||
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
|
# TODO: following tests are placeholders, need more tests, better coverage
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user