summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Riedemann <mriedem@us.ibm.com>2014-09-15 14:55:28 -0700
committerMatt Riedemann <mriedem@us.ibm.com>2014-09-15 14:57:58 -0700
commitba19a534b7576846d542f9c6a4d6769253c603e8 (patch)
tree478cdd7407ee84a91258ceb11384869a73695dba
parent4a5903bce7cbe7e8384541b66020074b7fbe1702 (diff)
downloadpython-glanceclient-ba19a534b7576846d542f9c6a4d6769253c603e8.tar.gz
Handle UnicodeDecodeError in log_http_response
Similar to commit dec9c9f35 and log_curl_request, this ignores decoding errors when logging response headers by passing errors='ignore' to safe_encode. Change-Id: Ic915a7d8334e9473f300c9db670a3a8f5cda8976 Closes-Bug: #1369756
-rw-r--r--glanceclient/common/http.py3
-rw-r--r--tests/test_http.py10
2 files changed, 12 insertions, 1 deletions
diff --git a/glanceclient/common/http.py b/glanceclient/common/http.py
index 8c7937a..91193db 100644
--- a/glanceclient/common/http.py
+++ b/glanceclient/common/http.py
@@ -130,7 +130,8 @@ class HTTPClient(object):
if body:
body = strutils.safe_decode(body)
dump.extend([body, ''])
- LOG.debug('\n'.join([strutils.safe_encode(x) for x in dump]))
+ LOG.debug('\n'.join([strutils.safe_encode(x, errors='ignore')
+ for x in dump]))
@staticmethod
def encode_headers(headers):
diff --git a/tests/test_http.py b/tests/test_http.py
index 0c8a4ac..89bc2af 100644
--- a/tests/test_http.py
+++ b/tests/test_http.py
@@ -232,6 +232,16 @@ class TestClient(testtools.TestCase):
self.assertTrue(isinstance(body, types.GeneratorType))
self.assertEqual([data], list(body))
+ def test_log_http_response_with_non_ascii_char(self):
+ try:
+ response = 'Ok'
+ headers = {"Content-Type": "text/plain",
+ "test": "value1\xa5\xa6"}
+ fake = utils.FakeResponse(headers, six.StringIO(response))
+ self.client.log_http_response(fake)
+ except UnicodeDecodeError as e:
+ self.fail("Unexpected UnicodeDecodeError exception '%s'" % e)
+
class TestVerifiedHTTPSConnection(testtools.TestCase):
"""Test fixture for glanceclient.common.http.VerifiedHTTPSConnection."""