#!/bin/bash

function TestGetHeader()
{
	curlHeaderOutputFile="./temp"
	if curl -I $1 --output $curlHeaderOutputFile 2> /dev/null; then
		regexPattern="Content\-Type: $2"
		headerContentType="$(egrep -o "$regexPattern" $curlHeaderOutputFile)"
		if [ -n "$headerContentType" ]; then
			echo "SUCCESS HEAD $1"
		else
			echo "FAILURE HEAD $1 contains bad MIME type (expected <Content-Type: $2>"
		fi

		rm $curlHeaderOutputFile
	else
		echo "FAILURE Cannot HEAD $1"
	fi
}

function TestHEAD()
{
	getUrl="http://localhost:8080/$1"

	TestGetHeader $getUrl $2
	echo ""
}

echo "*********"
echo "HEAD TEST"
echo "*********"
TestHEAD "index.html" 'text/html'
TestHEAD "robedude.png" 'image/png'
TestHEAD "hope.jpg" 'image/jpeg'
TestHEAD "ouroboros-by-kevin-macleod.mp3" 'audio/mpeg3'
TestHEAD "file_example_MP4_480_1_5MG.mp4" 'video/mp4'
TestHEAD "index.css" 'text/css'
TestHEAD "test.js" 'application/javascript'
TestHEAD "subdir/index.html" 'text/html'