Merge "Fix raw_request of SessionClient"

This commit is contained in:
Zuul 2020-04-30 13:03:32 +00:00 committed by Gerrit Code Review
commit ec27571c90
2 changed files with 18 additions and 2 deletions

View File

@ -398,7 +398,22 @@ class SessionClient(adapter.LegacyJsonAdapter):
kwargs.setdefault('headers', {})
kwargs['headers'].setdefault('Content-Type',
'application/octet-stream')
return self._http_request(url, method, **kwargs)
resp = self._http_request(url, method, **kwargs)
body = resp.content
status = resp.status_code
content_type = resp.headers.get('content-type', None)
if status == 204 or status == 205 or content_type is None:
return resp, list()
if 'application/json' in content_type:
try:
body = resp.json()
except ValueError:
LOG.error('Could not decode response body as JSON')
else:
body = None
return resp, body
class ResponseBodyIterator(object):

View File

@ -449,10 +449,11 @@ class SessionClientTest(utils.BaseTestCase):
client = http.SessionClient(
session=fake_session, endpoint_override='http://magnum')
resp = client.raw_request('GET', '/v1/bays')
resp, resp_body = client.raw_request('GET', '/v1/bays')
self.assertEqual(
fake_session.request.call_args[1]['headers']['Content-Type'],
'application/octet-stream'
)
self.assertEqual(None, resp_body)
self.assertEqual(fake_response, resp)