diff options
author | Tin Lam <tinlam@gmail.com> | 2017-01-16 23:14:42 -0600 |
---|---|---|
committer | Steve Martinelli <s.martinelli@gmail.com> | 2017-01-17 08:05:52 -0500 |
commit | dcb719d0e51afa0253c144136b41f0e390c48c4c (patch) | |
tree | f96fd028df8562a2be9166a8ac06bd391391d1ab /keystoneclient | |
parent | b120cc648ebf6b47c8b18745824d193b5cc73e94 (diff) | |
download | python-keystoneclient-dcb719d0e51afa0253c144136b41f0e390c48c4c.tar.gz |
Fix response body being omitted in debug mode incorrectly
In debug mode, when a response's header Content-Type is set
to "application/json" with a parameter, i.e.,
"application/json; charset=UTF-8". This patch set ignores
the additional parameter and only match the mimetype.
Change-Id: Ie8fcb1061e0e49b039436947524cfdc704c83846
Closes-Bug: #1656981
Diffstat (limited to 'keystoneclient')
-rw-r--r-- | keystoneclient/session.py | 10 | ||||
-rw-r--r-- | keystoneclient/tests/unit/test_session.py | 10 |
2 files changed, 18 insertions, 2 deletions
diff --git a/keystoneclient/session.py b/keystoneclient/session.py index 9b6d9b7..17b1d7f 100644 --- a/keystoneclient/session.py +++ b/keystoneclient/session.py @@ -232,8 +232,14 @@ class Session(object): # anyways may result on reading a long 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 = _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 = _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/keystoneclient/tests/unit/test_session.py b/keystoneclient/tests/unit/test_session.py index 5adc61f..7a3c57d 100644 --- a/keystoneclient/tests/unit/test_session.py +++ b/keystoneclient/tests/unit/test_session.py @@ -228,6 +228,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 = jsonutils.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_unicode_data_in_debug_output(self): """Verify that ascii-encodable data is logged without modification.""" session = client_session.Session(verify=False) |