Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Flask from ever sending Set-Cookie?

Can I prevent Flask framework from ever sending a Set-Cookie header?

I'm using a variety of blueprints that use the session cookie. I'm wondering if there is a way to tell the framework to simply never try to set cookies. I'd like to not have to prepare each individual response using suggestions like this or using app.after_request.

like image 957
sholsapp Avatar asked Jun 28 '17 01:06

sholsapp


1 Answers

You can create custom session interface and override should_set_cookie method

from flask import Flask
from flask.sessions import SecureCookieSessionInterface, SessionMixin


class CustomSessionInterface(SecureCookieSessionInterface):
    def should_set_cookie(self, app: "Flask", session: SessionMixin) -> bool:
        return False


app = Flask(__name__)
app.session_interface = CustomSessionInterface()
like image 196
r-m-n Avatar answered Nov 09 '22 08:11

r-m-n