Skip to content

Commit cdd6f55

Browse files
committed
more http sync/lwt updates
1 parent 4a94146 commit cdd6f55

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

zarr/src/storage/http.ml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
module type S = sig
22
exception Not_implemented
33
exception Request_failed of int * string
4-
type auth = {user : string; pwd : string}
54
include Storage.STORE
65

6+
type auth = {user : string; pwd : string}
7+
78
val with_open :
89
?basic_auth:auth ->
910
?redirects:int ->
@@ -16,6 +17,8 @@ module type S = sig
1617
and applies function [f] to the store's open handle.
1718
1819
{ul
20+
{- [basic_auth] is the username and password to use for each request if
21+
required by the server.}
1922
{- [redirects] is the maximum number of redirects allowed per http request.
2023
Defaults to 5.}
2124
{- [tries] is the maximum number of times to retry a failed request.
@@ -70,9 +73,10 @@ module Make
7073
let type' = if String.ends_with ~suffix:".json" key then "json" else "octet-stream" in
7174
let headers = [("Content-Type", "application/" ^ type')] in
7275
let* res = C.http ~headers ~tries ~client ~config ~url ~meth:HEAD () in
73-
match fold_result res with
74-
| {code; _} when code = 404 -> Deferred.return 0
75-
| {headers; code; _} when code = 200 ->
76+
match res with
77+
| Error _ -> Deferred.return 0
78+
| Ok {code; _} when code = 404 -> Deferred.return 0
79+
| Ok {headers; code; _} when code = 200 ->
7680
begin match List.assoc_opt "content-length" headers with
7781
| Some "0" -> Deferred.return 0
7882
| Some l -> Deferred.return @@ int_of_string l
@@ -81,7 +85,7 @@ module Make
8185
get t key >>| String.length with
8286
| Request_failed (404, _) -> Deferred.return 0 end
8387
end
84-
| {code; body; _} -> raise (Request_failed (code, body)) *)
88+
| Ok {code; body; _} -> raise (Request_failed (code, body)) *)
8589

8690
let is_member t key =
8791
let+ s = size t key in
@@ -144,15 +148,16 @@ module Make
144148
end
145149

146150
type auth = {user : string; pwd : string}
147-
let noauth = {user = ""; pwd = ""}
148151

149-
let with_open ?(basic_auth=noauth) ?(redirects=5) ?(tries=3) ?(timeout=5) url f =
152+
let default_cfg = Ezcurl_core.Config.(default |> follow_location true |> authmethod [CURLAUTH_ANY])
153+
154+
let with_open ?(basic_auth={user=""; pwd =""}) ?(redirects=5) ?(tries=3) ?(timeout=5) url f =
150155
let set_opts client = Curl.set_connecttimeout client timeout in
151156
let perform client =
152-
let config = Ezcurl_core.Config.(
153-
default |> max_redirects redirects |> follow_location true |>
154-
authmethod [CURLAUTH_ANY] |> username basic_auth.user |> password basic_auth.pwd
155-
) in
157+
let config = Ezcurl_core.Config.max_redirects redirects default_cfg
158+
|> Ezcurl_core.Config.username basic_auth.user
159+
|> Ezcurl_core.Config.password basic_auth.pwd
160+
in
156161
f IO.{tries; client; config; base_url = url ^ "/"}
157162
in
158163
C.with_client ~set_opts perform

0 commit comments

Comments
 (0)