Skip to content

Instantly share code, notes, and snippets.

@edmondscommerce
Created September 6, 2018 10:45
Show Gist options
  • Save edmondscommerce/e2259748b084b7668d136458ce84dc6c to your computer and use it in GitHub Desktop.
Save edmondscommerce/e2259748b084b7668d136458ce84dc6c to your computer and use it in GitHub Desktop.
Quickly test if Cloudflare is caching a resource
#!/usr/bin/env bash
readonly DIR=$(dirname $(readlink -f "$0"))
cd $DIR;
set -e
set -u
set -o pipefail
standardIFS="$IFS"
IFS=$'\n\t'
usage() {
echo "Usage: $0 [URL to test]";
}
if (( $# != 1 )); then
usage;
exit 1;
fi
readonly url=$1;
readonly result=$(curl -I --silent --stderr - "${url}" | grep 'cf-cache-status: HIT');
if [[ -z "${result}" ]]; then
echo "Not cached by Cloudflare";
else
echo "Cached by Cloudflare";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment