From 3231f3356bf8cc91d991e9da0e262276f2e470bd Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 12 Jul 2021 09:59:58 +0100 Subject: [PATCH] Error handling for redirect location --- daemon.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/daemon.py b/daemon.py index d0713e567..c0041c4be 100644 --- a/daemon.py +++ b/daemon.py @@ -731,7 +731,23 @@ class PubServer(BaseHTTPRequestHandler): self.send_header('Cookie', cookieStr) else: self.send_header('Set-Cookie', cookieStr) - self.send_header('Location', redirect) + + if '://' in redirect: + fallbackLocation = redirect.split('://')[1] + if '/' in fallbackLocation: + fallbackLocation = fallbackLocation.split('/')[0] + fallbackLocation = \ + redirect.split('://')[0] + '://' + fallbackLocation + else: + fallbackLocation = \ + self.server.httpPrefix + '://' + self.server.domainFull + try: + self.send_header('Location', redirect) + except BaseException: + print('WARN: fallback redirect for ' + str(redirect)) + self.send_header('Location', fallbackLocation) + pass + self.send_header('Host', callingDomain) self.send_header('InstanceID', self.server.instanceId) self.send_header('Content-Length', '0')