summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkg/pls/option.go3
-rw-r--r--pkg/test/http.go3
-rw-r--r--pkg/web/cookie/new.go13
3 files changed, 16 insertions, 3 deletions
diff --git a/pkg/pls/option.go b/pkg/pls/option.go
new file mode 100644
index 0000000..bd717fa
--- /dev/null
+++ b/pkg/pls/option.go
@@ -0,0 +1,3 @@
+package pls
+
+type Option[T any] func(T) T
diff --git a/pkg/test/http.go b/pkg/test/http.go
index 280aef6..6c15016 100644
--- a/pkg/test/http.go
+++ b/pkg/test/http.go
@@ -10,9 +10,10 @@ import (
xcontext "github.com/xlgmokha/x/pkg/context"
"github.com/xlgmokha/x/pkg/serde"
"github.com/xlgmokha/x/pkg/x"
+ "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls"
)
-type RequestOption func(*http.Request) *http.Request
+type RequestOption pls.Option[*http.Request]
func Request(method, target string, options ...RequestOption) *http.Request {
request := httptest.NewRequest(method, target, nil)
diff --git a/pkg/web/cookie/new.go b/pkg/web/cookie/new.go
index d4d0700..a3cb200 100644
--- a/pkg/web/cookie/new.go
+++ b/pkg/web/cookie/new.go
@@ -5,10 +5,13 @@ import (
"time"
"github.com/xlgmokha/x/pkg/env"
+ "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls"
)
-func New(name, value string, expires time.Time) *http.Cookie {
- return &http.Cookie{
+type CookieOption pls.Option[*http.Cookie]
+
+func New(name, value string, expires time.Time, options ...CookieOption) *http.Cookie {
+ cookie := &http.Cookie{
Name: name,
Value: value, // TODO:: digitally sign the value
Expires: expires,
@@ -19,4 +22,10 @@ func New(name, value string, expires time.Time) *http.Cookie {
SameSite: http.SameSiteStrictMode,
Domain: env.Fetch("HOST", "localhost"),
}
+
+ for _, option := range options {
+ cookie = option(cookie)
+ }
+
+ return cookie
}