Created
June 3, 2025 18:30
-
-
Save jlopezr/4d906b70cccf5eed278d56a74af567ab to your computer and use it in GitHub Desktop.
Checks if a URL is served with compression or not.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def check_compression(url): | |
try: | |
# Send a GET request with Accept-Encoding header to test for compression | |
headers = { | |
"Accept-Encoding": "gzip, deflate, br" | |
} | |
response = requests.get(url, headers=headers, timeout=10) | |
# Check the Content-Encoding header in the response | |
content_encoding = response.headers.get("Content-Encoding") | |
if content_encoding: | |
print(f"The URL {url} is served with compression: {content_encoding}") | |
else: | |
print(f"The URL {url} is not served with compression.") | |
except requests.exceptions.RequestException as e: | |
print(f"An error occurred while accessing the URL {url}: {e}") | |
# Example usage | |
if __name__ == "__main__": | |
url_to_check = input("Enter the URL to check: ").strip() | |
check_compression(url_to_check) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment