Add cookie header string constructor

This commit is contained in:
y a t s
2024-08-27 12:10:57 -04:00
parent bdba9d8e3d
commit 01b6837eea
5 changed files with 38 additions and 12 deletions

12
jar.go
View File

@@ -1,6 +1,7 @@
package libkiwi
import (
"fmt"
"net/http"
"net/url"
"sync"
@@ -78,6 +79,17 @@ func (kj *KiwiJar) Cookies(u *url.URL) []*http.Cookie {
return <-res
}
func (kj *KiwiJar) CookieString(u *url.URL) (cookies string) {
cs := kj.Cookies(u)
for _, c := range cs {
cookies += fmt.Sprintf("; %s=%s", c.Name, c.Value)
}
// Remove leading semicolon+space.
cookies = cookies[2:]
return
}
func (kj *KiwiJar) GetCookie(u *url.URL, name string) *http.Cookie {
kj.checkAlloc(u)