diff --git a/workbench_utils.py b/workbench_utils.py index 20b690b..534fc01 100644 --- a/workbench_utils.py +++ b/workbench_utils.py @@ -3098,7 +3098,7 @@ def check_input(config, args): for count, row in enumerate(check_for_redirects_csv_data, start=1): if row["redirect_source"].lower().startswith("http"): message = ( - 'Redirect source values cannot contain a hostname, they must be a path only. Please correct "' + 'Redirect source values cannot contain a hostname, they must be a path only, without a hostname. Please correct "' + row["redirect_source"] + " (row " + str(count) @@ -3108,7 +3108,32 @@ def check_input(config, args): warnings_about_redirect_input_csv = True continue - # Log if source path doesn't exist. We don't use issue_request() since we + # Check to see if the redirect source value is already a redirect. We don't use issue_request() + # since we don't want to override config["allow_redirects"] for this one request. + is_redirect_url = config["host"].rstrip("/") + "/" + row["redirect_source"] + is_redirect_response = requests.head( + is_redirect_url, + allow_redirects=False, + verify=config["secure_ssl_only"], + auth=(config["username"], config["password"]), + ) + if str(is_redirect_response.status_code).startswith("30"): + message = ( + 'Redirect source path "' + + row["redirect_source"].strip() + + '" (row ' + + str(count) + + ') is already a redirect to "' + + is_redirect_response.headers["Location"] + + '" (HTTP response code is ' + + str(is_redirect_response.status_code) + + ")." + ) + logging.warning(message) + warnings_about_redirect_input_csv = True + continue + + # Log whether the source path exists. We don't use issue_request() since we # don't want to override config["allow_redirects"] for this one request. path_exists_url = config["host"].rstrip("/") + "/" + row["redirect_source"] path_exists_response = requests.head( @@ -3125,33 +3150,23 @@ def check_input(config, args): + str(count) + ") does not exist (HTTP response code is " + str(path_exists_response.status_code) - + "). This may be intentional." + + ")." ) logging.warning(message) warnings_about_redirect_input_csv = True continue - - # Check to see if the redirect source value is already a redirect. We don't use issue_request() - # since we don't want to override config["allow_redirects"] for this one request. - is_redirect_url = config["host"].rstrip("/") + "/" + row["redirect_source"] - is_redirect_response = requests.head( - is_redirect_url, - allow_redirects=False, - verify=config["secure_ssl_only"], - auth=(config["username"], config["password"]), - ) - if str(is_redirect_response.status_code).startswith("30"): + else: + # We've already tested for 3xx responses, so assume that the path exists. message = ( - 'Redirect from "' + 'Redirect source path "' + row["redirect_source"].strip() + '" (row ' + str(count) - + ") is already a redirect (HTTP response code is " - + str(is_redirect_response.status_code) - + ")." + + ") already exists." ) logging.warning(message) warnings_about_redirect_input_csv = True + continue if warnings_about_redirect_input_csv is True: message = (