2

I have a python application running using BottlePy.

This application is routed by Nginx:

listen 443;
ssl on;
...

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

Because I'm using the BottlePy micro-framework, I can't call request.is_secure() (No such method).

But is there a way to read the UWSGI_SCHEME value from code?

My goal is to be sure, from code, that the request used HTTPS.

4

2 に答える 2

2

request.environ was indeed the way to go.

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

Thanks to Mike for pointing me the right direction.

print request.environ['wsgi.url_scheme']

Will print the scheme of the URL: http/https...

于 2012-08-06T13:46:18.747 に答える
1

I'm not sure where the is_secure request method comes from but you could write your own using the WSGI environment (request.environ)

def is_secure(request):
    if request.environ['SERVER_PORT'] == '443':
        return True
    return False
于 2012-08-06T13:38:24.333 に答える