Add cookie convenience funcs

Fix test helper func
This commit is contained in:
y a t s
2026-06-18 11:44:25 -04:00
parent 72840af90e
commit 92438691f1
5 changed files with 49 additions and 37 deletions
-27
View File
@@ -14,33 +14,6 @@ import (
"golang.org/x/net/html/atom"
)
func getCookie(jar http.CookieJar, u *url.URL, name string) *http.Cookie {
cookies := jar.Cookies(u)
for _, c := range cookies {
if c.Name == name {
return c
}
}
return nil
}
func setCookie(jar http.CookieJar, u *url.URL, newCookie *http.Cookie) {
cookies := jar.Cookies(u)
for i, c := range cookies {
if c.Name == newCookie.Name {
cookies[i] = newCookie
jar.SetCookies(u, cookies)
return
}
}
// Append if not already existing.
cookies = append(cookies, newCookie)
jar.SetCookies(u, cookies)
}
// Get XFToken (data-csrf) from page html.
func XFToken(page io.Reader) (string, error) {
z := html.NewTokenizer(page)