diff --git a/wsio/finstitutions/trading/main.py b/wsio/finstitutions/trading/main.py index 0ec7fe9..0a82dde 100644 --- a/wsio/finstitutions/trading/main.py +++ b/wsio/finstitutions/trading/main.py @@ -107,6 +107,7 @@ def allow_origins(origin): sio = socketio.AsyncServer( cors_allowed_origins = allow_origins, + allow_headers = ["X-Session-Token", "HTTP_X_SESSION_TOKEN"], async_mode = "asgi" ) app = socketio.ASGIApp(sio) @@ -153,7 +154,10 @@ flags = { @sio.on(event = EVENT_CONNECT, namespace = NAMESPACE_MODULE) -async def handle_connect(sid, environ) -> bool: +async def handle_connect(sid, environ, *args) -> bool: + + session_token = environ.get("HTTP_X_SESSION_TOKEN") + if not session_token and len(args) > 0: session_token = args[0].get("X-Session-Token") # Start the common background processes: if not flags.get("initDone"): @@ -164,13 +168,15 @@ async def handle_connect(sid, environ) -> bool: async with lock: connected_clients[sid] = { "user": None, - "redisKey": f"io_{environ.get('HTTP_X_SESSION_TOKEN')}", + "redisKey": f"io_{session_token}", "rooms": [] } # Allow/reject requests: printer(sid) + print("SESSION TOKEN:", session_token) # print("ENVIRON:", json.to_string(environ, default = str)) + # print("ARGS:", args) while redis_cache is None: await asyncio.sleep(0.5) result = await redis_cache.set( key = connected_clients[sid]["redisKey"],