fix: http

This commit is contained in:
Yeuoly 2024-03-14 11:35:51 +08:00
parent fcd470fcac
commit 3c3571713e
No known key found for this signature in database
GPG Key ID: A66E7E320FB19F61
4 changed files with 79 additions and 5 deletions

View File

@ -33,7 +33,7 @@ class HttpRequestNodeData(BaseNodeData):
return v
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]
variables: list[VariableSelector]

View File

@ -131,8 +131,6 @@ class HttpExecutor:
self.headers['Content-Type'] = 'application/json'
elif node_data.body.type == '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']:
body = {}
@ -152,8 +150,10 @@ class HttpExecutor:
}
else:
self.body = urlencode(body)
else:
elif node_data.body.type in ['json', 'raw']:
self.body = original_body
elif node_data.body.type == 'none':
self.body = ''
def _assembling_headers(self) -> dict[str, Any]:
authorization = deepcopy(self.authorization)

View File

@ -42,7 +42,7 @@ class HttpRequestNode(BaseNode):
inputs=variables,
outputs={
'status_code': response.status_code,
'body': response,
'body': response.body,
'headers': response.headers
},
process_data={

View File

@ -84,6 +84,41 @@ def test_no_auth(setup_http_mock):
assert '?A=b' 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)
def test_template(setup_http_mock):
node = HttpRequestNode(config={
@ -237,3 +272,42 @@ def test_form_data(setup_http_mock):
assert '2' in data
assert 'api-key: Basic ak-xxx' 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