1 (* Wrapper around Perl LWP::UserAgent class.
2 * Copyright (C) 2003 Merjis Ltd.
3 * $Id: pl_LWP_UserAgent.ml,v 1.2 2003-10-15 16:51:12 rich Exp $
11 let _ = eval "use LWP::UserAgent"
13 class lwp_useragent sv =
17 method simple_request (request : http_request) =
18 let sv = call_method sv "simple_request" [request#sv] in
20 method request (request : http_request) =
21 let sv = call_method sv "simple_request" [request#sv] in
24 string_of_sv (call_method sv "agent" [])
26 call_method_void sv "agent" [sv_of_string v]
28 string_of_sv (call_method sv "from" [])
30 call_method_void sv "from" [sv_of_string v]
32 int_of_sv (call_method sv "timeout" [])
33 method set_timeout v =
34 call_method_void sv "timeout" [sv_of_int v]
36 bool_of_sv (call_method sv "parse_head" [])
37 method set_parse_head v =
38 call_method_void sv "parse_head" [sv_of_bool v]
40 int_of_sv (call_method sv "max_size" [])
41 method set_max_size v =
42 call_method_void sv "max_size" [sv_of_int v]
44 call_method_void sv "env_proxy" []
48 (* Note that "new" is a reserved word, so I've appended an _ character. *)
49 let new_ ?agent ?from ?timeout ?use_eval ?parse_head ?max_size
50 ?env_proxy ?keep_alive () =
52 let may f = function None -> () | Some v -> f v in
54 args := sv_of_string "agent" :: sv_of_string v :: !args) agent;
56 args := sv_of_string "from" :: sv_of_string v :: !args) from;
58 args := sv_of_string "timeout" :: sv_of_int v :: !args) timeout;
60 args := sv_of_string "use_eval" :: sv_of_bool v :: !args) use_eval;
62 args := sv_of_string "parse_head" :: sv_of_bool v :: !args)parse_head;
64 args := sv_of_string "max_size" :: sv_of_int v :: !args) max_size;
66 args := sv_of_string "env_proxy" :: sv_of_bool v :: !args) env_proxy;
68 args := sv_of_string "keep_alive" :: sv_of_int v :: !args) keep_alive;
69 let sv = call_class_method "LWP::UserAgent" "new" !args in