Error handling for redirect location

main
Bob Mottram 2021-07-12 09:59:58 +01:00
parent 4a0dd19475
commit 3231f3356b
1 changed files with 17 additions and 1 deletions

View File

@ -731,7 +731,23 @@ class PubServer(BaseHTTPRequestHandler):
self.send_header('Cookie', cookieStr) self.send_header('Cookie', cookieStr)
else: else:
self.send_header('Set-Cookie', cookieStr) 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('Host', callingDomain)
self.send_header('InstanceID', self.server.instanceId) self.send_header('InstanceID', self.server.instanceId)
self.send_header('Content-Length', '0') self.send_header('Content-Length', '0')