CookieJar
stores cookies and replays them on matching requests.
Create a jar with CookieJar.create, then pass it to Client.get-with-jar
and similar functions:
(let-do [jar (CookieJar.create)]
(match (Client.get-with-jar "https://example.com/" &jar)
(Result.Success r) (println* (Response.body &r))
(Result.Error e) (IO.errorln &e))
; jar now has cookies; they are sent on the next request automatically
(match (Client.get-with-jar "https://example.com/page" &jar)
(Result.Success r) (println* (Response.body &r))
(Result.Error e) (IO.errorln &e)))
apply-to-headers
(Fn [(Ref CookieJar a), (Ref String b), (Ref (Map String (Array String)) c)] (Map String (Array String)))
(apply-to-headers jar url headers)
adds a Cookie header for matching cookies to the headers map. Returns headers unchanged if no cookies match.
cookie-header
(Fn [(Ref CookieJar a), (Ref String b)] (Maybe String))
(cookie-header jar url)
builds a Cookie header value for the URL, or Nothing if no cookies match.
cookies
(Fn [(Ref CookieJar a)] (Ref (Array Cookie) a))
gets the cookies property of a CookieJar.
matching
(Fn [(Ref CookieJar a), (Ref String b)] (Array Cookie))
(matching jar url)
returns cookies matching the given URL by domain, path, security, and expiry.
set-cookies
(Fn [CookieJar, (Array Cookie)] CookieJar)
sets the cookies property of a CookieJar.
set-cookies!
(Fn [(Ref CookieJar a), (Array Cookie)] ())
sets the cookies property of a CookieJar in place.
store!
(Fn [(Ref CookieJar a), (Ref Cookie a)] ())
(store! jar c)
stores a cookie, replacing any with the same name, domain, and path.
store-response!
(Fn [(Ref CookieJar a), (Ref Response b), (Ref String c)] ())
(store-response! jar resp url)
stores cookies from a response. The URL provides the default domain for cookies without a Domain attribute.
update-cookies
(Fn [CookieJar, (Ref (Fn [(Array Cookie)] (Array Cookie) a) b)] CookieJar)
updates the cookies property of a CookieJar using a function f.