summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-01-18 03:15:24 +0000
committerGerrit Code Review <review@openstack.org>2017-01-18 03:15:24 +0000
commit9365dbeb6d4ffb70d0e2ecf561fadbb3e150b23c (patch)
treec5be8332753bcfff9afbd37490161850c899e306
parent8a7bd461f43141ebd5df5ff457299e6ce9c6e2a0 (diff)
parented6ae95fa2ea529088d288e3e5f4099e8e1a2520 (diff)
Merge "Correctly Omit Response Body in Debug Mode"ocata-em2.18.0
-rw-r--r--keystoneauth1/session.py11
-rw-r--r--keystoneauth1/tests/unit/test_session.py10
2 files changed, 19 insertions, 2 deletions
diff --git a/keystoneauth1/session.py b/keystoneauth1/session.py
index 4ec5f0c..2943239 100644
--- a/keystoneauth1/session.py
+++ b/keystoneauth1/session.py
@@ -366,8 +366,15 @@ class Session(object):
366 # stream of bytes and getting an unexpected MemoryError. See 366 # stream of bytes and getting an unexpected MemoryError. See
367 # bug 1616105 for further details. 367 # bug 1616105 for further details.
368 content_type = response.headers.get('content-type', None) 368 content_type = response.headers.get('content-type', None)
369 if content_type in _LOG_CONTENT_TYPES: 369
370 text = self._remove_service_catalog(response.text) 370 # NOTE(lamt): Per [1], the Content-Type header can be of the
371 # form Content-Type := type "/" subtype *[";" parameter]
372 # [1] https://www.w3.org/Protocols/rfc1341/4_Content-Type.html
373 for log_type in _LOG_CONTENT_TYPES:
374 if content_type is not None and content_type.startswith(
375 log_type):
376 text = self._remove_service_catalog(response.text)
377 break
371 else: 378 else:
372 text = ('Omitted, Content-Type is set to %s. Only ' 379 text = ('Omitted, Content-Type is set to %s. Only '
373 '%s responses have their bodies logged.') 380 '%s responses have their bodies logged.')
diff --git a/keystoneauth1/tests/unit/test_session.py b/keystoneauth1/tests/unit/test_session.py
index b2ed3d7..f3e8ee7 100644
--- a/keystoneauth1/tests/unit/test_session.py
+++ b/keystoneauth1/tests/unit/test_session.py
@@ -292,6 +292,16 @@ class SessionTests(utils.TestCase):
292 self.assertIn(body, self.logger.output) 292 self.assertIn(body, self.logger.output)
293 self.assertNotIn(OMITTED_BODY % 'application/json', self.logger.output) 293 self.assertNotIn(OMITTED_BODY % 'application/json', self.logger.output)
294 294
295 # Content-Type is set to application/json; charset=UTF-8
296 body = json.dumps({'token': {'id': '...'}})
297 self.stub_url(
298 'POST', text=body,
299 headers={'Content-Type': 'application/json; charset=UTF-8'})
300 session.post(self.TEST_URL)
301 self.assertIn(body, self.logger.output)
302 self.assertNotIn(OMITTED_BODY % 'application/json; charset=UTF-8',
303 self.logger.output)
304
295 def test_logging_cacerts(self): 305 def test_logging_cacerts(self):
296 path_to_certs = '/path/to/certs' 306 path_to_certs = '/path/to/certs'
297 session = client_session.Session(verify=path_to_certs) 307 session = client_session.Session(verify=path_to_certs)