From 2d9b7c090a2f09ff8dd081cf203f3d1e99a26376 Mon Sep 17 00:00:00 2001 From: AZLisme Date: Fri, 11 Aug 2017 14:00:59 +0800 Subject: [PATCH] bug fix and example added --- examples/set_sessions.py | 19 +++++++++++++++++++ sanic/sessions.py | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 examples/set_sessions.py diff --git a/examples/set_sessions.py b/examples/set_sessions.py new file mode 100644 index 00000000..0d04138f --- /dev/null +++ b/examples/set_sessions.py @@ -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) diff --git a/sanic/sessions.py b/sanic/sessions.py index 697286cd..1de951d9 100644 --- a/sanic/sessions.py +++ b/sanic/sessions.py @@ -289,7 +289,7 @@ class SecureCookieSessionInterface(SessionInterface): if not self.should_set_cookie(app, session): return 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) val = self.get_signing_serializer(app).dumps(dict(session)) session_cookie_name = app.config.SESSION_COOKIE_NAME @@ -300,4 +300,4 @@ class SecureCookieSessionInterface(SessionInterface): if domain: response.cookies[session_cookie_name]["domain"] = domain response.cookies[session_cookie_name]["path"] = path - response.cookies[session_cookie_name]["secure"] = secure + # response.cookies[session_cookie_name]["secure"] = secure