def warn_if_redirected(req, ui):
    """
    test whether a request was redirect.
    Log a warning to the user if it was redirected
    """
    if req is None:
        return
    history = req.history
    if history:
        first = history[0]
        if first.is_redirect:
            starting_endpoint = first.url
            redirect_endpoint = first.headers.get('Location')
            if str(starting_endpoint) != str(redirect_endpoint):
                ui.warning(
                    'The requested URL:\n\t{}\n\twas redirected by the webserver to:\n\t{}'
                    .format(starting_endpoint, redirect_endpoint))
