diff --git a/keystoneauth1/session.py b/keystoneauth1/session.py index 4ec5f0cc..29432396 100644 --- a/keystoneauth1/session.py +++ b/keystoneauth1/session.py @@ -366,8 +366,15 @@ class Session(object): # stream of bytes and getting an unexpected MemoryError. See # bug 1616105 for further details. 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: text = ('Omitted, Content-Type is set to %s. Only ' '%s responses have their bodies logged.') diff --git a/keystoneauth1/tests/unit/test_session.py b/keystoneauth1/tests/unit/test_session.py index b2ed3d74..f3e8ee7c 100644 --- a/keystoneauth1/tests/unit/test_session.py +++ b/keystoneauth1/tests/unit/test_session.py @@ -292,6 +292,16 @@ class SessionTests(utils.TestCase): self.assertIn(body, 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): path_to_certs = '/path/to/certs' session = client_session.Session(verify=path_to_certs)