X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=wrappers%2Fpl_LWP_UserAgent.ml;h=a29383943ea3eb6a74f3e41d1b283925760bcd5b;hb=b7dea9bbf5d430051b73ff38eecc26f4f407a586;hp=2a68f4a6dc28fe8e5175f5bd7485726a45876f62;hpb=1c369c3ba6b71d4524dfacd0ba3554e8a524ed57;p=perl4caml.git diff --git a/wrappers/pl_LWP_UserAgent.ml b/wrappers/pl_LWP_UserAgent.ml index 2a68f4a..a293839 100644 --- a/wrappers/pl_LWP_UserAgent.ml +++ b/wrappers/pl_LWP_UserAgent.ml @@ -1,12 +1,17 @@ -(* Wrapper around Perl LWP::UserAgent class. - * Copyright (C) 2003 Merjis Ltd. - * $Id: pl_LWP_UserAgent.ml,v 1.1 2003-10-12 17:33:15 rich Exp $ - *) +(** Wrapper around Perl [LWP::UserAgent] class. + * + * Copyright (C) 2003 Merjis Ltd. + * + * $Id: pl_LWP_UserAgent.ml,v 1.5 2004-11-25 21:24:51 rich Exp $ + *) open Perl open Pl_HTTP_Request open Pl_HTTP_Response +open Pl_HTTP_Cookies + +let _ = eval "use LWP::UserAgent" class lwp_useragent sv = @@ -16,7 +21,7 @@ object (self) let sv = call_method sv "simple_request" [request#sv] in new http_response sv method request (request : http_request) = - let sv = call_method sv "simple_request" [request#sv] in + let sv = call_method sv "request" [request#sv] in new http_response sv method agent = string_of_sv (call_method sv "agent" []) @@ -26,6 +31,27 @@ object (self) 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 requests_redirectable = + let sv = call_method sv "requests_redirectable" [] in + let av = deref_array sv in + List.map string_of_sv (list_of_av av) + method set_requests_redirectable methods = + let av = av_empty () in + List.iter (av_push av) (List.map sv_of_string methods); + call_method_void sv "requests_redirectable" [arrayref av] + method add_requests_redirectable method_ = + let sv = call_method sv "requests_redirectable" [] in + let av = deref_array sv in + av_push av (sv_of_string method_) method timeout = int_of_sv (call_method sv "timeout" []) method set_timeout v = @@ -38,14 +64,14 @@ object (self) int_of_sv (call_method sv "max_size" []) method set_max_size v = call_method_void sv "max_size" [sv_of_int v] - method env_proxy = + method env_proxy () = call_method_void sv "env_proxy" [] end (* 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 -> @@ -64,5 +90,12 @@ let new_ ?agent ?from ?timeout ?use_eval ?parse_head ?max_size 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