-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathcookies.go
More file actions
36 lines (31 loc) · 811 Bytes
/
Copy pathcookies.go
File metadata and controls
36 lines (31 loc) · 811 Bytes
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
34
35
36
package surf
import (
"regexp"
"github.com/enetx/g"
"github.com/enetx/http"
)
// Cookies represents a list of HTTP Cookies.
type Cookies []*http.Cookie
// Contains checks if the cookies collection contains a cookie that matches the provided pattern.
// The pattern parameter can be either a string or a pointer to a regexp.Regexp object.
// The method returns true if a matching cookie is found and false otherwise.
func (cs Cookies) Contains(pattern any) bool {
for _, cookie := range cs {
c := g.String(cookie.String()).Lower()
switch p := pattern.(type) {
case string:
if c.Contains(g.String(p).Lower()) {
return true
}
case g.String:
if c.Contains(p.Lower()) {
return true
}
case *regexp.Regexp:
if c.Regexp().Match(p) {
return true
}
}
}
return false
}