@@ -175,8 +175,6 @@ class HTTPFetcher(object):
175175 """Fetches HTTP(S) pages via PyCURL. CA certificates can be configured.
176176 """
177177
178- _headerRe = regex .compile (r"(?P<name>\S+?): (?P<value>.*?)\r\n" )
179-
180178 def __init__ (self , platform , certPlatforms , fetchOptions , ruleTrie = None ):
181179 """Create fetcher that validates certificates using selected
182180 platform.
@@ -379,14 +377,12 @@ def fetchHtml(self, url):
379377 if httpCode == 0 :
380378 raise HTTPFetcherError ("Pycurl fetch failed for '%s'" % newUrl )
381379 elif httpCode in (301 , 302 , 303 , 307 ):
382- # Parse out the headers and extract location, case-insensitively.
383- # If there are multiple location headers, pick the last one.
384- headers = dict ()
385- for k , v in self ._headerRe .findall (headerStr ):
386- headers [k .lower ()] = v
387- location = headers .get ('location' )
388- if not location :
389- raise HTTPFetcherError ("Redirect for '%s' missing Location" % newUrl )
380+ location = None
381+ for piece in headerStr .split ('\n ' ):
382+ if piece .lower ().startswith ('location:' ):
383+ location = piece [len ('location:' ):].strip ()
384+ if location is None :
385+ raise HTTPFetcherError ("Redirect for '%s' missing location header" % newUrl )
390386
391387 location = self .absolutizeUrl (newUrl , location )
392388 logging .debug ("Following redirect %s => %s" , newUrl , location )
0 commit comments