mirror of
https://github.com/prometheus/alertmanager
synced 2025-01-15 18:49:02 +00:00
Merge pull request #1817 from mxinden/disable-caching
ui/web: Set HTTP headers to prevent asset caching
This commit is contained in:
commit
a36bc1bb8d
14
ui/web.go
14
ui/web.go
@ -31,24 +31,32 @@ func Register(r *route.Router, reloadCh chan<- chan error, logger log.Logger) {
|
||||
r.Get("/metrics", promhttp.Handler().ServeHTTP)
|
||||
|
||||
r.Get("/", func(w http.ResponseWriter, req *http.Request) {
|
||||
disableCaching(w)
|
||||
|
||||
req.URL.Path = "/static/"
|
||||
fs := http.FileServer(asset.Assets)
|
||||
fs.ServeHTTP(w, req)
|
||||
})
|
||||
|
||||
r.Get("/script.js", func(w http.ResponseWriter, req *http.Request) {
|
||||
disableCaching(w)
|
||||
|
||||
req.URL.Path = "/static/script.js"
|
||||
fs := http.FileServer(asset.Assets)
|
||||
fs.ServeHTTP(w, req)
|
||||
})
|
||||
|
||||
r.Get("/favicon.ico", func(w http.ResponseWriter, req *http.Request) {
|
||||
disableCaching(w)
|
||||
|
||||
req.URL.Path = "/static/favicon.ico"
|
||||
fs := http.FileServer(asset.Assets)
|
||||
fs.ServeHTTP(w, req)
|
||||
})
|
||||
|
||||
r.Get("/lib/*path", func(w http.ResponseWriter, req *http.Request) {
|
||||
disableCaching(w)
|
||||
|
||||
req.URL.Path = path.Join("/static/lib", route.Param(req.Context(), "path"))
|
||||
fs := http.FileServer(asset.Assets)
|
||||
fs.ServeHTTP(w, req)
|
||||
@ -76,3 +84,9 @@ func Register(r *route.Router, reloadCh chan<- chan error, logger log.Logger) {
|
||||
r.Get("/debug/*subpath", http.DefaultServeMux.ServeHTTP)
|
||||
r.Post("/debug/*subpath", http.DefaultServeMux.ServeHTTP)
|
||||
}
|
||||
|
||||
func disableCaching(w http.ResponseWriter) {
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
w.Header().Set("Pragma", "no-cache")
|
||||
w.Header().Set("Expires", "0") // Prevent proxies from caching.
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user