From 824238a620218b23d8c81c27288b1db1f1a2e90d Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 17 Apr 2025 22:02:16 -0700 Subject: [PATCH] enh: `AIOHTTP_CLIENT_SESSION_TOOL_SERVER_SSL` --- backend/open_webui/env.py | 5 +++++ backend/open_webui/utils/tools.py | 24 ++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index c9d71a4a0..cc1b02e01 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -437,6 +437,11 @@ else: except Exception: AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER_DATA = 10 + +AIOHTTP_CLIENT_SESSION_TOOL_SERVER_SSL = ( + os.environ.get("AIOHTTP_CLIENT_SESSION_TOOL_SERVER_SSL", "True").lower() == "true" +) + #################################### # OFFLINE_MODE #################################### diff --git a/backend/open_webui/utils/tools.py b/backend/open_webui/utils/tools.py index b5d916e1d..876e1c21d 100644 --- a/backend/open_webui/utils/tools.py +++ b/backend/open_webui/utils/tools.py @@ -36,7 +36,10 @@ from langchain_core.utils.function_calling import ( from open_webui.models.tools import Tools from open_webui.models.users import UserModel from open_webui.utils.plugin import load_tool_module_by_id -from open_webui.env import AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER_DATA +from open_webui.env import ( + AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER_DATA, + AIOHTTP_CLIENT_SESSION_TOOL_SERVER_SSL, +) import copy @@ -431,8 +434,10 @@ async def get_tool_server_data(token: str, url: str) -> Dict[str, Any]: error = None try: timeout = aiohttp.ClientTimeout(total=AIOHTTP_CLIENT_TIMEOUT_TOOL_SERVER_DATA) - async with aiohttp.ClientSession(timeout=timeout) as session: - async with session.get(url, headers=headers) as response: + async with aiohttp.ClientSession(timeout=timeout, trust_env=True) as session: + async with session.get( + url, headers=headers, ssl=AIOHTTP_CLIENT_SESSION_TOOL_SERVER_SSL + ) as response: if response.status != 200: error_body = await response.json() raise Exception(error_body) @@ -573,19 +578,26 @@ async def execute_tool_server( if token: headers["Authorization"] = f"Bearer {token}" - async with aiohttp.ClientSession() as session: + async with aiohttp.ClientSession(trust_env=True) as session: request_method = getattr(session, http_method.lower()) if http_method in ["post", "put", "patch"]: async with request_method( - final_url, json=body_params, headers=headers + final_url, + json=body_params, + headers=headers, + ssl=AIOHTTP_CLIENT_SESSION_TOOL_SERVER_SSL, ) as response: if response.status >= 400: text = await response.text() raise Exception(f"HTTP error {response.status}: {text}") return await response.json() else: - async with request_method(final_url, headers=headers) as response: + async with request_method( + final_url, + headers=headers, + ssl=AIOHTTP_CLIENT_SESSION_TOOL_SERVER_SSL, + ) as response: if response.status >= 400: text = await response.text() raise Exception(f"HTTP error {response.status}: {text}")