feat: add Ezcurl.Cookies module, get/set/transfer them

This commit is contained in:
Simon Cruanes 2024-10-01 12:01:36 -04:00
parent a8ad44d39e
commit 71a37788ac
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 31 additions and 6 deletions

View file

@ -95,8 +95,19 @@ let make ?(set_opts = fun _ -> ()) ?cookiejar_file
{ curl } { curl }
let delete (self : t) = Curl.cleanup self.curl let delete (self : t) = Curl.cleanup self.curl
let reload_cookiejar (self : t) : unit = Curl.set_cookielist self.curl "RELOAD"
module Cookies = struct
let reload_cookiejar (self : t) : unit =
Curl.set_cookielist self.curl "RELOAD"
let flush_cookiejar (self : t) : unit = Curl.set_cookielist self.curl "FLUSH" let flush_cookiejar (self : t) : unit = Curl.set_cookielist self.curl "FLUSH"
let get_cookies self = Curl.get_cookielist self.curl
let set_cookies self (l : string list) =
List.iter (Curl.set_cookielist self.curl) l
let transfer c1 c2 = set_cookies c2 @@ get_cookies c1
end
(* set options *) (* set options *)
let _apply_config (self : t) (config : Config.t) : unit = let _apply_config (self : t) (config : Config.t) : unit =

View file

@ -37,6 +37,10 @@ val delete : t -> unit
val with_client : ?set_opts:(Curl.t -> unit) -> (t -> 'a) -> 'a val with_client : ?set_opts:(Curl.t -> unit) -> (t -> 'a) -> 'a
(** Make a temporary client, call the function with it, then cleanup. *) (** Make a temporary client, call the function with it, then cleanup. *)
(** Cookie handling.
@since NEXT_RELEASE *)
module Cookies : sig
val flush_cookiejar : t -> unit val flush_cookiejar : t -> unit
(** If [cookiejar_file] was provided in {!make}, this flushes the current set of cookies (** If [cookiejar_file] was provided in {!make}, this flushes the current set of cookies
to the provided file. to the provided file.
@ -47,6 +51,16 @@ val reload_cookiejar : t -> unit
the provided file. the provided file.
@since NEXT_RELEASE *) @since NEXT_RELEASE *)
val get_cookies : t -> string list
(** Get cookie list (in netscape format) *)
val set_cookies : t -> string list -> unit
(** Set cookie list (in netscape format) *)
val transfer : t -> t -> unit
(** [transfer c1 c2] copies cookies in [c1] into [c2] *)
end
(* TODO: duphandle is deprecated, how do we iterate on options? (* TODO: duphandle is deprecated, how do we iterate on options?
val copy : t -> t val copy : t -> t
*) *)