1 (** Wrapper around Perl [LWP::UserAgent] class.
3 * Copyright (C) 2003 Merjis Ltd.
5 * $Id: pl_LWP_UserAgent.ml,v 1.4 2004-11-22 17:08:36 rich Exp $
14 let _ = eval "use LWP::UserAgent"
16 class lwp_useragent sv =
20 method simple_request (request : http_request) =
21 let sv = call_method sv "simple_request" [request#sv] in
23 method request (request : http_request) =
24 let sv = call_method sv "request" [request#sv] in
27 string_of_sv (call_method sv "agent" [])
29 call_method_void sv "agent" [sv_of_string v]
31 string_of_sv (call_method sv "from" [])
33 call_method_void sv "from" [sv_of_string v]
35 let sv = call_method sv "cookie_jar" [] in
37 method set_cookie_jar (v : http_cookies) =
38 call_method_void sv "cookie_jar" [v#sv]
39 method set_cookie_jar_file filename =
40 let hv = hv_empty () in
41 hv_set hv "file" (sv_of_string filename);
42 call_method_void sv "cookie_jar" [hashref hv]
44 int_of_sv (call_method sv "timeout" [])
45 method set_timeout v =
46 call_method_void sv "timeout" [sv_of_int v]
48 bool_of_sv (call_method sv "parse_head" [])
49 method set_parse_head v =
50 call_method_void sv "parse_head" [sv_of_bool v]
52 int_of_sv (call_method sv "max_size" [])
53 method set_max_size v =
54 call_method_void sv "max_size" [sv_of_int v]
56 call_method_void sv "env_proxy" []
60 (* Note that "new" is a reserved word, so I've appended an _ character. *)
61 let new_ ?agent ?from ?timeout ?use_eval ?parse_head ?max_size
62 ?env_proxy ?keep_alive ?cookie_jar ?cookie_jar_file () =
64 let may f = function None -> () | Some v -> f v in
66 args := sv_of_string "agent" :: sv_of_string v :: !args) agent;
68 args := sv_of_string "from" :: sv_of_string v :: !args) from;
70 args := sv_of_string "timeout" :: sv_of_int v :: !args) timeout;
72 args := sv_of_string "use_eval" :: sv_of_bool v :: !args) use_eval;
74 args := sv_of_string "parse_head" :: sv_of_bool v :: !args)parse_head;
76 args := sv_of_string "max_size" :: sv_of_int v :: !args) max_size;
78 args := sv_of_string "env_proxy" :: sv_of_bool v :: !args) env_proxy;
80 args := sv_of_string "keep_alive" :: sv_of_int v :: !args) keep_alive;
81 may (fun (v : http_cookies) ->
82 args := sv_of_string "cookie_jar" :: v#sv :: !args) cookie_jar;
84 let hv = hv_empty () in
85 hv_set hv "file" (sv_of_string v);
86 let sv = hashref hv in
87 args := sv_of_string "cookie_jar" :: sv :: !args) cookie_jar_file;
88 let sv = call_class_method "LWP::UserAgent" "new" !args in