Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 81d15e5

Browse files
committed
Fix for an Issue #101
1 parent c96e44b commit 81d15e5

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

lib/core/common.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3050,12 +3050,15 @@ def getHostHeader(url):
30503050
Returns proper Host header value for a given target URL
30513051
"""
30523052

3053-
retVal = urlparse.urlparse(url).netloc
3053+
retVal = url
30543054

3055-
if re.search("http(s)?://\[.+\]", url, re.I):
3056-
retVal = extractRegexResult("http(s)?://\[(?P<result>.+)\]", url)
3057-
elif any(retVal.endswith(':%d' % _) for _ in (80, 443)):
3058-
retVal = retVal.split(':')[0]
3055+
if url:
3056+
retVal = urlparse.urlparse(url).netloc
3057+
3058+
if re.search("http(s)?://\[.+\]", url, re.I):
3059+
retVal = extractRegexResult("http(s)?://\[(?P<result>.+)\]", url)
3060+
elif any(retVal.endswith(':%d' % _) for _ in (80, 443)):
3061+
retVal = retVal.split(':')[0]
30593062

30603063
return retVal
30613064

lib/request/redirecthandler.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ def http_error_302(self, req, fp, code, msg, headers):
7575
content = None
7676
redurl = self._get_header_redirect(headers)
7777

78-
if not urlparse.urlsplit(redurl).netloc:
79-
redurl = urlparse.urljoin(req.get_full_url(), redurl)
78+
if redurl:
79+
if not urlparse.urlsplit(redurl).netloc:
80+
redurl = urlparse.urljoin(req.get_full_url(), redurl)
8081

81-
self._infinite_loop_check(req)
82-
self._ask_redirect_choice(code, redurl)
82+
self._infinite_loop_check(req)
83+
self._ask_redirect_choice(code, redurl)
8384

8485
try:
8586
content = fp.read()
@@ -88,7 +89,7 @@ def http_error_302(self, req, fp, code, msg, headers):
8889
dbgMsg += "redirect response content (%s)" % msg
8990
logger.debug(dbgMsg)
9091

91-
if kb.redirectChoice == REDIRECTION.YES:
92+
if redurl and kb.redirectChoice == REDIRECTION.YES:
9293
req.headers[HTTPHEADER.HOST] = getHostHeader(redurl)
9394
result = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
9495
else:

0 commit comments

Comments
 (0)