mirror of
https://github.com/open-webui/open-webui
synced 2025-01-29 22:08:07 +00:00
feat: add ENABLE_WEBSOCKET_SUPPORT to force socket.io to ignore websocket upgrades
This commit is contained in:
parent
698976add0
commit
827c419251
@ -2,16 +2,15 @@ import asyncio
|
|||||||
|
|
||||||
import socketio
|
import socketio
|
||||||
from open_webui.apps.webui.models.users import Users
|
from open_webui.apps.webui.models.users import Users
|
||||||
from open_webui.config import ENABLE_WEBSOCKET_SUPPORT
|
from open_webui.env import ENABLE_WEBSOCKET_SUPPORT
|
||||||
from open_webui.utils.utils import decode_token
|
from open_webui.utils.utils import decode_token
|
||||||
|
|
||||||
sio = socketio.AsyncServer(
|
sio = socketio.AsyncServer(
|
||||||
cors_allowed_origins=[],
|
cors_allowed_origins=[],
|
||||||
async_mode="asgi",
|
async_mode="asgi",
|
||||||
transports=(
|
transports=(["polling", "websocket"] if ENABLE_WEBSOCKET_SUPPORT else ["polling"]),
|
||||||
["polling", "websocket"] if ENABLE_WEBSOCKET_SUPPORT.value else ["polling"]
|
allow_upgrades=ENABLE_WEBSOCKET_SUPPORT,
|
||||||
),
|
always_connect=True,
|
||||||
allow_upgrades=ENABLE_WEBSOCKET_SUPPORT.value,
|
|
||||||
)
|
)
|
||||||
app = socketio.ASGIApp(sio, socketio_path="/ws/socket.io")
|
app = socketio.ASGIApp(sio, socketio_path="/ws/socket.io")
|
||||||
|
|
||||||
|
@ -810,12 +810,6 @@ ENABLE_MESSAGE_RATING = PersistentConfig(
|
|||||||
os.environ.get("ENABLE_MESSAGE_RATING", "True").lower() == "true",
|
os.environ.get("ENABLE_MESSAGE_RATING", "True").lower() == "true",
|
||||||
)
|
)
|
||||||
|
|
||||||
ENABLE_WEBSOCKET_SUPPORT = PersistentConfig(
|
|
||||||
"ENABLE_WEBSOCKET_SUPPORT",
|
|
||||||
"ui.enable_websocket_support",
|
|
||||||
os.environ.get("ENABLE_WEBSOCKET_SUPPORT", "True").lower() == "true",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def validate_cors_origins(origins):
|
def validate_cors_origins(origins):
|
||||||
for origin in origins:
|
for origin in origins:
|
||||||
|
@ -273,3 +273,7 @@ WEBUI_SESSION_COOKIE_SECURE = os.environ.get(
|
|||||||
|
|
||||||
if WEBUI_AUTH and WEBUI_SECRET_KEY == "":
|
if WEBUI_AUTH and WEBUI_SECRET_KEY == "":
|
||||||
raise ValueError(ERROR_MESSAGES.ENV_VAR_NOT_FOUND)
|
raise ValueError(ERROR_MESSAGES.ENV_VAR_NOT_FOUND)
|
||||||
|
|
||||||
|
ENABLE_WEBSOCKET_SUPPORT = (
|
||||||
|
os.environ.get("ENABLE_WEBSOCKET_SUPPORT", "True").lower() == "true"
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user