From 81d15e50515a5763e37d03f71ca13233720984b2 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Tue, 17 Jul 2012 00:19:33 +0200 Subject: [PATCH] Fix for an Issue #101 --- lib/core/common.py | 13 ++++++++----- lib/request/redirecthandler.py | 11 ++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 8b04ea96f..a1766fb30 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -3050,12 +3050,15 @@ def getHostHeader(url): Returns proper Host header value for a given target URL """ - retVal = urlparse.urlparse(url).netloc + retVal = url - if re.search("http(s)?://\[.+\]", url, re.I): - retVal = extractRegexResult("http(s)?://\[(?P.+)\]", url) - elif any(retVal.endswith(':%d' % _) for _ in (80, 443)): - retVal = retVal.split(':')[0] + if url: + retVal = urlparse.urlparse(url).netloc + + if re.search("http(s)?://\[.+\]", url, re.I): + retVal = extractRegexResult("http(s)?://\[(?P.+)\]", url) + elif any(retVal.endswith(':%d' % _) for _ in (80, 443)): + retVal = retVal.split(':')[0] return retVal diff --git a/lib/request/redirecthandler.py b/lib/request/redirecthandler.py index 66eeb87a4..7062a9724 100644 --- a/lib/request/redirecthandler.py +++ b/lib/request/redirecthandler.py @@ -75,11 +75,12 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler): content = None redurl = self._get_header_redirect(headers) - if not urlparse.urlsplit(redurl).netloc: - redurl = urlparse.urljoin(req.get_full_url(), redurl) + if redurl: + if not urlparse.urlsplit(redurl).netloc: + redurl = urlparse.urljoin(req.get_full_url(), redurl) - self._infinite_loop_check(req) - self._ask_redirect_choice(code, redurl) + self._infinite_loop_check(req) + self._ask_redirect_choice(code, redurl) try: content = fp.read() @@ -88,7 +89,7 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler): dbgMsg += "redirect response content (%s)" % msg logger.debug(dbgMsg) - if kb.redirectChoice == REDIRECTION.YES: + if redurl and kb.redirectChoice == REDIRECTION.YES: req.headers[HTTPHEADER.HOST] = getHostHeader(redurl) result = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers) else: