diff --git a/keystoneauth1/session.py b/keystoneauth1/session.py index 0fa31845..0330c249 100644 --- a/keystoneauth1/session.py +++ b/keystoneauth1/session.py @@ -48,7 +48,7 @@ DEFAULT_USER_AGENT = 'keystoneauth1/%s %s %s/%s' % ( # NOTE(jamielennox): Clients will likely want to print more than json. Please # propose a patch if you have a content type you think is reasonable to print # here and we'll add it to the list as required. -_LOG_CONTENT_TYPES = set(['application/json']) +_LOG_CONTENT_TYPES = set(['application/json', 'text/plain']) _MAX_RETRY_INTERVAL = 60.0 _EXPONENTIAL_DELAY_START = 0.5 diff --git a/keystoneauth1/tests/unit/test_session.py b/keystoneauth1/tests/unit/test_session.py index b191e8d9..cff5b544 100644 --- a/keystoneauth1/tests/unit/test_session.py +++ b/keystoneauth1/tests/unit/test_session.py @@ -383,11 +383,13 @@ class SessionTests(utils.TestCase): """Verify response body is only logged in specific content types. Response bodies are logged only when the response's Content-Type header - is set to application/json. This prevents us to get an unexpected - MemoryError when reading arbitrary responses, such as streams. + is set to application/json or text/plain. This prevents us to get an + unexpected MemoryError when reading arbitrary responses, such as + streams. """ - OMITTED_BODY = ('Omitted, Content-Type is set to %s. Only ' - 'application/json responses have their bodies logged.') + OMITTED_BODY = ('Omitted, Content-Type is set to %s. Only ' + + ', '.join(client_session._LOG_CONTENT_TYPES) + + ' responses have their bodies logged.') session = client_session.Session(verify=False) # Content-Type is not set @@ -422,6 +424,23 @@ class SessionTests(utils.TestCase): self.assertNotIn(OMITTED_BODY % 'application/json; charset=UTF-8', self.logger.output) + # Content-Type is set to text/plain + text = 'Error detected, unable to continue.' + self.stub_url('POST', text=text, + headers={'Content-Type': 'text/plain'}) + session.post(self.TEST_URL) + self.assertIn(text, self.logger.output) + self.assertNotIn(OMITTED_BODY % 'text/plain', self.logger.output) + + # Content-Type is set to text/plain; charset=UTF-8 + text = 'Error detected, unable to continue.' + self.stub_url('POST', text=text, + headers={'Content-Type': 'text/plain; charset=UTF-8'}) + session.post(self.TEST_URL) + self.assertIn(text, self.logger.output) + self.assertNotIn(OMITTED_BODY % 'text/plain; 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)