pkg/http: Add function to create a new request aware cookie handler.

Signed-off-by: Mark Laing <mark.laing@canonical.com>
This commit is contained in:
Mark Laing 2025-06-04 10:19:58 +01:00
parent 0a5b6fadbe
commit a96fc0498c
No known key found for this signature in database
GPG key ID: D9277AD9F18400E0

View file

@ -31,6 +31,21 @@ func NewCookieHandler(hashKey, encryptKey []byte, opts ...CookieHandlerOpt) *Coo
return c return c
} }
func NewRequestAwareCookieHandler(secureCookieFunc func(r *http.Request) (*securecookie.SecureCookie, error), opts ...CookieHandlerOpt) *CookieHandler {
c := &CookieHandler{
secureCookieFunc: secureCookieFunc,
secureOnly: true,
sameSite: http.SameSiteLaxMode,
path: "/",
}
for _, opt := range opts {
opt(c)
}
return c
}
type CookieHandlerOpt func(*CookieHandler) type CookieHandlerOpt func(*CookieHandler)
func WithUnsecure() CookieHandlerOpt { func WithUnsecure() CookieHandlerOpt {