mirror of
https://gitgud.io/yats/libkiwi.git
synced 2026-06-28 23:12:04 -04:00
Add cookie convenience funcs
Fix test helper func
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user