Merge pull request #18 from justyntemme/master

Use filepath/Ext in case a user decides to name a file with multiple .
This commit is contained in:
George Shaw 2017-10-23 14:21:59 -05:00 committed by GitHub
commit 21275c8606

View file

@ -3,7 +3,7 @@ package routing
import (
"errors"
"strings"
"path/filepath"
)
// getContentType returns the http header safe content-type attribute for the
@ -13,14 +13,12 @@ import (
// BUG(george-e-shaw-iv) Does not cover the bulk of encountered content types on the web
func GetContentType(path string) (string, error) {
var contentType string
splitPath := strings.Split(path, ".")
fileType := filepath.Ext(path)
if len(splitPath) == 1 && splitPath[0] == path {
if fileType == "" {
return contentType, errors.New("Invalid path, contained no period-separated content-type")
}
fileType := splitPath[len(splitPath)-1]
switch fileType {
case "html":
contentType = "text/html"