Skip to content

Commit 67b77d5

Browse files
committed
improve httpstore for sync
1 parent d19f953 commit 67b77d5

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

zarr-sync/src/storage.ml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,11 @@ module HttpStore = struct
147147
(*let size t key =
148148
let tries = t.tries and client = t.client and config = t.config in
149149
let url = t.base_url ^ key in
150-
print_endline @@ "about to HEAD " ^ url;
151-
let res = Ezcurl.http ~tries ~client ~config ~url ~meth:HEAD () in
150+
let type' = if String.ends_with ~suffix:".json" key then "json" else "octet-stream" in
151+
let headers = [("Content-Type", "application/" ^ type')] in
152+
let res = Ezcurl.http ~headers ~tries ~client ~config ~url ~meth:HEAD () in
152153
match fold_result res with
153-
| {code; _} when code = 404 ->
154-
print_endline "akho head";
155-
0
154+
| {code; _} when code = 404 -> 0
156155
| {headers; _} ->
157156
match List.assoc_opt "content-length" headers with
158157
| (Some "0" | None) ->
@@ -177,7 +176,11 @@ module HttpStore = struct
177176
let set t key data =
178177
let tries = t.tries and client = t.client and config = t.config
179178
and url = t.base_url ^ key and content = `String data in
180-
let res = Ezcurl.post ~params:[] ~tries ~client ~config ~url ~content () in
179+
let type' = if String.ends_with ~suffix:".json" key then "json" else "octet-stream" in
180+
let headers =
181+
[("Content-Length", string_of_int (String.length data))
182+
;("Content-Type", "application/" ^ type')] in
183+
let res = Ezcurl.post ~params:[] ~headers ~tries ~client ~config ~url ~content () in
181184
match fold_result res with
182185
| {code; _} when code = 200 || code = 201 -> ()
183186
| {code; body; _} -> raise (Request_failed (code, body))
@@ -212,10 +215,11 @@ module HttpStore = struct
212215
let rename _ = raise Not_implemented
213216
end
214217

215-
let with_open ?(redirects=5) ?(tries=3) url f =
218+
let with_open ?(redirects=5) ?(tries=3) ?(timeout=5) url f =
216219
let config = Ezcurl_core.Config.(default |> max_redirects redirects |> follow_location true) in
217220
let perform client = f IO.{tries; client; config; base_url = url ^ "/"} in
218-
Ezcurl_core.with_client perform
221+
let set_opts client = Curl.set_connecttimeout client timeout in
222+
Ezcurl_core.with_client ~set_opts perform
219223

220224
include Zarr.Storage.Make(IO)
221225
end

zarr-sync/src/storage.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ module HttpStore : sig
2525
exception Not_implemented
2626
exception Request_failed of int * string
2727
include Zarr.Storage.STORE with module Deferred = Deferred
28-
val with_open : ?redirects:int -> ?tries:int -> string -> (t -> 'a) -> 'a
28+
val with_open : ?redirects:int -> ?tries:int -> ?timeout:int -> string -> (t -> 'a) -> 'a
2929
end

0 commit comments

Comments
 (0)