Skip to content

Commit

Permalink
Merge pull request #9 from danielwhite/fix-content-types
Browse files Browse the repository at this point in the history
Fix generation of content types
  • Loading branch information
ian-kent committed Oct 6, 2015
2 parents bc6dbdc + 896b571 commit d78b1cc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"mime"
"net/http"
"path/filepath"
"strings"

"github.com/gorilla/pat"
Expand Down Expand Up @@ -38,7 +39,9 @@ func (web Web) Static(pattern string) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, req *http.Request) {
fp := strings.TrimSuffix(pattern, "{{file}}") + req.URL.Query().Get(":file")
if b, err := web.asset(fp); err == nil {
w.Header().Set("Content-Type", mime.TypeByExtension(fp))
ext := filepath.Ext(fp)

w.Header().Set("Content-Type", mime.TypeByExtension(ext))
w.WriteHeader(200)
w.Write(b)
return
Expand Down Expand Up @@ -102,6 +105,7 @@ func (web Web) Index() func(http.ResponseWriter, *http.Request) {
return
}

w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(200)
w.Write(b.Bytes())
}
Expand Down

0 comments on commit d78b1cc

Please sign in to comment.