Skip to content

Commit 9b77faa

Browse files
committed
add basic auth for sync and lwt
1 parent 29d7fe5 commit 9b77faa

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

zarr/src/storage/http.ml

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

67
val with_open :
8+
?basic_auth:auth ->
79
?redirects:int ->
810
?tries:int ->
911
?timeout:int ->
@@ -141,10 +143,18 @@ module Make
141143
let rename _ = raise Not_implemented
142144
end
143145

144-
let with_open ?(redirects=5) ?(tries=3) ?(timeout=5) url f =
145-
let config = Ezcurl_core.Config.(default |> max_redirects redirects |> follow_location true) in
146-
let perform client = f IO.{tries; client; config; base_url = url ^ "/"} in
146+
type auth = {user : string; pwd : string}
147+
let noauth = {user = ""; pwd = ""}
148+
149+
let with_open ?(basic_auth=noauth) ?(redirects=5) ?(tries=3) ?(timeout=5) url f =
147150
let set_opts client = Curl.set_connecttimeout client timeout in
151+
let perform client =
152+
let config = Ezcurl_core.Config.(
153+
default |> max_redirects redirects |> follow_location true |>
154+
username basic_auth.user |> password basic_auth.pwd
155+
) in
156+
f IO.{tries; client; config; base_url = url ^ "/"}
157+
in
148158
C.with_client ~set_opts perform
149159

150160
include Storage.Make(IO)

0 commit comments

Comments
 (0)