This commit is contained in:
Typer_Body
2026-05-08 00:56:27 +08:00
parent eb9f38b102
commit 75fdfe6806
51 changed files with 1585 additions and 1643 deletions

View File

@@ -15,15 +15,15 @@ from ..node import WorkflowNode, workflow_node, NodePort, NodeConfig
class HTTPRequestNode(WorkflowNode):
"""HTTP request node - make HTTP API calls"""
type_name = "http_request"
category = "process"
icon = "🌐"
name = "http_request"
description = "http_request"
name_zh = "HTTP 请求"
name_en = "HTTP Request"
description_zh = "向外部 API 发送 HTTP 请求"
description_en = "Make HTTP requests to external APIs"
type_name = 'http_request'
category = 'process'
icon = '🌐'
name = 'http_request'
description = 'http_request'
name_zh = 'HTTP 请求'
name_en = 'HTTP Request'
description_zh = '向外部 API 发送 HTTP 请求'
description_en = 'Make HTTP requests to external APIs'
inputs: ClassVar[list[NodePort]] = []
outputs: ClassVar[list[NodePort]] = []
@@ -32,39 +32,44 @@ class HTTPRequestNode(WorkflowNode):
async def execute(self, inputs: dict[str, Any], context: ExecutionContext) -> dict[str, Any]:
import aiohttp
url = self.get_config("url", "")
method = self.get_config("method", "GET")
timeout = self.get_config("timeout", 30)
content_type = self.get_config("content_type", "application/json")
url = self.get_config('url', '')
method = self.get_config('method', 'GET')
timeout = self.get_config('timeout', 30)
content_type = self.get_config('content_type', 'application/json')
headers = inputs.get("headers", {})
headers["Content-Type"] = content_type
headers = inputs.get('headers', {})
headers['Content-Type'] = content_type
auth_type = self.get_config("auth_type", "none")
auth_config = self.get_config("auth_config", {})
auth_type = self.get_config('auth_type', 'none')
auth_config = self.get_config('auth_config', {})
if auth_type == "bearer":
headers["Authorization"] = f"Bearer {auth_config.get('token', '')}"
elif auth_type == "api_key":
header_name = auth_config.get("header", "X-API-Key")
headers[header_name] = auth_config.get("key", "")
if auth_type == 'bearer':
headers['Authorization'] = f'Bearer {auth_config.get("token", "")}'
elif auth_type == 'api_key':
header_name = auth_config.get('header', 'X-API-Key')
headers[header_name] = auth_config.get('key', '')
body = inputs.get("body")
body = inputs.get('body')
try:
async with aiohttp.ClientSession() as session:
async with session.request(
method=method, url=url,
json=body if content_type == "application/json" else None,
data=body if content_type != "application/json" else None,
method=method,
url=url,
json=body if content_type == 'application/json' else None,
data=body if content_type != 'application/json' else None,
headers=headers,
timeout=aiohttp.ClientTimeout(total=timeout)
timeout=aiohttp.ClientTimeout(total=timeout),
) as response:
try:
response_data = await response.json()
except Exception:
response_data = await response.text()
return {"response": response_data, "status_code": response.status, "headers": dict(response.headers)}
return {
'response': response_data,
'status_code': response.status,
'headers': dict(response.headers),
}
except Exception as e:
return {"response": None, "status_code": 0, "headers": {}, "error": str(e)}
return {'response': None, 'status_code': 0, 'headers': {}, 'error': str(e)}