--- urllib2.py 2010-04-16 16:58:00.000000000 +0300 +++ urllib2_new.py 2010-12-10 13:16:21.000000000 +0200 @@ -525,7 +525,7 @@ # assuming we're in a loop max_redirections = 10 - def redirect_request(self, req, fp, code, msg, headers, newurl): + def redirect_request(self, req, fp, code, msg, headers, newurl, newhost): """Return a Request or None in response to a redirect. This is called by the http_error_30x methods when a @@ -548,6 +548,7 @@ newheaders = dict((k,v) for k,v in req.headers.items() if k.lower() not in ("content-length", "content-type") ) + newheaders.update({"Host": newhost}) return Request(newurl, headers=newheaders, origin_req_host=req.get_origin_req_host(), @@ -571,6 +572,7 @@ # fix a possible malformed URL urlparts = urlparse.urlparse(newurl) + newhost = urlparts[1] if not urlparts.path: urlparts = list(urlparts) urlparts[2] = "/" @@ -581,7 +583,7 @@ # XXX Probably want to forget about the state of the current # request, although that might interact poorly with other # handlers that also use handler-specific request attributes - new = self.redirect_request(req, fp, code, msg, headers, newurl) + new = self.redirect_request(req, fp, code, msg, headers, newurl, newhost) if new is None: return @@ -610,7 +612,6 @@ "lead to an infinite loop.\n" \ "The last 30x error message was:\n" - def _parse_proxy(proxy): """Return (scheme, user, password, host/port) given a URL or an authority.