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
This commit is contained in:
@@ -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):
|
||||
|
@@ -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."""
|
||||
|
Reference in New Issue
Block a user