Merge "Fix raw_request of SessionClient"
This commit is contained in:
commit
ec27571c90
@ -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):
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user