forked from thecodingmachine/gotenberg-go-client
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcookies.go
33 lines (26 loc) · 757 Bytes
/
cookies.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package gotenberg
import "errors"
const (
sameSiteStrict = "Strict"
sameSiteLax = "Lax"
sameSiteNone = "None"
)
var errRequiredCookieFieldEmpty = errors.New("required cookie field empty")
type Cookie struct {
Name string `json:"name"`
Value string `json:"value"`
Domain string `json:"domain"`
Path string `json:"path,omitempty"`
Secure bool `json:"secure,omitempty"`
HTTPOnly bool `json:"http_only,omitempty"`
SameSite string `json:"same_site,omitempty"`
}
func (c *Cookie) validate() error {
if c.Name == "" || c.Value == "" || c.Domain == "" {
return errRequiredCookieFieldEmpty
}
if c.SameSite != sameSiteStrict && c.SameSite != sameSiteLax && c.SameSite != sameSiteNone {
c.SameSite = ""
}
return nil
}