Flask-SocketIO session dont sharing between http and websocket behind spring cloud gateway redirect #1908
Unanswered
GMoraesGarcia
asked this question in
Q&A
Replies: 1 comment 2 replies
-
Unfortunately I cannot help with this, as I'm not familiar with the cloud service that you are using. You need to ensure that the session cookie is always passed on to the Flask app. It must be missing in your WebSocket requests. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a simple endpoint redirection in spring cloud gateway, to my flask service, when i access this flask app by gateway, the session between http and websocket is not sync, and when i access direct my flask app works normaly, i using redis session.
My configuration:
app.config['SECRET_KEY'] = 'secret!'
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "redis"
app.config['SESSION_USE_SIGNER'] = True
app.config['SESSION_REDIS'] = redis.from_url('redis://{HOST_REDIS}:6379')
Session(app)
CORS(app, resources={r"/": {"origins":""}})
socketio = SocketIO(app, cors_allowed_origins="*", manage_session=True, engineio_logger=True)
endpoint that the gateway does the redirection:
@app.route("/flask-mvp", methods=['GET'])
def print_hi():
header = request.headers
bearer_token = TOKEN #header.get("Authorization").split(" ")[1]
content = decoder(bearer_token)
user_id = content['sub']
user_name = content['name']
user_email = content['email']
session['user_infs'] = {
"user_name": user_name,
"user_email": user_email,
"user_id": user_id
}
logging.critical(session['user_infs']['user_id'])
return render_template('mvp-front-session.html',
user_id=user_id,
user_name=user_name,
user_email=user_email,
)
websocket topic when i consume session infs:
@socketio.on('sendOther')
def other_impl_teste(msg):
rabbit_conn = pika.BlockingConnection(pika.ConnectionParameters(RABBITMQ_HOST))
channel = rabbit_conn.channel()
queue_callback = "callback_other_" + session['user_infs']['user_id']
data = {
"message": msg,
"queue_callback": queue_callback
}
channel.queue_declare(queue=queue_callback)
channel.basic_publish(
exchange='',
routing_key=queue_callback,
body=json.dumps(data)
)
channel.close()
emit('getOther', 'Deploing Other...')
time.sleep(20)
sub_rabbit(queue_callback)
Beta Was this translation helpful? Give feedback.
All reactions