'Test whether webserver redirects to secure connection.'

def redirect(self, name, port=80, headers=None):

    url = 'http://{0}:{1}'.format(name, port)
    if headers:
        response = requests.get(url, headers=headers, allow_redirects=False)
    else:
        response = requests.get(url, allow_redirects=False)
    redirect_location = response.headers.get('location', '')
    if (not redirect_location.startswith('https://')):
        return False
    if (response.status_code != 301):
        logger.error('Server    did    not    redirect    with    permanent    code')
        return False
    return True
