From db743e363544d2064107cbaedcf2f5fda4683b8a Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Mon, 2 Feb 2015 09:39:15 -0600 Subject: [PATCH] Ignore NoneType when encoding headers Some generated header values may in fact be None. Trying to encode None causes the client to fail with an exception and cannot be worked around by the user. Change-Id: I638b1fba0ef9a07d726445d8c2cdd774140f5b83 Closes-bug: 1415935 --- glanceclient/common/http.py | 2 +- tests/test_http.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/glanceclient/common/http.py b/glanceclient/common/http.py index e867ac2d..40a39cb2 100644 --- a/glanceclient/common/http.py +++ b/glanceclient/common/http.py @@ -147,7 +147,7 @@ class HTTPClient(object): names and values """ return dict((encodeutils.safe_encode(h), encodeutils.safe_encode(v)) - for h, v in six.iteritems(headers)) + for h, v in six.iteritems(headers) if v is not None) def _request(self, method, url, **kwargs): """Send an http request with the specified characteristics. diff --git a/tests/test_http.py b/tests/test_http.py index 7356ca46..daab8057 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -163,9 +163,10 @@ class TestClient(testtools.TestCase): def test_headers_encoding(self): value = u'ni\xf1o' - headers = {"test": value} + headers = {"test": value, "none-val": None} encoded = self.client.encode_headers(headers) self.assertEqual(b"ni\xc3\xb1o", encoded[b"test"]) + self.assertNotIn("none-val", encoded) def test_raw_request(self): " Verify the path being used for HTTP requests reflects accurately. "