Skip to content

Instantly share code, notes, and snippets.

@edmondscommerce
Created September 6, 2018 10:45
Show Gist options
  • Select an option

  • Save edmondscommerce/e2259748b084b7668d136458ce84dc6c to your computer and use it in GitHub Desktop.

Select an option

Save edmondscommerce/e2259748b084b7668d136458ce84dc6c to your computer and use it in GitHub Desktop.

Revisions

  1. edmondscommerce created this gist Sep 6, 2018.
    28 changes: 28 additions & 0 deletions is_cloudflare_caching.bash
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/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