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