Skip to content

Commit

Permalink
fix: http method can be upper case and lower case close langgenius#11877
Browse files Browse the repository at this point in the history
 (langgenius#12401)

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
  • Loading branch information
yihong0618 authored Jan 6, 2025
1 parent 34519de commit fe26be2
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
19 changes: 17 additions & 2 deletions api/core/tools/tool/api_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,23 @@ def do_http_request(
else:
body = body

if method in {"get", "head", "post", "put", "delete", "patch"}:
response: httpx.Response = getattr(ssrf_proxy, method)(
if method in {
"get",
"head",
"post",
"put",
"delete",
"patch",
"options",
"GET",
"POST",
"PUT",
"PATCH",
"DELETE",
"HEAD",
"OPTIONS",
}:
response: httpx.Response = getattr(ssrf_proxy, method.lower())(
url,
params=params,
headers=headers,
Expand Down
17 changes: 16 additions & 1 deletion api/core/workflow/nodes/http_request/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,22 @@ class HttpRequestNodeData(BaseNodeData):
Code Node Data.
"""

method: Literal["get", "post", "put", "patch", "delete", "head"]
method: Literal[
"get",
"post",
"put",
"patch",
"delete",
"head",
"options",
"GET",
"POST",
"PUT",
"PATCH",
"DELETE",
"HEAD",
"OPTIONS",
]
url: str
authorization: HttpRequestNodeAuthorization
headers: str
Expand Down
36 changes: 33 additions & 3 deletions api/core/workflow/nodes/http_request/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,22 @@


class Executor:
method: Literal["get", "head", "post", "put", "delete", "patch"]
method: Literal[
"get",
"head",
"post",
"put",
"delete",
"patch",
"options",
"GET",
"POST",
"PUT",
"PATCH",
"DELETE",
"HEAD",
"OPTIONS",
]
url: str
params: list[tuple[str, str]] | None
content: str | bytes | None
Expand Down Expand Up @@ -249,7 +264,22 @@ def _do_http_request(self, headers: dict[str, Any]) -> httpx.Response:
"""
do http request depending on api bundle
"""
if self.method not in {"get", "head", "post", "put", "delete", "patch"}:
if self.method not in {
"get",
"head",
"post",
"put",
"delete",
"patch",
"options",
"GET",
"POST",
"PUT",
"PATCH",
"DELETE",
"HEAD",
"OPTIONS",
}:
raise InvalidHttpMethodError(f"Invalid http method {self.method}")

request_args = {
Expand All @@ -266,7 +296,7 @@ def _do_http_request(self, headers: dict[str, Any]) -> httpx.Response:
}
# request_args = {k: v for k, v in request_args.items() if v is not None}
try:
response = getattr(ssrf_proxy, self.method)(**request_args)
response = getattr(ssrf_proxy, self.method.lower())(**request_args)
except (ssrf_proxy.MaxRetriesExceededError, httpx.RequestError) as e:
raise HttpRequestNodeError(str(e))
# FIXME: fix type ignore, this maybe httpx type issue
Expand Down

0 comments on commit fe26be2

Please sign in to comment.