Merge "Allow logging of Content-Type text/plain"

This commit is contained in:
Zuul 2022-05-13 17:11:37 +00:00 committed by Gerrit Code Review
commit f194e6a820
2 changed files with 24 additions and 5 deletions

View File

@ -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

View File

@ -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)