From 3d1fa9f0486582ec44cdd71dfdfb2175272e1d3e Mon Sep 17 00:00:00 2001 From: "Langhammer, Jens" Date: Tue, 9 Jul 2019 15:28:52 +0200 Subject: [PATCH] app_gw: Rewrite redirect responses (replace upstream location with server_name) --- passbook/app_gw/proxy/handler.py | 8 ++++++++ passbook/app_gw/proxy/response.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/passbook/app_gw/proxy/handler.py b/passbook/app_gw/proxy/handler.py index 10d405509..ea6b376c4 100644 --- a/passbook/app_gw/proxy/handler.py +++ b/passbook/app_gw/proxy/handler.py @@ -221,5 +221,13 @@ class RequestHandler: self._set_content_type(proxy_response) response = get_django_response(proxy_response, strict_cookies=False) + # If response has a 'Location' header, we rewrite that location as well + if 'Location' in response: + LOGGER.debug("Rewriting Location header") + for server_name in self.app_gw.server_name: + response['Location'] = response['Location'].replace( + self._parsed_url.hostname, server_name) + LOGGER.debug(response['Location']) + # LOGGER.debug("RESPONSE RETURNED: %s", response) return response diff --git a/passbook/app_gw/proxy/response.py b/passbook/app_gw/proxy/response.py index 426533a5a..3984953bc 100644 --- a/passbook/app_gw/proxy/response.py +++ b/passbook/app_gw/proxy/response.py @@ -9,7 +9,7 @@ from passbook.app_gw.proxy.utils import (cookie_from_string, #: Default number of bytes that are going to be read in a file lecture DEFAULT_AMT = 2 ** 16 -logger = logging.getLogger('revproxy.response') +logger = logging.getLogger(__name__) def get_django_response(proxy_response, strict_cookies=False):