Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>tags/1.8.0
| """ | """ | ||||
| do http request depending on api bundle | do http request depending on api bundle | ||||
| """ | """ | ||||
| if self.method not in { | |||||
| "get", | |||||
| "head", | |||||
| "post", | |||||
| "put", | |||||
| "delete", | |||||
| "patch", | |||||
| "options", | |||||
| "GET", | |||||
| "POST", | |||||
| "PUT", | |||||
| "PATCH", | |||||
| "DELETE", | |||||
| "HEAD", | |||||
| "OPTIONS", | |||||
| }: | |||||
| _METHOD_MAP = { | |||||
| "get": ssrf_proxy.get, | |||||
| "head": ssrf_proxy.head, | |||||
| "post": ssrf_proxy.post, | |||||
| "put": ssrf_proxy.put, | |||||
| "delete": ssrf_proxy.delete, | |||||
| "patch": ssrf_proxy.patch, | |||||
| } | |||||
| method_lc = self.method.lower() | |||||
| if method_lc not in _METHOD_MAP: | |||||
| raise InvalidHttpMethodError(f"Invalid http method {self.method}") | raise InvalidHttpMethodError(f"Invalid http method {self.method}") | ||||
| request_args = { | request_args = { | ||||
| } | } | ||||
| # request_args = {k: v for k, v in request_args.items() if v is not None} | # request_args = {k: v for k, v in request_args.items() if v is not None} | ||||
| try: | try: | ||||
| response = getattr(ssrf_proxy, self.method.lower())(**request_args) | |||||
| response: httpx.Response = _METHOD_MAP[method_lc](**request_args) | |||||
| except (ssrf_proxy.MaxRetriesExceededError, httpx.RequestError) as e: | except (ssrf_proxy.MaxRetriesExceededError, httpx.RequestError) as e: | ||||
| raise HttpRequestNodeError(str(e)) from e | raise HttpRequestNodeError(str(e)) from e | ||||
| # FIXME: fix type ignore, this maybe httpx type issue | # FIXME: fix type ignore, this maybe httpx type issue | ||||
| return response # type: ignore | |||||
| return response | |||||
| def invoke(self) -> Response: | def invoke(self) -> Response: | ||||
| # assemble headers | # assemble headers |
| from constants import HIDDEN_VALUE | from constants import HIDDEN_VALUE | ||||
| from core.helper import ssrf_proxy | from core.helper import ssrf_proxy | ||||
| from core.rag.entities.metadata_entities import MetadataCondition | from core.rag.entities.metadata_entities import MetadataCondition | ||||
| from core.workflow.nodes.http_request.exc import InvalidHttpMethodError | |||||
| from extensions.ext_database import db | from extensions.ext_database import db | ||||
| from libs.datetime_utils import naive_utc_now | from libs.datetime_utils import naive_utc_now | ||||
| from models.dataset import ( | from models.dataset import ( | ||||
| "follow_redirects": True, | "follow_redirects": True, | ||||
| } | } | ||||
| response: httpx.Response = getattr(ssrf_proxy, settings.request_method)( | |||||
| data=json.dumps(settings.params), files=files, **kwargs | |||||
| ) | |||||
| _METHOD_MAP = { | |||||
| "get": ssrf_proxy.get, | |||||
| "head": ssrf_proxy.head, | |||||
| "post": ssrf_proxy.post, | |||||
| "put": ssrf_proxy.put, | |||||
| "delete": ssrf_proxy.delete, | |||||
| "patch": ssrf_proxy.patch, | |||||
| } | |||||
| method_lc = settings.request_method.lower() | |||||
| if method_lc not in _METHOD_MAP: | |||||
| raise InvalidHttpMethodError(f"Invalid http method {settings.request_method}") | |||||
| response: httpx.Response = _METHOD_MAP[method_lc](data=json.dumps(settings.params), files=files, **kwargs) | |||||
| return response | return response | ||||
| @staticmethod | @staticmethod |