Added backward compatible code for reverse proxy in case werkzeug is older.

Make werkzeug greater than equal to 0.15.0
This commit is contained in:
Aditya Toshniwal 2019-10-01 17:55:43 +05:30 committed by Akshay Joshi
parent 6c662ae672
commit 245a6e6f57
2 changed files with 12 additions and 8 deletions

View File

@ -16,6 +16,7 @@
##############################################################################
blinker==1.4
Flask==1.0.2
Werkzeug>=0.15.0
Flask-Gravatar==0.5.0
Flask-Login==0.4.1
Flask-Mail==0.9.1

View File

@ -13,7 +13,6 @@ to start a web server."""
import os
import sys
from werkzeug.middleware.proxy_fix import ProxyFix
if sys.version_info[0] >= 3:
import builtins
@ -71,13 +70,17 @@ if not os.path.isfile(config.SQLITE_PATH):
class ReverseProxied(object):
def __init__(self, app):
# https://werkzeug.palletsprojects.com/en/0.15.x/middleware/proxy_fix/#module-werkzeug.middleware.proxy_fix
self.app = ProxyFix(app,
x_for=config.PROXY_X_FOR_COUNT,
x_proto=config.PROXY_X_PROTO_COUNT,
x_host=config.PROXY_X_HOST_COUNT,
x_port=config.PROXY_X_PORT_COUNT,
x_prefix=config.PROXY_X_PREFIX_COUNT
)
try:
from werkzeug.middleware.proxy_fix import ProxyFix
self.app = ProxyFix(app,
x_for=config.PROXY_X_FOR_COUNT,
x_proto=config.PROXY_X_PROTO_COUNT,
x_host=config.PROXY_X_HOST_COUNT,
x_port=config.PROXY_X_PORT_COUNT,
x_prefix=config.PROXY_X_PREFIX_COUNT
)
except ImportError:
pass
def __call__(self, environ, start_response):
script_name = environ.get("HTTP_X_SCRIPT_NAME", "")