mirror of
https://github.com/donl/gPanel.git
synced 2026-06-30 06:12:06 -06:00
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:
commit
21275c8606
1 changed files with 3 additions and 5 deletions
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue