diff options
author | Rabi Mishra <ramishra@redhat.com> | 2019-03-14 20:27:25 +0530 |
---|---|---|
committer | Rabi Mishra <ramishra@redhat.com> | 2019-03-18 05:28:03 +0000 |
commit | 951b50fdc951f748b613fe0cf216a66676266de9 (patch) | |
tree | c6a0dd0d0832f23ab75c54ee6f7bf2fe9ff3a88f | |
parent | 9925529b2726558e98037c4b446d1e2ea9d53ac5 (diff) | |
download | python-heatclient-951b50fdc951f748b613fe0cf216a66676266de9.tar.gz |
Set Content-Type header explictly for SessionClient1.16.2
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
(cherry picked from commit bd33e310e09339a21097c66d4022538f6bcbad2f)
-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 bb2f0c1..c1bab6f 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) |