Support forward "content-type" header 49/46949/1
authorEthan Lynn <ethanlynnl@vmware.com>
Thu, 10 May 2018 05:51:43 +0000 (13:51 +0800)
committerEthan Lynn <ethanlynnl@vmware.com>
Thu, 10 May 2018 05:54:14 +0000 (13:54 +0800)
Forward "content-type" in request headers

Change-Id: Iac920045534aafb10a31cc21ebb95a436104c5b7
Issue-ID: MULTICLOUD-229
Signed-off-by: Ethan Lynn <ethanlynnl@vmware.com>
multivimbroker/multivimbroker/pub/utils/syscomm.py
multivimbroker/multivimbroker/tests/test_syscomm.py

index 7a45395..9e96d2e 100644 (file)
@@ -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):
index e28c2c7..1a5017c 100644 (file)
@@ -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)