use a generic regular expression to fix location header

Closes #6614
This commit is contained in:
Jérôme Schneider 2015-03-09 17:23:29 +01:00
parent d6f82392e0
commit 00ba2176af
2 changed files with 8 additions and 6 deletions

View File

@ -36,12 +36,14 @@ class MandayeFilter(object):
cookie['domain'] = re.sub('^\.*%s$' % (target.hostname),
src_hostname, cookie['domain'])
# Modify headers
if response.headers.has_key('location'):
response.headers.addheader('location',
re.sub(r'http(s*)://%s' % env["target"].hostname,
r"%s://%s" % (env["mandaye.scheme"], env["HTTP_HOST"]),
response.headers.getheader('location'),
flags=re.IGNORECASE)
)
blacklist = ['transfer-encoding', 'content-length']
for key, value in response.headers.iteritems():
if key == 'location':
location = value[0].replace(target.geturl(),
"%s://%s" % (env['mandaye.scheme'], env["HTTP_HOST"]))
response.headers['location'] = [location]
for name in blacklist:
if response.headers.has_key(name):
del response.headers[name]

View File

@ -48,7 +48,7 @@ def _get_traceback():
return tb_str
def _302(location, cookies=None):
headers = HTTPHeader({'Location': [location],
headers = HTTPHeader({'location': [location],
'Content-Type': ['text/html']})
msg = "Reload the page to get source for: %s" % location
logger.info('302 redirect to %s' % location)