A variant of Flask-Session, Flask-Session. Move cookie based approach into HTTP Header
based apporach.
This apporach exists because some client environment doesn't allow cookies, e.g. Weixi mini program.
Python2: pip install Flask-Header-Session
Python3: pip3 install Flask-Header-Session
# As usual import flask
import flask
# Import our package
from flask_header_session import Session
# Some configs
app.config['SESSION_TYPE'] = ......
# Use
Session(app)
This project rewrited open_session
and save_session
function to use HTTP Header
as the vehicle instead of cookie
These backends are fully supported and tested:
SQLAlchemy
Redis
The session header name can be set:
SESSION_HEADER_NAME='X-HTTP-HaHaHa'
Default value is X-Header-Session
.
See ./test_session.py
to see the sample usage.
- Create some temp data folders.
mkdir -p ./docker/volumes/varlibmysql
- Go to the test executable folder. cd
./docker/test/
- Then run
./up.sh
to run the tests in local docker containers.
- Leave an issue.
- Email me.
Flask-Session的一个变种, Flask-Session源码. 将原来的cookie的session 放入Header里面,有更好的适应性。
这个需求存在于无法使用cookie记录客户的场合,例如微信小程序不允许使用cookie。
Python2: pip install Flask-Header-Session
Python3: pip3 install Flask-Header-Session
# 引入flask
import flask
# 引入库package
from flask_header_session import Session
# 设置好环境变量
app.config['SESSION_TYPE'] = ......
# 初始化Session
Session(app)
重写了 open_session
和 save_session
方法,使用HTTP Header
而不是 cookie
来装载session内容。
以下都是完全测试过 并且支持的:
SQLAlchemy
Redis
HTTP Header名字可以更改:
SESSION_HEADER_NAME='X-HTTP-HaHaHa'
若不更改,则缺省值是 X-Header-Session
.
翻看 ./test_session.py
有两种支持后端的使用案例.
- 创建一些临时文件夹.
mkdir -p ./docker/volumes/varlibmysql
- 去往测试执行所在的文件夹. cd
./docker/test/
- 执行
./up.sh
在本地的docker环境里执行测试.
- 开个 issue.
- 给我发送 Email.