feat(security): #305 don't cache sensitive data #309
26
handler/middleware/cache_control.go
Normal file
26
handler/middleware/cache_control.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"me-fit/log"
|
||||
)
|
||||
|
||||
func CacheControl(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
path := r.URL.Path
|
||||
log.Info("path: %v", path)
|
||||
|
||||
cached := false
|
||||
if strings.HasPrefix(path, "/static") {
|
||||
cached = true
|
||||
}
|
||||
|
||||
if !cached {
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
}
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user