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

defn

(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.

clear!

defn

(Fn [(Ref CookieJar a)] ())

                        (clear! jar)
                    

removes all cookies.

defn

(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

instantiate

(Fn [(Ref CookieJar a)] (Ref (Array Cookie) a))

gets the cookies property of a CookieJar.

copy

instantiate

(Fn [(Ref CookieJar a)] CookieJar)

copies a CookieJar.

create

defn

(Fn [] CookieJar)

                        (create)
                    

creates an empty cookie jar.

delete

instantiate

(Fn [CookieJar] ())

deletes a CookieJar. Should usually not be called manually.

init

instantiate

(Fn [(Array Cookie)] CookieJar)

creates a CookieJar.

matching

defn

(Fn [(Ref CookieJar a), (Ref String b)] (Array Cookie))

                        (matching jar url)
                    

returns cookies matching the given URL by domain, path, security, and expiry.

prn

instantiate

(Fn [(Ref CookieJar a)] String)

converts a CookieJar to a string.

set-cookies

instantiate

(Fn [CookieJar, (Array Cookie)] CookieJar)

sets the cookies property of a CookieJar.

set-cookies!

instantiate

(Fn [(Ref CookieJar a), (Array Cookie)] ())

sets the cookies property of a CookieJar in place.

size

defn

(Fn [(Ref CookieJar a)] Int)

                        (size jar)
                    

returns the number of cookies stored.

store!

defn

(Fn [(Ref CookieJar a), (Ref Cookie a)] ())

                        (store! jar c)
                    

stores a cookie, replacing any with the same name, domain, and path.

store-response!

defn

(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.

str

instantiate

(Fn [(Ref CookieJar a)] String)

converts a CookieJar to a string.

update-cookies

instantiate

(Fn [CookieJar, (Ref (Fn [(Array Cookie)] (Array Cookie) a) b)] CookieJar)

updates the cookies property of a CookieJar using a function f.