From 04293b1595a3d2fd62491cf79d1d00148678fac8 Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Tue, 9 Jun 2015 18:34:04 -0700 Subject: [PATCH] Set Content-Type on static files. Fixes #763 --- pages/static/static.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pages/static/static.go b/pages/static/static.go index 96f2513a..a942e0e1 100644 --- a/pages/static/static.go +++ b/pages/static/static.go @@ -18,8 +18,10 @@ package static import ( "fmt" + "mime" "net/http" "net/url" + "path" ) const StaticResource = "/static/" @@ -46,6 +48,12 @@ func HandleRequest(w http.ResponseWriter, u *url.URL) error { return fmt.Errorf("unknown static resource %q", resource) } + // Set Content-Type if we were able to detect it. + contentType := mime.TypeByExtension(path.Ext(resource)) + if contentType != "" { + w.Header().Set("Content-Type", contentType) + } + _, err := w.Write([]byte(content)) return err }