improved redirection mechanism

This commit is contained in:
Miroslav Stampar
2011-05-23 23:20:03 +00:00
parent 128a012121
commit a536bf210f
3 changed files with 19 additions and 23 deletions

View File

@@ -8,6 +8,7 @@ See the file 'doc/COPYING' for copying permission
"""
import urllib2
import urlparse
from lib.core.data import conf
from lib.core.data import logger
@@ -52,6 +53,10 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
elif "uri" in headers:
result.redurl = headers.getheaders("uri")[0].split("?")[0]
if hasattr(result, 'redurl'):
if result.redurl.startswith('.') or result.redurl.startswith('/'):
result.redurl = urlparse.urljoin(conf.url, result.redurl)
if "set-cookie" in headers:
result.setcookie = headers["set-cookie"].split("; path")[0]