cduce_curl.ml 564 Bytes
Newer Older
1
let load_url s =
2 3 4 5
  try
    let buff = Buffer.create 4096 in 
    let conn = Curl.init () in
    Curl.set_url conn s;
6 7 8 9 10 11 12 13
    Curl.set_writefunction conn (
      fun str ->
	try
          Buffer.add_string buff str;
	  String.length str
	with
	    Failure _ -> 0
      );
14 15 16 17
    Curl.perform conn;
    Buffer.contents buff
  with Curl.CurlException (code, n, msg) ->
    Value.failwith' (Printf.sprintf "Curl error for url `%s' %i: %s" s n msg)
18 19 20


let () = 
21
  Cduce_config.register 
22 23
    "curl" 
    "Load external URLs with curl"
24
    (fun () -> Url.url_loader := load_url)