Skip to content

Instantly share code, notes, and snippets.

@asvinours
Last active April 14, 2017 15:24
Show Gist options
  • Save asvinours/1a1f52b38b7d5b5113d2f0e06da9880d to your computer and use it in GitHub Desktop.
Save asvinours/1a1f52b38b7d5b5113d2f0e06da9880d to your computer and use it in GitHub Desktop.
Test for static gzip and brotli pre-compressed files
#!/usr/bin/env bash
LIST_URLS=("/foo.bar");
HOSTS=("example.com");
PROTOCOLS=("http" "https");
for PROTOCOL in ${PROTOCOLS[@]:0};
do
for HOST in ${HOSTS[@]:0};
do
for URL in ${LIST_URLS[@]:0};
do
# GZIP
REGULAR=$(curl --silent --write-out '%{http_code};%{size_download}' --output /dev/null "$PROTOCOL://$HOST$URL");
REG_INFO=(${REGULAR//;/ });
REG_STATUS_CODE=${REG_INFO[0]};
REG_SIZE=${REG_INFO[1]};
if [[ $REG_STATUS_CODE != "200" ]];
then
echo "$PROTOCOL://$HOST$URL does not return a 200";
continue;
fi
GZ_FILE=$(curl --silent --write-out '%{http_code};%{size_download}' --output /dev/null "$PROTOCOL://$HOST$URL.gz");
GZ_INFO=(${GZ_FILE//;/ });
GZ_STATUS_CODE=${GZ_INFO[0]};
GZ_SIZE=${GZ_INFO[1]};
GZ_REQUESTED=$(curl --silent --write-out '%{size_download}' -H "Accept-Encoding: gzip,deflate" --output /dev/null "$PROTOCOL://$HOST$URL");
if [[ $GZ_STATUS_CODE == "200" ]];
then
if [ $GZ_REQUESTED -gt $GZ_SIZE ];
then
echo "There is a gz file on disk for $PROTOCOL://$HOST$URL but it is not served when requested";
else
echo "$PROTOCOL://$HOST$URL is OK";
echo "Good job Reg file: $REG_SIZE - Gz file: $GZ_SIZE";
fi;
else
echo "No gz file on disk for $PROTOCOL://$HOST$URL";
fi;
# BROTLI
BR_FILE=$(curl --silent --write-out '%{http_code};%{size_download}' --output /dev/null "$PROTOCOL://$HOST$URL.br");
BR_INFO=(${BR_FILE//;/ });
BR_STATUS_CODE=${BR_INFO[0]};
BR_SIZE=${BR_INFO[1]};
BR_REQUESTED=$(curl --silent --write-out '%{size_download}' -H "Accept-Encoding: br,gzip,deflate" --output /dev/null "$PROTOCOL://$HOST$URL");
if [[ $BR_STATUS_CODE == "200" ]];
then
if [ $BR_REQUESTED -gt $BR_SIZE ];
then
echo "There is a brotli file on disk for $PROTOCOL://$HOST$URL but it is not served when requested";
else
echo "$PROTOCOL://$HOST$URL is OK";
echo "Good job Reg file: $REG_SIZE - Brotli file: $BR_SIZE";
fi;
else
echo "No br file on disk for $PROTOCOL://$HOST$URL";
fi;
done;
done;
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment