mirror of
https://github.com/c-cube/ezcurl.git
synced 2025-12-06 03:05:31 -05:00
feat: add Ezcurl.Cookies module, get/set/transfer them
This commit is contained in:
parent
a8ad44d39e
commit
71a37788ac
2 changed files with 31 additions and 6 deletions
|
|
@ -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 =
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
*)
|
*)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue