Compare commits

..

1 commit

Author SHA1 Message Date
Simon Cruanes
aa5474167f
prepare for 0.3
Some checks are pending
format / format (push) Waiting to run
github pages / deploy (push) Waiting to run
build / Build (push) Waiting to run
2026-01-20 21:10:01 -05:00
5 changed files with 46 additions and 51 deletions

View file

@ -23,7 +23,6 @@
(ocurl
(>= 0.8))
(odoc :with-doc)
(tiny_httpd (and (>= 0.19) :with-test))
(ocaml
(>= 4.03))))

View file

@ -13,7 +13,6 @@ depends: [
"dune" {>= "3.0"}
"ocurl" {>= "0.8"}
"odoc" {with-doc}
"tiny_httpd" {>= "0.19" & with-test}
"ocaml" {>= "4.03"}
]
build: [

View file

@ -1,8 +1,39 @@
get: OK
code=200,body=```
hello jeanjacques
body=```
version = 0.27.0
profile=conventional
margin=80
if-then-else=k-r
parens-ite=true
parens-tuple=multi-line-only
sequence-style=terminator
type-decl=sparse
break-cases=toplevel
cases-exp-indent=2
field-space=tight-decl
leading-nested-match-parens=true
module-item-spacing=compact
quiet=true
ocaml-version=4.08.0
```
streaming get: OK
code=200, body=```
hello reineclaude
body=```
version = 0.27.0
profile=conventional
margin=80
if-then-else=k-r
parens-ite=true
parens-tuple=multi-line-only
sequence-style=terminator
type-decl=sparse
break-cases=toplevel
cases-exp-indent=2
field-space=tight-decl
leading-nested-match-parens=true
module-item-spacing=compact
quiet=true
ocaml-version=4.08.0
```
same buf? true

View file

@ -1,44 +1,17 @@
module H = Tiny_httpd
let body = ref ""
(** Start server, return its port and a thread *)
let start_server () : int * Thread.t =
let port = ref (-1) in
let cond = Condition.create () in
let mutex = Mutex.create () in
let url =
"https://raw.githubusercontent.com/c-cube/ezcurl/refs/heads/main/.ocamlformat"
let server = H.create ~masksigpipe:true ~addr:"127.0.0.1" ~port:0 () in
H.add_route_handler server
H.Route.(exact "test" @/ string @/ return)
(fun str _req ->
H.Response.make_string ~code:200 @@ Ok (Printf.sprintf "hello %s" str));
let th =
Thread.create
(H.run_exn ~after_init:(fun () ->
port := H.port server;
Condition.broadcast cond))
server
in
(* wait for server to start *)
while !port < 0 do
Mutex.lock mutex;
Condition.wait cond mutex;
Mutex.unlock mutex
done;
!port, th
let test1 ~port () =
let name = "jeanjacques" in
let url = Printf.sprintf "http://127.0.0.1:%d/test/%s" port name in
let () =
match Ezcurl.get ~url () with
| Error (code, msg) ->
Format.eprintf "curl error: code `%s` (%s)@." (Curl.strerror code) msg
| Ok res ->
Format.printf "get: OK@.code=%d,body=```@.%s@.```@." res.code res.body
body := res.body;
Format.printf "get: OK@.body=```@.%s@.```@." !body
let test2 ~port () =
let name = "reineclaude" in
let url = Printf.sprintf "http://127.0.0.1:%d/test/%s" port name in
let () =
let buf = Buffer.create 32 in
match
Ezcurl.http_stream ~meth:GET ~url
@ -51,13 +24,7 @@ let test2 ~port () =
with
| Error (code, msg) ->
Format.eprintf "curl error: code `%s` (%s)@." (Curl.strerror code) msg
| Ok res ->
| Ok _res ->
let new_body = Buffer.contents buf in
Format.printf "streaming get: OK@.code=%d, body=```@.%s@.```@." res.code
new_body
let () =
let port, _th = start_server () in
test1 ~port ();
test2 ~port ();
exit 0
Format.printf "streaming get: OK@.body=```@.%s@.```@." new_body;
Format.printf "same buf? %b@." (new_body = !body)

View file

@ -1,4 +1,3 @@
(test
(name basic_test)
(package ezcurl)
(libraries ezcurl tiny_httpd threads.posix))
(libraries ezcurl))