*
* Copyright (C) 2003 Merjis Ltd.
*
- * $Id: pl_LWP_UserAgent.ml,v 1.3 2003-10-16 13:41:07 rich Exp $
+ * $Id: pl_LWP_UserAgent.ml,v 1.4 2004-11-22 17:08:36 rich Exp $
*)
open Perl
open Pl_HTTP_Request
open Pl_HTTP_Response
+open Pl_HTTP_Cookies
let _ = eval "use LWP::UserAgent"
string_of_sv (call_method sv "from" [])
method set_from v =
call_method_void sv "from" [sv_of_string v]
+ method cookie_jar =
+ let sv = call_method sv "cookie_jar" [] in
+ new http_cookies sv
+ method set_cookie_jar (v : http_cookies) =
+ call_method_void sv "cookie_jar" [v#sv]
+ method set_cookie_jar_file filename =
+ let hv = hv_empty () in
+ hv_set hv "file" (sv_of_string filename);
+ call_method_void sv "cookie_jar" [hashref hv]
method timeout =
int_of_sv (call_method sv "timeout" [])
method set_timeout v =
(* Note that "new" is a reserved word, so I've appended an _ character. *)
let new_ ?agent ?from ?timeout ?use_eval ?parse_head ?max_size
- ?env_proxy ?keep_alive () =
+ ?env_proxy ?keep_alive ?cookie_jar ?cookie_jar_file () =
let args = ref [] in
let may f = function None -> () | Some v -> f v in
may (fun v ->
args := sv_of_string "env_proxy" :: sv_of_bool v :: !args) env_proxy;
may (fun v ->
args := sv_of_string "keep_alive" :: sv_of_int v :: !args) keep_alive;
+ may (fun (v : http_cookies) ->
+ args := sv_of_string "cookie_jar" :: v#sv :: !args) cookie_jar;
+ may (fun v ->
+ let hv = hv_empty () in
+ hv_set hv "file" (sv_of_string v);
+ let sv = hashref hv in
+ args := sv_of_string "cookie_jar" :: sv :: !args) cookie_jar_file;
let sv = call_class_method "LWP::UserAgent" "new" !args in
new lwp_useragent sv