'Handle sslstrip for HTTP redirects.
This does SSLstrip on the Location header.'

def replace_redirect(self, response):

    resp = util.http.parse_response(response)
    headers = dict(resp.getheaders())
    location = headers['location']
    callback = self.build_report_callback(location)
    new_location = ('http://' + location[8:])
    new_location = ClientReportDetection.add_callback_url(callback, new_location, timeout=5)
    headers['location'] = new_location
    self.log(logging.DEBUG, ('Replacing    redirect    to    %s    with    %s' % (location, new_location)))
    version = ('HTTP/1.0' if (resp.version == 10) else 'HTTP/1.1')
    message = (('{version}    {status}    OK\r\n' + '\r\n'.join([('%s:    %s' % (k, v)) for (k, v) in headers.items()])) + '\r\n\r\n')
    data = message.format(version=version, status=resp.status)
    total_consumed = ((response.index('\r\n\r\n') + 4) + int(headers.get('content-length', 0)))
    if (total_consumed < len(response)):
        data += response[total_consumed:]
    return data
