Unverified Commit 3c357171 authored by Yeuoly's avatar Yeuoly

fix: http

parent fcd470fc
...@@ -33,7 +33,7 @@ class HttpRequestNodeData(BaseNodeData): ...@@ -33,7 +33,7 @@ class HttpRequestNodeData(BaseNodeData):
return v return v
class Body(BaseModel): class Body(BaseModel):
type: Literal[None, 'form-data', 'x-www-form-urlencoded', 'raw', 'json'] type: Literal['none', 'form-data', 'x-www-form-urlencoded', 'raw', 'json']
data: Union[None, str] data: Union[None, str]
variables: list[VariableSelector] variables: list[VariableSelector]
......
...@@ -131,8 +131,6 @@ class HttpExecutor: ...@@ -131,8 +131,6 @@ class HttpExecutor:
self.headers['Content-Type'] = 'application/json' self.headers['Content-Type'] = 'application/json'
elif node_data.body.type == 'x-www-form-urlencoded': elif node_data.body.type == 'x-www-form-urlencoded':
self.headers['Content-Type'] = 'application/x-www-form-urlencoded' self.headers['Content-Type'] = 'application/x-www-form-urlencoded'
# elif node_data.body.type == 'form-data':
# self.headers['Content-Type'] = 'multipart/form-data'
if node_data.body.type in ['form-data', 'x-www-form-urlencoded']: if node_data.body.type in ['form-data', 'x-www-form-urlencoded']:
body = {} body = {}
...@@ -152,8 +150,10 @@ class HttpExecutor: ...@@ -152,8 +150,10 @@ class HttpExecutor:
} }
else: else:
self.body = urlencode(body) self.body = urlencode(body)
else: elif node_data.body.type in ['json', 'raw']:
self.body = original_body self.body = original_body
elif node_data.body.type == 'none':
self.body = ''
def _assembling_headers(self) -> dict[str, Any]: def _assembling_headers(self) -> dict[str, Any]:
authorization = deepcopy(self.authorization) authorization = deepcopy(self.authorization)
......
...@@ -42,7 +42,7 @@ class HttpRequestNode(BaseNode): ...@@ -42,7 +42,7 @@ class HttpRequestNode(BaseNode):
inputs=variables, inputs=variables,
outputs={ outputs={
'status_code': response.status_code, 'status_code': response.status_code,
'body': response, 'body': response.body,
'headers': response.headers 'headers': response.headers
}, },
process_data={ process_data={
......
...@@ -84,6 +84,41 @@ def test_no_auth(setup_http_mock): ...@@ -84,6 +84,41 @@ def test_no_auth(setup_http_mock):
assert '?A=b' in data assert '?A=b' in data
assert 'X-Header: 123' in data assert 'X-Header: 123' in data
@pytest.mark.parametrize('setup_http_mock', [['none']], indirect=True)
def test_custom_authorization_header(setup_http_mock):
node = HttpRequestNode(config={
'id': '1',
'data': {
'title': 'http',
'desc': '',
'variables': [{
'variable': 'args1',
'value_selector': ['1', '123', 'args1'],
}],
'method': 'get',
'url': 'http://example.com',
'authorization': {
'type': 'api-key',
'config': {
'type': 'custom',
'api_key': 'Auth',
'header': 'X-Auth',
},
},
'headers': 'X-Header:123',
'params': 'A:b',
'body': None,
}
}, **BASIC_NODE_DATA)
result = node.run(pool)
data = result.process_data.get('request', '')
assert '?A=b' in data
assert 'X-Header: 123' in data
assert 'X-Auth: Auth' in data
@pytest.mark.parametrize('setup_http_mock', [['none']], indirect=True) @pytest.mark.parametrize('setup_http_mock', [['none']], indirect=True)
def test_template(setup_http_mock): def test_template(setup_http_mock):
node = HttpRequestNode(config={ node = HttpRequestNode(config={
...@@ -237,3 +272,42 @@ def test_form_data(setup_http_mock): ...@@ -237,3 +272,42 @@ def test_form_data(setup_http_mock):
assert '2' in data assert '2' in data
assert 'api-key: Basic ak-xxx' in data assert 'api-key: Basic ak-xxx' in data
assert 'X-Header: 123' in data assert 'X-Header: 123' in data
def test_none_data(setup_http_mock):
node = HttpRequestNode(config={
'id': '1',
'data': {
'title': 'http',
'desc': '',
'variables': [{
'variable': 'args1',
'value_selector': ['1', '123', 'args1'],
}, {
'variable': 'args2',
'value_selector': ['1', '123', 'args2'],
}],
'method': 'post',
'url': 'http://example.com',
'authorization': {
'type': 'api-key',
'config': {
'type': 'basic',
'api_key':'ak-xxx',
'header': 'api-key',
}
},
'headers': 'X-Header:123',
'params': 'A:b',
'body': {
'type': 'none',
'data': '123123123'
},
}
}, **BASIC_NODE_DATA)
result = node.run(pool)
data = result.process_data.get('request', '')
assert 'api-key: Basic ak-xxx' in data
assert 'X-Header: 123' in data
assert '123123123' not in data
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment