fix: http method can be upper case and lower case close #11877 (#12401)

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
This commit is contained in:
yihong 2025-01-06 20:35:53 +08:00 committed by GitHub
parent 34519de3b7
commit fe26be2312
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 66 additions and 6 deletions

View File

@ -202,8 +202,23 @@ class ApiTool(Tool):
else: else:
body = body body = body
if method in {"get", "head", "post", "put", "delete", "patch"}: if method in {
response: httpx.Response = getattr(ssrf_proxy, method)( "get",
"head",
"post",
"put",
"delete",
"patch",
"options",
"GET",
"POST",
"PUT",
"PATCH",
"DELETE",
"HEAD",
"OPTIONS",
}:
response: httpx.Response = getattr(ssrf_proxy, method.lower())(
url, url,
params=params, params=params,
headers=headers, headers=headers,

View File

@ -68,7 +68,22 @@ class HttpRequestNodeData(BaseNodeData):
Code Node Data. 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 url: str
authorization: HttpRequestNodeAuthorization authorization: HttpRequestNodeAuthorization
headers: str headers: str

View File

@ -37,7 +37,22 @@ BODY_TYPE_TO_CONTENT_TYPE = {
class Executor: 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 url: str
params: list[tuple[str, str]] | None params: list[tuple[str, str]] | None
content: str | bytes | None content: str | bytes | None
@ -249,7 +264,22 @@ class Executor:
""" """
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"}: 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}") raise InvalidHttpMethodError(f"Invalid http method {self.method}")
request_args = { request_args = {
@ -266,7 +296,7 @@ class Executor:
} }
# 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)(**request_args) response = getattr(ssrf_proxy, self.method.lower())(**request_args)
except (ssrf_proxy.MaxRetriesExceededError, httpx.RequestError) as e: except (ssrf_proxy.MaxRetriesExceededError, httpx.RequestError) as e:
raise HttpRequestNodeError(str(e)) raise HttpRequestNodeError(str(e))
# FIXME: fix type ignore, this maybe httpx type issue # FIXME: fix type ignore, this maybe httpx type issue