From 9f1d217e508685e1761eece68f38456cf5b5506e Mon Sep 17 00:00:00 2001 From: Alok Saldanha Date: Wed, 8 Jan 2020 03:32:06 -0500 Subject: [PATCH] #14 properly use the external protocol in 302 redirects --- cellxgene_gateway/gateway.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cellxgene_gateway/gateway.py b/cellxgene_gateway/gateway.py index 272f7cd..e34e181 100644 --- a/cellxgene_gateway/gateway.py +++ b/cellxgene_gateway/gateway.py @@ -37,6 +37,14 @@ from cellxgene_gateway.util import current_time_stamp from cellxgene_gateway.path_util import get_key app = Flask(__name__) + +def _force_https(app): + def wrapper(environ, start_response): + environ['wsgi.url_scheme'] = env.external_protocol + return app(environ, start_response) + return wrapper +app.wsgi_app = _force_https(app.wsgi_app) + cache = BackendCache() location = f"{env.external_protocol}://{env.external_host}" @@ -151,7 +159,7 @@ def upload_file(): "Invalid directory.", status.HTTP_400_BAD_REQUEST ) - return redirect(env.location, code=302) + return redirect(location, code=302) if env.enable_upload: