feat: Update isCurl to isCLI to allow more CLI agents

This commit is contained in:
2025-10-30 17:07:20 +11:00
parent 19c51c3665
commit 844f1b52e2
3 changed files with 17 additions and 11 deletions

View File

@@ -27,6 +27,12 @@ CRAWLERS = [
"Twitterbot"
]
CLI_AGENTS = [
"curl",
"hurl",
"xh"
]
def getClientIP(request: Request) -> str:
"""
@@ -75,7 +81,7 @@ def getGitCommit() -> str:
return "failed to get version"
def isCurl(request: Request) -> bool:
def isCLI(request: Request) -> bool:
"""
Check if the request is from curl or hurl.
@@ -87,7 +93,7 @@ def isCurl(request: Request) -> bool:
"""
if request.headers and request.headers.get("User-Agent"):
user_agent = request.headers.get("User-Agent", "")
return "curl" in user_agent or "hurl" in user_agent
return any(agent in user_agent for agent in CLI_AGENTS)
return False
@@ -221,7 +227,7 @@ def error_response(
Returns:
Union[Tuple[Dict, int], object]: The JSON or HTML response
"""
if force_json or isCurl(request):
if force_json or isCLI(request):
return json_response(request, message, code)
# Check if <error code>.html exists in templates