@@ -12,15 +12,24 @@ python package. In case you experience performance options, one can try to use
1212"""
1313struct HTTPStore <: AbstractStore
1414 url:: String
15+ allowed_codes:: Set{Int}
1516end
17+ HTTPStore (url) = HTTPStore (url,Set ((404 ,)))
1618
1719function Base. getindex (s:: HTTPStore , k:: String )
1820r = HTTP. request (" GET" ,string (s. url," /" ,k),status_exception = false ,socket_type_tls= OpenSSL. SSLStream)
1921if r. status >= 300
20- if r. status == 404
22+ if r. status in s . allowed_codes
2123 nothing
2224 else
23- error (" Error connecting to $(s. url) :" , String (r. body))
25+ err_msg =
26+ """ Received error code $(r. status) when connecting to $(s. url) with message $(String (r. body)) .
27+ This might be an actual error or an indication that the server returns a different error code
28+ than 404 for missing chunks. In the later case you can run
29+ `Zarr.missing_chunk_return_code!(a.storage,$(r. status) )` where a is your Zarr array or group to
30+ fix the issue.
31+ """
32+ throw (ErrorException (err_msg))
2433 end
2534else
2635 r. body
@@ -32,11 +41,28 @@ push!(storageregexlist,r"^https://"=>HTTPStore)
3241push! (storageregexlist,r" ^http://" => HTTPStore)
3342storefromstring (:: Type{<:HTTPStore} , s,_) = ConsolidatedStore (HTTPStore (s)," " )," "
3443
44+ """
45+ missing_chunk_return_code!(s::HTTPStore, code::Union{Int,AbstractVector{Int}})
46+
47+ Extends the list of HTTP return codes that signals that a certain key in a HTTPStore is not available. Most data providers
48+ return code 404 for missing elements, but some may use different return codes like 403. This function can be used
49+ to add return codes that signal missing chunks.
50+
51+ ### Example
52+
53+ ````julia
54+ a = zopen("https://path/to/remote/array")
55+ missing_chunk_return_code!(a.storage, 403)
56+ ````
57+ """
58+ missing_chunk_return_code! (s:: ConsolidatedStore ,code) = missing_chunk_return_code! (s. parent,code)
59+ missing_chunk_return_code! (s:: HTTPStore , code:: Integer ) = push! (s. allowed_codes,code)
60+ missing_chunk_return_code! (s:: HTTPStore , codes:: AbstractVector{<:Integer} ) = foreach (c-> push! (s. allowed_codes,c),codes)
3561store_read_strategy (:: HTTPStore ) = ConcurrentRead (concurrent_io_tasks[])
3662
3763
3864# # This is a server implementation for Zarr datasets
39- function zarr_req_handler (s:: AbstractStore , p)
65+ function zarr_req_handler (s:: AbstractStore , p, notfound = 404 )
4066 if s[p," .zmetadata" ] === nothing
4167 consolidate_metadata (s)
4268 end
@@ -47,12 +73,12 @@ function zarr_req_handler(s::AbstractStore, p)
4773 r = s[p,k]
4874 try
4975 if r === nothing
50- return HTTP. Response (404 , " Error: Key $k not found" )
76+ return HTTP. Response (notfound , " Error: Key $k not found" )
5177 else
5278 return HTTP. Response (200 , r)
5379 end
5480 catch e
55- return HTTP. Response (404 , " Error: $e " )
81+ return HTTP. Response (notfound , " Error: $e " )
5682 end
5783 end
5884end
0 commit comments