@@ -149,6 +149,7 @@ def httpraw(self, raw: str, **kwargs):
149149 proxy = kwargs .get ("proxy" , None )
150150 real_host = kwargs .get ("real_host" , None )
151151 ssl = kwargs .get ("ssl" , False )
152+ location = kwargs .get ("location" , True )
152153
153154 scheme = 'http'
154155 port = 80
@@ -245,6 +246,13 @@ def httpraw(self, raw: str, **kwargs):
245246 _url = "{scheme}://{host}{path}" .format (scheme = scheme , host = host , path = path )
246247 else :
247248 _url = "{scheme}://{host}{path}" .format (scheme = scheme , host = host + ":" + port , path = path )
249+
250+ redirect = rep .msg .get ('location' , None ) # handle 301/302
251+ if redirect and location :
252+ if not redirect .startswith ('http' ):
253+ redirect = parse .urljoin (_url , redirect )
254+ return self .http (redirect , post = None , method = method , headers = headers , location = True , locationcount = 1 )
255+
248256 return response (rep , _url , log , )
249257
250258 def http (self , url , ** kwargs ):
@@ -368,7 +376,7 @@ def __init__(self, rep, redirect, log, oldcookie=''):
368376 self .cookies = {}
369377
370378 self .headers = _header_dict
371- self .header = self .rep .msg # response header
379+ self .header = str ( self .rep .msg ) # response header
372380 self .log = log
373381 charset = self .rep .msg .get ('content-type' , 'utf-8' )
374382 try :
0 commit comments