Skip to content

Instantly share code, notes, and snippets.

@thsutton
Created November 4, 2011 03:47
Show Gist options
  • Save thsutton/1338619 to your computer and use it in GitHub Desktop.
Save thsutton/1338619 to your computer and use it in GitHub Desktop.
Check that MIME type header and file content match
#!/bin/sh
#
# Check that the MIME type sent be a web server and the type of data in the file match.
#
# Usage: mimetypecheck.sh http://example.com/ http://example.org/
CURL="curl --silent"
for URL in $*; do
PATT=$(mktemp -t typecheck)
HEAD="${PATT}.head"
BODY="${PATT}.body"
$CURL "$URL" --dump-header "$HEAD" -o "$BODY"
ASSERT=$(grep -i content-type "$HEAD" | cut -d: -f2 | cut -d\; -f1 | tr -d " ")
ACTUAL=$(file -bI "$BODY" | cut -d\; -f1 | tr -d " ")
echo "$URL"
echo "Sent: ${ASSERT}"
echo "Real: ${ACTUAL}"
echo
rm -f "$PATT" "${PATT}.head" "${PATT}.body"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment