Skip to content

Instantly share code, notes, and snippets.

@robatwilliams
Created December 19, 2017 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robatwilliams/9c3eb6c0d641571f489d3f4249df5061 to your computer and use it in GitHub Desktop.
Save robatwilliams/9c3eb6c0d641571f489d3f4249df5061 to your computer and use it in GitHub Desktop.
Check expected & unexpected HTTP headers
HTTP/1.1 200 OK
Content-Encoding: gzip
#!/bin/bash
headers="$(curl -sS -IX GET -H "Accept-Encoding: gzip" www.bbc.com)"
# should not find any unmatched patterns
missingExpected="$(grep -oxFf expected.txt <<< $headers | grep -vxFf - expected.txt)"
expected=$?
# should not find any matched patterns
presentUnexpected="$(grep -oxFf unexpected.txt <<< $headers)"
unexpected=$?
[ "$expected" -eq 0 ] && echo -e "*** Missing expected: ***\n$missingExpected"
[ "$unexpected" -eq 0 ] && echo -e "*** Present unexpected: ***\n$presentUnexpected"
exit $((2 - $expected - $unexpected))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment