Skip to content

Commit

Permalink
Fix urlcheck github actions
Browse files Browse the repository at this point in the history
Fix URL checker to flag redirects to custom 404 page
  • Loading branch information
cordt-sei authored Oct 15, 2024
1 parent 774b7b9 commit 18fcbd1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions scripts/urlcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
def check_url_status(url):
try:
response = requests.head(url, allow_redirects=True, timeout=5)
return response.status_code, response.reason, response.url
final_url = response.url # Get the final URL after redirects
return response.status_code, response.reason, final_url
except requests.RequestException as e:
return None, str(e), None

Expand All @@ -36,7 +37,8 @@ def process_file(file_path):
for url in urls:
if is_valid_url(url):
status_code, reason, final_url = check_url_status(url)
if status_code and status_code not in {200, 403, 415, 501} and final_url != INTERNAL_404_URL:
# Flag the URL if status code is bad OR if it redirects to the 404 page
if (status_code and status_code not in {200, 403, 415, 501}) or final_url == INTERNAL_404_URL:
file_report.append({
'file': file_path,
'line': line_number,
Expand Down

0 comments on commit 18fcbd1

Please sign in to comment.