feat(workflow): add default User-Agent and redirect following for HTTP request node, add config example
This commit is contained in:
@@ -188,6 +188,50 @@ class HttpRequestNodeConfig(BaseNodeConfig):
|
||||
description="Configuration for handling HTTP request errors",
|
||||
)
|
||||
|
||||
class Config:
|
||||
json_schema_extra = {
|
||||
"examples": [
|
||||
{
|
||||
"method": "GET",
|
||||
"url": "{{sys.message}}",
|
||||
"auth": {
|
||||
"auth_type": "none",
|
||||
"header": "",
|
||||
"api_key": ""
|
||||
},
|
||||
"headers": {
|
||||
# "Content-Type": "application/json",
|
||||
# "User-Agent": "Workflow-HttpNode/1.0"
|
||||
},
|
||||
"params": {},
|
||||
"body": {
|
||||
"content_type": "none",
|
||||
"data": ""
|
||||
},
|
||||
"verify_ssl": True,
|
||||
"timeouts": {
|
||||
"connect_timeout": 5,
|
||||
"read_timeout": 30,
|
||||
"write_timeout": 10
|
||||
},
|
||||
"retry": {
|
||||
"max_attempts": 3,
|
||||
"retry_interval": 500
|
||||
},
|
||||
"error_handle": {
|
||||
"method": "default",
|
||||
"default": {
|
||||
"body": "Upstream service unavailable",
|
||||
"status_code": 502,
|
||||
"headers": {
|
||||
"Content-Type": "text/plain"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
class HttpRequestNodeOutput(BaseModel):
|
||||
body: str = Field(
|
||||
|
||||
@@ -13,6 +13,9 @@ from app.core.workflow.nodes.http_request.config import HttpRequestNodeConfig, H
|
||||
|
||||
logger = logging.getLogger(__file__)
|
||||
|
||||
DEFAULT_USER_AGENT = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
||||
"(KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36")
|
||||
|
||||
|
||||
class HttpRequestNode(BaseNode):
|
||||
"""
|
||||
@@ -88,7 +91,9 @@ class HttpRequestNode(BaseNode):
|
||||
|
||||
Both header keys and values support runtime template rendering.
|
||||
"""
|
||||
headers = {}
|
||||
headers = {
|
||||
"user-agent": DEFAULT_USER_AGENT
|
||||
}
|
||||
for key, value in self.typed_config.headers.items():
|
||||
headers[self._render_template(key, state)] = self._render_template(value, state)
|
||||
return headers
|
||||
@@ -204,6 +209,7 @@ class HttpRequestNode(BaseNode):
|
||||
timeout=self._build_timeout(),
|
||||
headers=self._build_header(state) | self._build_auth(state),
|
||||
params=self._build_params(state),
|
||||
follow_redirects=True
|
||||
) as client:
|
||||
retries = self.typed_config.retry.max_attempts
|
||||
while retries > 0:
|
||||
|
||||
Reference in New Issue
Block a user