From 03056c2a987eb89129d5f2533fc78dffc73c2481 Mon Sep 17 00:00:00 2001 From: Ethan Lynn Date: Thu, 10 May 2018 13:51:43 +0800 Subject: Support forward "content-type" header Forward "content-type" in request headers Change-Id: Iac920045534aafb10a31cc21ebb95a436104c5b7 Issue-ID: MULTICLOUD-229 Signed-off-by: Ethan Lynn --- multivimbroker/multivimbroker/pub/utils/syscomm.py | 11 +++++++---- multivimbroker/multivimbroker/tests/test_syscomm.py | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'multivimbroker') diff --git a/multivimbroker/multivimbroker/pub/utils/syscomm.py b/multivimbroker/multivimbroker/pub/utils/syscomm.py index 7a45395..9e96d2e 100644 --- a/multivimbroker/multivimbroker/pub/utils/syscomm.py +++ b/multivimbroker/multivimbroker/pub/utils/syscomm.py @@ -38,10 +38,13 @@ def getHeadersKeys(response): # trim out 'HTTP_' prefix part and replace "_" wiht "-". def originHeaders(request): - regex = re.compile('^HTTP_') - return dict((regex.sub('', header).replace("_", "-"), value) - for (header, value) in request.META.items() - if header.startswith('HTTP_')) + headers = {} + for key, value in request.META.items(): + if key.startswith('HTTP_') and key != 'HTTP_HOST': + headers[key[5:].replace('_', '-')] = value + elif key in ('CONTENT_TYPE', 'CONTENT_LENGTH'): + headers[key.replace('_', '-')] = value + return headers def findMultivimDriver(vim=None): diff --git a/multivimbroker/multivimbroker/tests/test_syscomm.py b/multivimbroker/multivimbroker/tests/test_syscomm.py index e28c2c7..1a5017c 100644 --- a/multivimbroker/multivimbroker/tests/test_syscomm.py +++ b/multivimbroker/multivimbroker/tests/test_syscomm.py @@ -57,10 +57,12 @@ class TestSyscomm(unittest.TestCase): req = mock.Mock() req.META = { "HTTP_X_AUTH_TOKEN": "token_1", - "NOT_STARTSWITH_HTTP": "value_1" + "NOT_STARTSWITH_HTTP": "value_1", + "CONTENT_TYPE": "application/json" } expect_headers = { - "X-AUTH-TOKEN": "token_1" + "X-AUTH-TOKEN": "token_1", + "CONTENT-TYPE": "application/json" } ret_headers = syscomm.originHeaders(req) self.assertDictEqual(expect_headers, ret_headers) -- cgit 1.2.3-korg