'Fetch HTML from given http/https URL. Return codes 301, 302,
303, 307, and 308 are followed, URLs rewritten using HTTPS
Everywhere rules.
@param url: string URL of http(s) resource
@returns: tuple (httpResponseCode, htmlData)
@throws pycurl.error: on failed fetch
@throws HTTPFetcherError: on failed fetch/redirection'

def fetchHtml(self, url):

    newUrl = url
    newUrlPlatformPath = self.platformPath
    seenUrls = set()
    options = self.options
    for depth in range(options.redirectDepth):
        newUrl = self.idnEncodedUrl(newUrl)
        seenUrls.add(newUrl)
        if options.staticCAPath:
            newUrlPlatformPath = options.staticCAPath
        fetched = HTTPFetcher._doFetch(newUrl, options, newUrlPlatformPath)
        httpCode = fetched.httpCode
        bufValue = fetched.data
        headerStr = fetched.headerStr
        if (httpCode == 0):
            raise HTTPFetcherError(("Pycurl    fetch    failed    for    '%s'" % newUrl))
        elif (httpCode in (301, 302, 303, 307, 308)):
            location = None
            for piece in headerStr.split('\n'):
                if piece.lower().startswith('location:'):
                    location = piece[len('location:'):].strip()
            if (location is None):
                raise HTTPFetcherError(("Redirect    for    '%s'    missing    location    header" % newUrl))
            location = self.absolutizeUrl(newUrl, location)
            logging.debug('Following    redirect    %s    =>    %s', newUrl, location)
            if self.ruleTrie:
                ruleMatch = self.ruleTrie.transformUrl(location)
                newUrl = ruleMatch.url
                if ruleMatch.ruleset:
                    newUrlPlatformPath = self.certPlatforms.getCAPath(ruleMatch.ruleset.platform)
                else:
                    newUrlPlatformPath = self.platformPath
                if (newUrl != location):
                    logging.debug('Redirect    rewritten:    %s    =>    %s', location, newUrl)
            else:
                newUrl = location
            continue
        return (httpCode, bufValue)
    raise HTTPFetcherError(("Too    many    redirects    while    fetching    '%s'" % url))
