Last active
March 24, 2021 02:51
-
-
Save jefftriplett/2b24997e377da787e922288d8925aa34 to your computer and use it in GitHub Desktop.
This is a quick script to check the "CF-Cache-Status" header to see if Cloudflare is serving your content out of cache.
This file contains 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 frontmatter | |
import requests | |
import typer | |
def main(url: str): | |
request = requests.get(url) | |
post = frontmatter.loads("") | |
headers = request.headers | |
post["headers"] = {} | |
for header in headers: | |
post["headers"][header] = headers[header] | |
typer.secho(f"Age: {request.headers.get('Age')}", fg="yellow") | |
typer.secho(f"CF-Cache-Status: {request.headers['CF-Cache-Status']}", fg="yellow") | |
typer.secho(frontmatter.dumps(post), fg="blue") | |
if __name__ == "__main__": | |
typer.run(main) |
This file contains 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
python-frontmatter | |
requests | |
typer |
This file contains 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
# | |
# This file is autogenerated by pip-compile | |
# To update, run: | |
# | |
# pip-compile | |
# | |
certifi==2020.6.20 # via requests | |
chardet==3.0.4 # via requests | |
click==7.1.2 # via typer | |
idna==2.10 # via requests | |
python-frontmatter==0.5.0 # via -r requirements.in | |
pyyaml==5.3.1 # via python-frontmatter | |
requests==2.24.0 # via -r requirements.in | |
six==1.15.0 # via python-frontmatter | |
typer==0.3.1 # via -r requirements.in | |
urllib3==1.25.10 # via requests |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment