代码之家  ›  专栏  ›  技术社区  ›  shkschneider blazzerbg

BottlyPy-如何阅读UWSGI_SCHEE?

  •  2
  • shkschneider blazzerbg  · 技术社区  · 13 年前

    我有一个使用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。

    2 回复  |  直到 13 年前
        1
  •  2
  •   shkschneider blazzerbg    13 年前

    request.environ 确实是要走的路。

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

    幸亏 迈克 为我指明了正确的方向。

    print request.environ['wsgi.url_scheme']
    

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

        2
  •  1
  •   stderr    13 年前

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

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