Ensure Content-Type header is set when required
This used to be set to application/json when there was request data,
but this was removed in change
I6bd9a0719acfb839fcf137c58bcf03254b1af5ad without any particular
explanation.
There have been reports of some redfish implementations returning
error responses (400 or 415) when this header is not set, specifically
HPE Gen9. It is good practice to always set Content-Type on requests
with data anyway. This change adds that header back.
Change-Id: I13107bbea4d422fdfe620ade735a2e150cb51bf2
(cherry picked from commit f52aac46cd
)
This commit is contained in:
parent
95b3a32a81
commit
c808743d62
|
@ -88,7 +88,10 @@ class Connector(object):
|
|||
url = path if urlparse.urlparse(path).netloc else urlparse.urljoin(
|
||||
self._url, path)
|
||||
headers = headers or {}
|
||||
if not any(k.lower() == 'odata-version' for k in headers):
|
||||
lc_headers = [k.lower() for k in headers]
|
||||
if data is not None and 'content-type' not in lc_headers:
|
||||
headers['Content-Type'] = 'application/json'
|
||||
if 'odata-version' not in lc_headers:
|
||||
headers['OData-Version'] = '4.0'
|
||||
# TODO(lucasagomes): We should mask the data to remove sensitive
|
||||
# information
|
||||
|
|
|
@ -220,6 +220,7 @@ class ConnectorOpTestCase(base.TestCase):
|
|||
self.conn._session.headers['X-Auth-Token'] = 'asdf1234'
|
||||
expected_headers = self.headers.copy()
|
||||
expected_headers['OData-Version'] = '4.0'
|
||||
expected_headers['Content-Type'] = 'application/json'
|
||||
self.conn._op('POST', path='fake/path', headers=self.headers,
|
||||
data=self.data)
|
||||
self.request.assert_called_once_with(
|
||||
|
|
Loading…
Reference in New Issue