mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-06 05:13:01 +03:00
27 lines
665 B
Go
27 lines
665 B
Go
package middleware
|
|
|
|
import "github.com/gin-gonic/gin"
|
|
|
|
// CacheControlMiddleware sets a safe default Cache-Control header on responses
|
|
// that do not already specify one. This prevents proxies from caching
|
|
// authenticated responses that might contain private data.
|
|
type CacheControlMiddleware struct {
|
|
headerValue string
|
|
}
|
|
|
|
func NewCacheControlMiddleware() *CacheControlMiddleware {
|
|
return &CacheControlMiddleware{
|
|
headerValue: "private, no-store",
|
|
}
|
|
}
|
|
|
|
func (m *CacheControlMiddleware) Add() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
if c.Writer.Header().Get("Cache-Control") == "" {
|
|
c.Header("Cache-Control", m.headerValue)
|
|
}
|
|
|
|
c.Next()
|
|
}
|
|
}
|