diff --git a/oscar_python/_utils.py b/oscar_python/_utils.py index 5f3a27b..212432e 100644 --- a/oscar_python/_utils.py +++ b/oscar_python/_utils.py @@ -42,6 +42,13 @@ def make_request(c, path, method, **kwargs): if "data" in kwargs.keys() and kwargs["data"]: req_kwargs["data"] = kwargs["data"] req_kwargs["headers"]["Content-Type"] = "application/json" + if "headers" in kwargs.keys() and kwargs["headers"]: + try: + for header in kwargs["headers"].split(","): + chunck = header.split(":") + req_kwargs["headers"][chunck[0]] = chunck[1].lstrip() + except Exception as e: + print("error: " + str(e)) result = requests.request(method, url, **req_kwargs) else: result = requests.request(method, url, headers=headers, verify=c.ssl, timeout=timeout) diff --git a/oscar_python/default_client.py b/oscar_python/default_client.py index e748d4b..416b7c2 100644 --- a/oscar_python/default_client.py +++ b/oscar_python/default_client.py @@ -31,7 +31,8 @@ def run_service(self, name, **kwargs): path = _JOB_PATH + "/" + name response = utils.make_request(self, path, _POST, data=send_data, - token=token, timeout=kwargs.get("timeout")) + token=token, timeout=kwargs.get("timeout"), + headers=kwargs.get("headers")) if kwargs.get("output"): utils.decode_output(response.text, kwargs["output"]) diff --git a/tests/test_default_client.py b/tests/test_default_client.py index 74428e1..c17afdb 100644 --- a/tests/test_default_client.py +++ b/tests/test_default_client.py @@ -27,7 +27,7 @@ def test_run_service_with_input_and_token(mock_decode_output, mock_encode_input, mock_encode_input.assert_called_once_with("test_input") mock_make_request.assert_called_once_with( client, _RUN_PATH+"/test_service", _POST, - data="encoded_input", token="test_token", timeout=30) + data="encoded_input", token="test_token", timeout=30, headers=None) mock_decode_output.assert_called_once_with("response_text", "output_file") assert response == mock_response @@ -45,7 +45,7 @@ def test_run_service_with_input_no_token(mock_encode_input, mock_make_request, c mock_encode_input.assert_called_once_with("test_input") mock_make_request.assert_called_once_with( client, _RUN_PATH+"/test_service", _POST, - data="encoded_input", token="test_token", timeout=None) + data="encoded_input", token="test_token", timeout=None, headers=None) assert response == mock_response @@ -57,9 +57,9 @@ def test_run_service_no_input(mock_make_request, client): response = client.run_service("test_service", input="data") mock_make_request.assert_called_with(client, _RUN_PATH+"/test_service", _POST, - token="test_token", data=b'ZGF0YQ==', timeout=None) + token="test_token", data=b'ZGF0YQ==', timeout=None, headers=None) response = client.run_service("test_service", input="data", async_call=True, timeout=30) mock_make_request.assert_called_with(client, _JOB_PATH+"/test_service", _POST, - token="test_token", data=b'ZGF0YQ==', timeout=30) + token="test_token", data=b'ZGF0YQ==', timeout=30, headers=None) assert response == mock_response