From 3d39c6cb3b27e8b9c8814585050aaf253346e541 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Thu, 15 Mar 2012 12:14:50 +0000 Subject: [PATCH] some fixes here and there --- lib/request/redirecthandler.py | 46 ++++++++-------------------------- 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/lib/request/redirecthandler.py b/lib/request/redirecthandler.py index aa03534e4..8b1932605 100644 --- a/lib/request/redirecthandler.py +++ b/lib/request/redirecthandler.py @@ -48,7 +48,7 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler): kb.redirectChoice = choice - def _process_http_redirect(self, result, headers, code, content, msg): + def _process_http_redirect(self, result, headers, code, content, msg, redurl): content = decodePage(content, headers.get(HTTPHEADER.CONTENT_ENCODING), headers.get(HTTPHEADER.CONTENT_TYPE)) threadData = getCurrentThreadData() @@ -68,47 +68,21 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler): logger.log(7, responseMsg) - if self._get_header_redirect(headers): - result.redurl = self._get_header_redirect(headers) - - if not urlparse.urlsplit(result.redurl).netloc: - result.redurl = urlparse.urljoin(conf.url, result.redurl) - if "set-cookie" in headers: kb.redirectSetCookie = headers["set-cookie"].split("; path")[0] result.redcode = code + result.redurl = redurl return result - def http_error_301(self, req, fp, code, msg, headers): - content = None, None - redurl = self._get_header_redirect(headers) - - self._infinite_loop_check(req) - self._ask_redirect_choice(code, redurl) - - try: - content = fp.read() - except Exception, msg: - dbgMsg = "there was a problem while retrieving " - dbgMsg += "redirect response content (%s)" % msg - logger.debug(dbgMsg) - - if redurl: - req.headers[HTTPHEADER.HOST] = getHostHeader(redurl) - - if kb.redirectChoice == REDIRECTION.FOLLOW: - result = urllib2.HTTPRedirectHandler.http_error_301(self, req, fp, code, msg, headers) - else: - result = fp - - return self._process_http_redirect(result, headers, code, content, msg) - def http_error_302(self, req, fp, code, msg, headers): - content = None, None + content = None redurl = self._get_header_redirect(headers) + if not urlparse.urlsplit(redurl).netloc: + redurl = urlparse.urljoin(conf.url, redurl) + self._infinite_loop_check(req) self._ask_redirect_choice(code, redurl) @@ -119,15 +93,15 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler): dbgMsg += "redirect response content (%s)" % msg logger.debug(dbgMsg) - if redurl: - req.headers[HTTPHEADER.HOST] = getHostHeader(redurl) - if kb.redirectChoice == REDIRECTION.FOLLOW: + req.headers[HTTPHEADER.HOST] = getHostHeader(redurl) result = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers) else: result = fp - return self._process_http_redirect(result, headers, code, content, msg) + return self._process_http_redirect(result, headers, code, content, msg, redurl) + + http_error_301 = http_error_303 = http_error_307 = http_error_302 def _infinite_loop_check(self, req): if hasattr(req, 'redirect_dict') and (req.redirect_dict.get(req.get_full_url(), 0) >= MAX_SINGLE_URL_REDIRECTIONS or len(req.redirect_dict) >= MAX_TOTAL_REDIRECTIONS):