我想将所有请求重定向到http
to https
.
是否有通用的设置方法wsgi.url_scheme
to https
在 Python 2.7 Bottle 应用程序中?
应用程序的一般结构是:
setup.py // contains 'install_requires'
wsgi
- myapplication.py // the custom application containing bottle routes
wsgi.url_scheme
似乎与环境变量有关:
http://wsgi.readthedocs.org/en/latest/definitions.html#envvar-wsgi.url_scheme
但我不确定如何实际将环境变量“设置”为https
以及是否可以在setup.py
or myapplication.py
文件。
这里有一段代码:
https://github.com/defnull/bottle/issues/347
def i_am_https_dammit(app):
def https_app(environ, start_response):
environ['wsgi.url_scheme'] = 'https'
return app(environ, start_response)
return https_app
但我不知道如何实现这一点,因为我对应用程序的调用来自cork并且只使用:
application=default_app()
session_opts = {
'session.cookie_expires': True,
'session.encrypt_key': 'please use a random key and keep it secret!',
'session.httponly': True,
'session.timeout': 3600 * 24, # 1 day
'session.type': 'cookie',
'session.validate_key': True,
}
application = SessionMiddleware(application, session_opts)