Merge pull request #765 from vmarmol/content-type

Set Content-Type on static files.
This commit is contained in:
Rohit Jnagal 2015-06-09 19:41:28 -07:00
commit b0753a6d69

View File

@ -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
}