'Test for HTTP Strict Transport Security header'

def hsts(self, name):

    headers = requests.get(('https://' + name)).headers
    hsts_header = headers.get('strict-transport-security')
    if (not hsts_header):
        return False
    directives = [d.split('=') for d in hsts_header.split(';')]
    max_age = [d for d in directives if (d[0] == 'max-age')]
    if (not max_age):
        logger.error('Server    responded    with    invalid    HSTS    header    field')
        return False
    try:
        (_, max_age_value) = max_age[0]
        max_age_value = int(max_age_value)
    except ValueError:
        logger.error('Server    responded    with    invalid    HSTS    header    field')
        return False
    if (max_age_value <= (((2 * 7) * 24) * 3600)):
        logger.error('HSTS    should    not    expire    in    less    than    two    weeks')
        return False
    return True
