How to prevent update of session expiration time for specific URL

The6thSense

Flask Version:

>>> flask.__version__
'0.12.2'

I don't want to update the expiration time for a certain URL.
Currently, I use the following method for setting session expiration time:

session.permanent = true
app.permanent_session_lifetime = timedelta(minutes=int(10))

I have a status page which auto-refreshes every minute using an ajax method to get only the data.
I don't want to reset the session expiration time in this case.
Is there any way to do so?

Edit:

My Code so far:

from datetime import timedelta
from flask import Flask
from flask import session

APP = Flask(__name__, static_url_path='', static_folder='templates')

def create_user_session(user_accountid, auth_token):
    session['token'] = auth_token
    session['user_accountid'] = user_accountid

def update_session():
    session.permanent = True
    APP.permanent_session_lifetime = timedelta(minutes=10)
    session.modified = True

@APP.route('/batch_status', methods=['GET'])
def view_status():
    create_user_session(1, "****")
    update_session()
    return "Session Change"

@APP.route('/batch_status_json', methods=['GET'])
def retrieve_status():
    return "Session No Change"

if __name__ == '__main__':
    APP.secret_key = "My Precious Key"
    APP.run(host='0.0.0.0', debug=True, port=8000)

I don't want to change the session expiration time on batch_status_json call but it automatically changes when called.

Edit2:

monitor_controller.py:

from datetime import timedelta
from flask import Flask
from flask import session
from status import RETRIEVE_STATUS

APP = Flask(__name__, static_url_path='', static_folder='templates')

APP.register_blueprint(RETRIEVE_STATUS)
def create_user_session(user_accountid, auth_token):
    session['token'] = auth_token
    session['user_accountid'] = user_accountid

def update_session():
    session.permanent = True
    APP.permanent_session_lifetime = timedelta(minutes=10)
    session.modified = True

@APP.route('/batch_status', methods=['GET'])
def view_status():
    create_user_session(1, "****")
    update_session()
    return "Session Change"

if __name__ == '__main__':
    APP.secret_key = "My Precious Key"
    APP.run(host='0.0.0.0', debug=True, port=8000)

status.py:

from flask import Blueprint

RETRIEVE_STATUS = Blueprint('retrieve_status', __name__)
@RETRIEVE_STATUS.route('/batch_status_json', methods=['GET'])
def retrieve_status():
    return "Session No Change"
user650881

The cookies are set if the session is marked modified OR if the SESSION_REFRESH_EACH_REQUEST option is set. By default the option is True.

In your Flask config try setting

SESSION_REFRESH_EACH_REQUEST = False

From the documentation:

SESSION_REFRESH_EACH_REQUEST

Control whether the cookie is sent with every response when session.permanent is true. Sending the cookie every time (the default) can more reliably keep the session from expiring, but uses more bandwidth. Non-permanent sessions are not affected.

Default: True

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to update a session variable of a specific session

How to set the expiration time for a cookie managed by Plack::Middleware::Session?

How to update Expiration Time in Azure Notification Hub registration?

Google Bigquery: How to update partition expiration time for a partitioned table?

How to prevent actions at specific date and time?

How to set expire time for specific session

phpMyAdmin - cannot change session expiration time

how can i extend the cookie expiration time in php everytime i i regenerate the session id?

How to prevent password expiration in apache Archiva

clickonce, customer specific update URL - How to manage

What is the maximum expiration time for CloudFront signed url

How to set/update expiration time for a table in Google big Query using ruby

How precise is websphere's session expiration?

How can I remove the session expiration for a user?

Elixir / Phoenix: How to implement session timeout / expiration

How to check expiration time of a cached Pre-Signed URL accessKeyId (the signer, not the signature)?

SQL UPDATE for specific user session

AWS S3 API session expiration time

iOS prevent date/time update?

I'm currently logged in my web mail (mail.com). How do I check cookie/session expiration time?

How to create a new watson assistant session on exisiting session expiration in Flask?

Session timeout in php with specific time

Spring Security: session expiration without redirect to expired-url?

Prevent session timeout during database update

How to prevent tomcat session hijacking?

Azure Oauth - how to change token expiration time?

How to change the expiration time of a Google Access Token?

How to set expiration time for hmset in node redis?

Rails: How to look for project time expiration?