From 9bb682040276d4301a7530889bf3025e58b06903 Mon Sep 17 00:00:00 2001 From: Johannes 'fish' Ziemke Date: Fri, 22 Mar 2013 12:03:31 +0100 Subject: [PATCH] Use filename based type if DetectContentType fails. DetectContentType returns text/plain for our stylesheets and javascripts. That causes chrome to ignore those files. --- web/blob/blob.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/web/blob/blob.go b/web/blob/blob.go index 5d9e4c135..6144bb5a5 100644 --- a/web/blob/blob.go +++ b/web/blob/blob.go @@ -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) }