diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-06-07 19:33:07 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-06-07 19:33:07 +0200 |
commit | c7a8aa113a914e70e027fea93265c7232b865b5e (patch) | |
tree | d5514cb6e5f49838ff75e814b64652ad244cf0ef /pkg/handler/static | |
parent | 18aa098f50e2a2c7db01dd4d04dde460fd40f5d5 (diff) | |
download | cerrado-c7a8aa113a914e70e027fea93265c7232b865b5e.tar.gz cerrado-c7a8aa113a914e70e027fea93265c7232b865b5e.tar.bz2 cerrado-c7a8aa113a914e70e027fea93265c7232b865b5e.zip |
feat: Add compression
Diffstat (limited to 'pkg/handler/static')
-rw-r--r-- | pkg/handler/static/handler.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/pkg/handler/static/handler.go b/pkg/handler/static/handler.go index a8b4583..5155068 100644 --- a/pkg/handler/static/handler.go +++ b/pkg/handler/static/handler.go @@ -2,8 +2,11 @@ package static import ( "io/fs" + "mime" "net/http" + "path/filepath" + "git.gabrielgio.me/cerrado/pkg/ext" "git.gabrielgio.me/cerrado/static" ) @@ -14,8 +17,12 @@ func ServeStaticHandler() (func(w http.ResponseWriter, r *http.Request), error) } return func(w http.ResponseWriter, r *http.Request) { - f := r.PathValue("file") - + var ( + f = r.PathValue("file") + e = filepath.Ext(f) + m = mime.TypeByExtension(e) + ) + ext.SetMIME(w, m) http.ServeFileFS(w, r, staticFs, f) }, nil } |