add HTTP_VERSION_2_PRIOR_KNOWLEDGE
[ocurl.git] / examples / test_lwt_unit.ml
blobe2df03fae570d0362d0ae18322979184ddb6af24
1 (* Copyright (c) 2014, Thomas Leonard, <talex5@gmail.com> *)
3 open Curl
4 open Printf
6 let verbose = false
8 let (|>) x f = f x
9 let printfn fmt = ksprintf print_endline fmt
11 let setup buf =
12 let h = init () in
13 set_url h "http://localhost:1/missing.png";
14 set_errorbuffer h buf;
17 let () =
18 let buf1 = ref "" in
19 let h = setup buf1 in
20 (* easy *)
21 let () = try
22 perform h
23 with CurlException (code,_,_) ->
24 if verbose then printfn "Sync errors: %s <%s>" (strerror code) !buf1
26 (* lwt *)
27 let buf2 = ref "" in
28 let h = setup buf2 in
29 let code = Curl_lwt.perform h |> Lwt_main.run in
30 if verbose then printfn "Lwt errors: %s <%s>" (strerror code) !buf2;
32 if buf1 <> buf2 then
33 (printfn "FAILED: %S <> %S" !buf1 !buf2; exit 1)
34 else
35 (printfn "OK"; exit 0)