BottlyPy – 如何阅读UWSGI_SCHEME?

我有一个使用BottlePy运行的Python应用程序。

此应用程序由Nginx路由:

listen 443; ssl on; ... location / { include uwsgi_params; uwsgi_param UWSGI_SCHEME https; uwsgi_pass unix:///var/run/uwsgi/uwsgi.sock; } 

因为我使用的是BottlePy微框架,我不能调用request.is_secure() (没有这样的方法)。

但有没有办法从代码读取UWSGI_SCHEME值?

我的目标是从代码中确定请求使用了HTTPS。

request.environ的确是要走的路。

http://bottlepy.org/docs/dev/api.html#bottle.BaseRequest.environ

感谢迈克指点我正确的方向。

 print request.environ['wsgi.url_scheme'] 

将打印URL的方案:http / https …

我不确定is_secure请求方法来自哪里,但可以使用WSGI环境( request.environ )编写自己的请求方法

 def is_secure(request): if request.environ['SERVER_PORT'] == '443': return True return False