From 91cfbc94add301e055906fff4ac729a59706a733 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 28 Feb 2023 11:06:39 -0500 Subject: [PATCH 1/4] fix: correctly set size of payload for POST close #12 --- src/core/Ezcurl_core.ml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/core/Ezcurl_core.ml b/src/core/Ezcurl_core.ml index f465e03..b4b71fb 100644 --- a/src/core/Ezcurl_core.ml +++ b/src/core/Ezcurl_core.ml @@ -311,15 +311,22 @@ module Make(IO : IO) in _apply_config self config; opt_iter range ~f:(fun s -> Curl.set_range self s); + (* TODO: ability to make content a stream with a `read` function *) opt_iter content ~f:(fun content -> Curl.set_readfunction self (content_read_fun_ content); (* also set size if known *) - match content_size_ content with - | None -> headers := ("transfer-encoding", "chunked") :: !headers - | Some size -> Curl.set_infilesize self size + match content_size_ content, meth with + | None, _ -> + Printf.eprintf "size not known\n%!"; + headers := ("transfer-encoding", "chunked") :: !headers + | Some size , POST _ -> + Curl.set_postfieldsize self size; + | Some size, _ -> + Curl.set_infilesize self size ); + (* local state *) let tries = max tries 1 in (* at least one attempt *) let body = Buffer.create 64 in @@ -329,7 +336,8 @@ module Make(IO : IO) begin match meth with | POST [] when (content <> None) -> Curl.set_post self true - | POST l -> Curl.set_httppost self l; + | POST l -> + Curl.set_httppost self l; | GET -> Curl.set_httpget self true; | PUT -> Curl.set_customrequest self "PUT"; @@ -341,6 +349,7 @@ module Make(IO : IO) | TRACE -> Curl.set_customrequest self "TRACE" | PATCH -> Curl.set_customrequest self "PATCH" end; + _set_headers self !headers; Curl.set_headerfunction self (fun s0 -> From 9e7d9be5c3430575761ba55770629e77acfc7692 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 28 Feb 2023 11:07:20 -0500 Subject: [PATCH 2/4] fix: workaround servers which do not understand Expect header --- src/core/Ezcurl_core.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/Ezcurl_core.ml b/src/core/Ezcurl_core.ml index b4b71fb..00983a0 100644 --- a/src/core/Ezcurl_core.ml +++ b/src/core/Ezcurl_core.ml @@ -320,7 +320,7 @@ module Make(IO : IO) match content_size_ content, meth with | None, _ -> Printf.eprintf "size not known\n%!"; - headers := ("transfer-encoding", "chunked") :: !headers + headers := ("expect", "") :: ("transfer-encoding", "chunked") :: !headers | Some size , POST _ -> Curl.set_postfieldsize self size; | Some size, _ -> From 849194728a1ec2a09402ccfc3c03e85b83a79892 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 28 Feb 2023 11:07:55 -0500 Subject: [PATCH 3/4] chore: makefile --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 499085d..2428bca 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,8 @@ clean: doc: @dune build @doc +WATCH?=@all watch: - @dune build @all -w + @dune build $(WATCH )-w .PHONY: all build test watch From 5bb480235af61ecfa9f9b6c3c6ca3bf19212d5da Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 9 Mar 2023 11:10:50 -0500 Subject: [PATCH 4/4] remove spurious eprintf --- src/core/Ezcurl_core.ml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/Ezcurl_core.ml b/src/core/Ezcurl_core.ml index 00983a0..5e573a0 100644 --- a/src/core/Ezcurl_core.ml +++ b/src/core/Ezcurl_core.ml @@ -319,7 +319,6 @@ module Make(IO : IO) (* also set size if known *) match content_size_ content, meth with | None, _ -> - Printf.eprintf "size not known\n%!"; headers := ("expect", "") :: ("transfer-encoding", "chunked") :: !headers | Some size , POST _ -> Curl.set_postfieldsize self size;