From aec132d37c47a1ec4e2f66d61ffdd1e3a803bdac Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sun, 8 Feb 2026 12:44:02 +0000 Subject: [PATCH] Refactor: group PUT and PATCH together with conditional upload Both methods need identical handling (customrequest + upload flag), so combine them using pattern matching to reduce duplication. Only set the upload flag when content is provided, matching the behavior of POST and preventing curl from trying to read when there's no content to upload. --- src/core/ezcurl_core.ml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/core/ezcurl_core.ml b/src/core/ezcurl_core.ml index c72679e..c8ee6d0 100644 --- a/src/core/ezcurl_core.ml +++ b/src/core/ezcurl_core.ml @@ -434,17 +434,14 @@ module Make (IO : IO) : S with type 'a io = 'a IO.t = struct | POST [] when content <> None -> Curl.set_post self.curl true | POST l -> Curl.set_httppost self.curl l | GET -> Curl.set_httpget self.curl true - | PUT -> - Curl.set_customrequest self.curl "PUT"; - Curl.set_upload self.curl true + | (PUT | PATCH) as meth -> + Curl.set_customrequest self.curl (string_of_meth meth); + if content <> None then Curl.set_upload self.curl true | DELETE -> Curl.set_customrequest self.curl "DELETE" | HEAD -> Curl.set_customrequest self.curl "HEAD" | CONNECT -> Curl.set_customrequest self.curl "CONNECT" | OPTIONS -> Curl.set_customrequest self.curl "OPTIONS" - | TRACE -> Curl.set_customrequest self.curl "TRACE" - | PATCH -> - Curl.set_customrequest self.curl "PATCH"; - Curl.set_upload self.curl true); + | TRACE -> Curl.set_customrequest self.curl "TRACE"); _set_headers self !headers; Curl.set_headerfunction self.curl (fun s0 ->