fix issue #51. Support https schema. Pas an Http header to gunicorn :

X-Forwarded-Protocol=https , X-Forwarded-Ssl=on
This commit is contained in:
benoitc 2010-05-26 16:27:12 +02:00
parent b4d4427416
commit e06b44a28f

View File

@ -103,6 +103,12 @@ class Request(object):
forward_adress = self.parser.headers_dict.get('X-Forwarded-For', forward_adress = self.parser.headers_dict.get('X-Forwarded-For',
client_address) client_address)
if self.parser.headers_dict.get("X-Forwarded-Protocol") == "https" or \
self.parser.headers_dict.get("X-Forwarded-Ssl") == "on":
url_scheme = "https"
else:
url_scheme = "http"
if isinstance(forward_adress, basestring): if isinstance(forward_adress, basestring):
# we only took the last one # we only took the last one
# http://en.wikipedia.org/wiki/X-Forwarded-For # http://en.wikipedia.org/wiki/X-Forwarded-For
@ -129,7 +135,7 @@ class Request(object):
path_info = path_info.split(script_name, 1)[-1] path_info = path_info.split(script_name, 1)[-1]
environ = { environ = {
"wsgi.url_scheme": 'http', "wsgi.url_scheme": url_scheme,
"wsgi.input": wsgi_input, "wsgi.input": wsgi_input,
"wsgi.errors": sys.stderr, "wsgi.errors": sys.stderr,
"wsgi.version": (1, 0), "wsgi.version": (1, 0),