bug fix and example added
This commit is contained in:
parent
4260b115e2
commit
2d9b7c090a
19
examples/set_sessions.py
Normal file
19
examples/set_sessions.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
|
from sanic import Sanic
|
||||||
|
from sanic.response import json
|
||||||
|
|
||||||
|
app = Sanic()
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
async def test(request):
|
||||||
|
if request.session.get('key') is None:
|
||||||
|
request.session['key'] = 'value'
|
||||||
|
return json(dict(ok=True))
|
||||||
|
else:
|
||||||
|
return json(dict(key=request.session['key']))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run(host="0.0.0.0", port=8000)
|
|
@ -289,7 +289,7 @@ class SecureCookieSessionInterface(SessionInterface):
|
||||||
if not self.should_set_cookie(app, session):
|
if not self.should_set_cookie(app, session):
|
||||||
return
|
return
|
||||||
httponly = self.get_cookie_httponly(app)
|
httponly = self.get_cookie_httponly(app)
|
||||||
secure = self.get_cookie_secure(app)
|
# secure = self.get_cookie_secure(app)
|
||||||
expires = self.get_expiration_time(app, session)
|
expires = self.get_expiration_time(app, session)
|
||||||
val = self.get_signing_serializer(app).dumps(dict(session))
|
val = self.get_signing_serializer(app).dumps(dict(session))
|
||||||
session_cookie_name = app.config.SESSION_COOKIE_NAME
|
session_cookie_name = app.config.SESSION_COOKIE_NAME
|
||||||
|
@ -300,4 +300,4 @@ class SecureCookieSessionInterface(SessionInterface):
|
||||||
if domain:
|
if domain:
|
||||||
response.cookies[session_cookie_name]["domain"] = domain
|
response.cookies[session_cookie_name]["domain"] = domain
|
||||||
response.cookies[session_cookie_name]["path"] = path
|
response.cookies[session_cookie_name]["path"] = path
|
||||||
response.cookies[session_cookie_name]["secure"] = secure
|
# response.cookies[session_cookie_name]["secure"] = secure
|
||||||
|
|
Loading…
Reference in New Issue
Block a user