1
0
mirror of https://github.com/axzilla/templui.git synced 2025-02-23 03:24:07 +00:00
templui/internal/middleware/middleware.go

30 lines
758 B
Go
Raw Permalink Normal View History

package middleware
import (
"context"
"net/http"
"github.com/axzilla/templui/internal/ctxkeys"
)
2024-12-29 15:24:09 +07:00
func CacheControlMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "max-age=0, must-revalidate, no-cache, no-store, private")
w.Header().Set("Pragma", "no-cache")
w.Header().Set("Expires", "0")
next.ServeHTTP(w, r)
})
}
// WithURLPathValue adds the current URL's path to the context.
func WithURLPathValue(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := context.WithValue(
r.Context(),
ctxkeys.URLPathValue,
r.URL.Path,
)
next.ServeHTTP(w, r.WithContext(ctx))
})
}