Merge "Correctly Omit Response Body in Debug Mode"

This commit is contained in:
Jenkins 2017-01-18 03:15:24 +00:00 committed by Gerrit Code Review
commit 9365dbeb6d
2 changed files with 19 additions and 2 deletions

View File

@ -366,8 +366,15 @@ class Session(object):
# stream of bytes and getting an unexpected MemoryError. See # stream of bytes and getting an unexpected MemoryError. See
# bug 1616105 for further details. # bug 1616105 for further details.
content_type = response.headers.get('content-type', None) content_type = response.headers.get('content-type', None)
if content_type in _LOG_CONTENT_TYPES:
text = self._remove_service_catalog(response.text) # NOTE(lamt): Per [1], the Content-Type header can be of the
# form Content-Type := type "/" subtype *[";" parameter]
# [1] https://www.w3.org/Protocols/rfc1341/4_Content-Type.html
for log_type in _LOG_CONTENT_TYPES:
if content_type is not None and content_type.startswith(
log_type):
text = self._remove_service_catalog(response.text)
break
else: else:
text = ('Omitted, Content-Type is set to %s. Only ' text = ('Omitted, Content-Type is set to %s. Only '
'%s responses have their bodies logged.') '%s responses have their bodies logged.')

View File

@ -292,6 +292,16 @@ class SessionTests(utils.TestCase):
self.assertIn(body, self.logger.output) self.assertIn(body, self.logger.output)
self.assertNotIn(OMITTED_BODY % 'application/json', self.logger.output) self.assertNotIn(OMITTED_BODY % 'application/json', self.logger.output)
# Content-Type is set to application/json; charset=UTF-8
body = json.dumps({'token': {'id': '...'}})
self.stub_url(
'POST', text=body,
headers={'Content-Type': 'application/json; charset=UTF-8'})
session.post(self.TEST_URL)
self.assertIn(body, self.logger.output)
self.assertNotIn(OMITTED_BODY % 'application/json; charset=UTF-8',
self.logger.output)
def test_logging_cacerts(self): def test_logging_cacerts(self):
path_to_certs = '/path/to/certs' path_to_certs = '/path/to/certs'
session = client_session.Session(verify=path_to_certs) session = client_session.Session(verify=path_to_certs)