diff --git a/src/crowdstrike/foundry/function/model.py b/src/crowdstrike/foundry/function/model.py index 6789161..0f265cf 100644 --- a/src/crowdstrike/foundry/function/model.py +++ b/src/crowdstrike/foundry/function/model.py @@ -52,6 +52,24 @@ def map_dict_to_dataclass(d: Dict, dc) -> [None, dataclass]: return dc +def _canonize_header(h: str) -> str: + """ + Converts a header key into its canonical version. + :param h: Header key. + :return: Canonized version. + """ + canon = '' + upper = True + for c in h: + if upper: + canon += c.upper() + else: + canon += c.lower() + + upper = c == '-' + return canon + + @dataclass class APIError: """ @@ -102,6 +120,11 @@ def from_json_payload(payload: str) -> 'Request': req_dict = json.loads(payload) req = map_dict_to_dataclass(req_dict, Request()) req.params = map_dict_to_dataclass(req_dict.get('params', None), Params()) + if req.params.header is not None and len(req.params.header) > 0: + h = {} + for k, v in req.params.header.items(): + h[_canonize_header(k)] = v + req.params.header = h return req diff --git a/tests/crowdstrike/foundry/function/test_model.py b/tests/crowdstrike/foundry/function/test_model.py index 8fb313c..82387fa 100644 --- a/tests/crowdstrike/foundry/function/test_model.py +++ b/tests/crowdstrike/foundry/function/test_model.py @@ -37,7 +37,9 @@ def test_from_json_payload(self): method='GET', params=Params( header={ - 'xyz': ['a', 'b'], + 'Accepts': ['application/json'], + 'Content-Type': ['application/json'], + 'Xyz': ['a', 'b'], }, query={ 'ijk': ['4', '5', '6'], @@ -56,6 +58,8 @@ def test_from_json_payload(self): 'method': 'GET', 'params': { 'header': { + 'accepts': ['application/json'], + 'ContENt-type': ['application/json'], 'xyz': ['a', 'b'], }, 'query': {