From 5055dad156db126036f5456bdb5800fca2782403 Mon Sep 17 00:00:00 2001 From: Justyn Temme Date: Sat, 21 Oct 2017 21:54:24 -0500 Subject: [PATCH] Use filepath/Ext in case a user decides to name a file with multiple . --- general/routing/contentTypes.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/general/routing/contentTypes.go b/general/routing/contentTypes.go index 4b8db09..ec72284 100644 --- a/general/routing/contentTypes.go +++ b/general/routing/contentTypes.go @@ -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"