From 24dbda8f4106e84a7ad14c21cbf9437cf5052ae9 Mon Sep 17 00:00:00 2001 From: Ryan Kelly Date: Fri, 6 Feb 2015 14:45:44 +1100 Subject: [PATCH] Forcibly update host_port if it seems wrong in the environ --- syncserver/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/syncserver/__init__.py b/syncserver/__init__.py index eb90f6a..170cd4a 100644 --- a/syncserver/__init__.py +++ b/syncserver/__init__.py @@ -117,6 +117,14 @@ def reconcile_wsgi_environ_with_public_url(event): # is serving us at some sub-path. if not request.script_name: request.script_name = p_public_url.path.rstrip("/") + # If the public_url claims we're on a non-standard port but the environ + # says we're on a standard port, assume the public_url is correct. + # This is often the case with e.g. apache mod_wsgi. + if p_public_url.port not in (None, 80, 443): + port_str = str(p_public_url.port) + if request.host_port != port_str: + if request.host_port in (None, "80", "443"): + request.host = p_public_url.netloc # Log a noisy error if the application url is different to what we'd # expect based on public_url setting. application_url = request.application_url