From a96fc0498cf46a830ebb39570340ef05da6053cc Mon Sep 17 00:00:00 2001 From: Mark Laing Date: Wed, 4 Jun 2025 10:19:58 +0100 Subject: [PATCH] pkg/http: Add function to create a new request aware cookie handler. Signed-off-by: Mark Laing --- pkg/http/cookie.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/http/cookie.go b/pkg/http/cookie.go index 9fe1531..6b87d3d 100644 --- a/pkg/http/cookie.go +++ b/pkg/http/cookie.go @@ -31,6 +31,21 @@ func NewCookieHandler(hashKey, encryptKey []byte, opts ...CookieHandlerOpt) *Coo 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) func WithUnsecure() CookieHandlerOpt {