python - Removing Flask session -
in app after logging in, set:
session['venue_id'] = true
in javascript
connect websocket
:
var socket = io.connect('http://my.ip.address.' + ':' + '80' + namespace);
this triggers following code on server:
@socketio.on('connect', namespace='/test') def test_connect(): if session.get('venue_id'): session.pop('venue_id', none) else: request.namespace.disconnect()
following make calls api
check:
if session.get('venue_id')
however, goes through fine. have thought these requests
not have gone through if
statement venue_id
had been popped
?
i read answer here: python + flask - removing key session fast
but confused purpose of session.pop('venue_id', none)
is?
any clearing appreciated.
you need send (non-websocket) response alter session. popping value nothing, browser doesn't update it's side , sends data again next request. right now, application:
- logs in, sets value, returns response
- sends request (for websocket), sends value
- whatever response socket sends occurs before
test_connect
event handler, doesn't pop value - event handler runs, no way tell browswer session has changed
- whatever response socket sends occurs before
- browser sends request other page, sends value
probably simplest solution store session server side, can alter without sending response.
Comments
Post a Comment