Skip to content

Commit

Permalink
Set Content-Type on static files.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarmol committed Jun 10, 2015
1 parent c2f6049 commit 04293b1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pages/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ package static

import (
"fmt"
"mime"
"net/http"
"net/url"
"path"
)

const StaticResource = "/static/"
Expand All @@ -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
}

0 comments on commit 04293b1

Please sign in to comment.