Browse Source

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)
changes/04/781204/1 3.4.3
Steve Baker 2 months ago
committed by Dmitry Tantsur
parent
commit
af4d7fb053
2 changed files with 5 additions and 1 deletions
  1. +4
    -1
      sushy/connector.py
  2. +1
    -0
      sushy/tests/unit/test_connector.py

+ 4
- 1
sushy/connector.py View File

@ -93,7 +93,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


+ 1
- 0
sushy/tests/unit/test_connector.py View File

@ -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…
Cancel
Save