import requests


def is_reachable(url: str, redirects: bool) -> bool:
    """
    Test if a web site is reachable.

    This test has two different uses in the certmgr container:
      1. Test if the NGINX server is up; and
      2. Test if the device, e.g. the NUC, is connected to the internet.

    Args:
        url: the URL to be tested
        redirects: a boolean value that specifies if redirects are allowed.

    """
    try:
        resp: requests.Response = requests.get(url, allow_redirects=redirects)
    except requests.ConnectionError:
        return False
    else:
        if resp.status_code in (200, 301):
            return True
        return False