Use filename based type if DetectContentType fails.

DetectContentType returns text/plain for our stylesheets and javascripts. That causes chrome to ignore those files.
pull/92/merge
Johannes 'fish' Ziemke 12 years ago
parent a33d2726bc
commit 9bb6820402

@ -6,6 +6,7 @@ import (
"io"
"log"
"net/http"
"strings"
)
const (
@ -13,6 +14,11 @@ const (
StaticFiles = "static"
)
var mimeMap = map[string]string{
"css": "text/css",
"js": "text/javascript",
}
func GetFile(bucket string, name string) ([]byte, error) {
reader := bytes.NewReader(files[bucket][name])
gz, err := gzip.NewReader(reader)
@ -43,6 +49,11 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
return
}
w.Header().Set("Content-Type", http.DetectContentType(file))
contentType := http.DetectContentType(file)
if strings.Contains(contentType, "text/plain") || strings.Contains(contentType, "application/octet-stream") {
parts := strings.Split(name, ".")
contentType = mimeMap[parts[len(parts)-1]]
}
w.Header().Set("Content-Type", contentType)
w.Write(file)
}

Loading…
Cancel
Save