doronhorwitz · GitHub

Most of the other arguments passed into response.set_cookie() in SecureCookieSessionInterface.save_session() use the overridable methods of SessionInterface to fill in each argument. Except for the cookie name, which is statically set to app.session_cookie_name.

Sometimes a cookie name needs to be set dynamically based on the current request, for example, a cookie name that is dependent on the current subpath in the URL. At the moment, the best way of doing this is to override the save_session() method of SecureCookieSessionInterface and make it dynamically pass in the cookie name to response.set_cookie().

To avoid having to override the whole of save_session(), this pull request adds in an overridable get_cookie_name() method on SessionInterface to match the other get_xxx() methods of that class.

Note: I originally posted a question about this in Stackoverflow ("Something like get_cookie_name in Flask's SessionInterface?") and also asked the question (using the Stackoverflow link) in the Flask Discord chat. I was not satisfied with the response I got, so I've opened up this pull request.

Read the original on github.com ↗