diff options
author | Rabi Mishra <ramishra@redhat.com> | 2019-03-14 20:27:25 +0530 |
---|---|---|
committer | Rabi Mishra <ramishra@redhat.com> | 2019-03-15 05:08:51 +0000 |
commit | bd33e310e09339a21097c66d4022538f6bcbad2f (patch) | |
tree | 8abcab58ba228b406185d2f5b875149389e827b6 | |
parent | 8af5deb458d51f4ec16e769d7fd6c94655f82f5f (diff) | |
download | python-heatclient-bd33e310e09339a21097c66d4022538f6bcbad2f.tar.gz |
Set Content-Type header explictly for SessionClient
SessionClient is subclassed from keystoneauth LegacyJsonAdapter.
LegacyJsonAdapter does not set the Content-Type explicitly
and results in decodeing issues in some cases.
Change-Id: Idf23022b394607c332490331fc4b216de6ff1313
Story: 2005237
Task: 30027
-rw-r--r-- | heatclient/common/http.py | 3 | ||||
-rw-r--r-- | heatclient/tests/unit/test_common_http.py | 8 |
2 files changed, 9 insertions, 2 deletions
diff --git a/heatclient/common/http.py b/heatclient/common/http.py index 0894e19..1f86c24 100644 --- a/heatclient/common/http.py +++ b/heatclient/common/http.py @@ -308,6 +308,9 @@ class SessionClient(adapter.LegacyJsonAdapter): redirect = kwargs.get('redirect') kwargs.setdefault('user_agent', USER_AGENT) + headers = kwargs.setdefault('headers', {}) + headers.setdefault('Content-Type', 'application/json') + if 'data' in kwargs: kwargs['data'] = jsonutils.dumps(kwargs['data']) diff --git a/heatclient/tests/unit/test_common_http.py b/heatclient/tests/unit/test_common_http.py index 79cb551..17afa38 100644 --- a/heatclient/tests/unit/test_common_http.py +++ b/heatclient/tests/unit/test_common_http.py @@ -637,7 +637,8 @@ class SessionClientTest(testtools.TestCase): self.assertEqual(('', 'GET'), self.request.call_args_list[0][0]) self.assertEqual(('ishere', 'GET'), self.request.call_args_list[1][0]) for call in self.request.call_args_list: - self.assertEqual({'user_agent': 'python-heatclient', + self.assertEqual({'headers': {'Content-Type': 'application/json'}, + 'user_agent': 'python-heatclient', 'raise_exc': False, 'redirect': True}, call[1]) @@ -668,7 +669,8 @@ class SessionClientTest(testtools.TestCase): self.assertEqual(('http://no.where/ishere', 'GET'), self.request.call_args_list[1][0]) for call in self.request.call_args_list: - self.assertEqual({'user_agent': 'python-heatclient', + self.assertEqual({'headers': {'Content-Type': 'application/json'}, + 'user_agent': 'python-heatclient', 'raise_exc': False, 'redirect': True}, call[1]) @@ -750,6 +752,7 @@ class SessionClientTest(testtools.TestCase): self.assertEqual({'endpoint_override': 'http://no.where/', 'data': '"some_data"', + 'headers': {'Content-Type': 'application/json'}, 'user_agent': 'python-heatclient', 'raise_exc': False}, self.request.call_args[1]) self.assertEqual(200, resp.status_code) @@ -774,6 +777,7 @@ class SessionClientTest(testtools.TestCase): self.assertEqual({'endpoint_override': 'http://no.where/', 'data': "{'files': test}}", + 'headers': {'Content-Type': 'application/json'}, 'user_agent': 'python-heatclient', 'raise_exc': False}, self.request.call_args[1]) self.assertEqual(200, resp.status_code) |