Skip to content

Commit

Permalink
Merge pull request #9 from fabriziosalmi/codeflash/optimize-check_hst…
Browse files Browse the repository at this point in the history
…s-m6y4ryng

⚡️ Speed up function `check_hsts` by 9%
  • Loading branch information
fabriziosalmi authored Feb 10, 2025
2 parents fec974b + f085bbf commit dc4f324
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions checks/check_hsts.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,8 @@ def check_hsts(website: str) -> str:
response.raise_for_status() # Raise an exception for HTTP errors

# Check if the 'Strict-Transport-Security' header is present
if 'Strict-Transport-Security' in response.headers:
print(f"HSTS is enabled for {website}.")
return "🟢"
else:
print(f"HSTS is not enabled for {website}.")
return "🔴"

except (Timeout, HTTPError) as e:
print(f"Timeout or HTTP error occurred while checking HSTS for {website}: {e}")
return "⚪"
except RequestException as e:
print(f"Request-related error occurred while checking HSTS for {website}: {e}")
return "⚪"
except Exception as e:
print(f"An unexpected error occurred while checking HSTS for {website}: {e}")
return "🟢" if 'Strict-Transport-Security' in response.headers else "🔴"

except (requests.RequestException, Exception) as e:
print(f"An error occurred while checking HSTS for {website}: {e}")
return "⚪"

0 comments on commit dc4f324

Please sign in to comment.