cduce_curl.ml 466 Bytes
Newer Older
1
let load_url s =
2 3 4 5 6 7 8 9 10
  try
    let buff = Buffer.create 4096 in 
    let conn = Curl.init () in
    Curl.set_url conn s;
    Curl.set_writefunction conn (Buffer.add_string buff);
    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)
11 12 13


let () = 
14 15 16
  Config.register 
    "curl" 
    "Load external URLs with curl"
17
    (fun () -> Url.url_loader := load_url)