diff --git a/src/Downloads.jl b/src/Downloads.jl index b56561d..cda5cf7 100644 --- a/src/Downloads.jl +++ b/src/Downloads.jl @@ -50,10 +50,6 @@ function grace_ms(grace::Real) grace <= typemax(UInt64) รท 1000 ? round(UInt64, 1000*grace) : typemax(UInt64) end -function easy_hook(downloader::Downloader, easy::Easy, info::NamedTuple) - downloader.easy_hook !== nothing && downloader.easy_hook(easy, info) -end - get_ca_roots() = Curl.SYSTEM_SSL ? ca_roots() : ca_roots_path() function set_ca_roots(downloader::Downloader, easy::Easy) @@ -289,6 +285,7 @@ function request( verbose :: Bool = false, throw :: Bool = true, downloader :: Union{Downloader, Nothing} = nothing, + easy_hook :: Union{Function, Nothing} = nothing ) :: Union{Response, RequestError} lock(DOWNLOAD_LOCK) do yield() # let other downloads finish @@ -338,8 +335,11 @@ function request( method !== nothing && set_method(easy, method) progress !== nothing && enable_progress(easy) set_ca_roots(downloader, easy) + + # Apply user-defined customizations to the Curl easy handle info = (url = url, method = method, headers = headers) - easy_hook(downloader, easy, info) + downloader.easy_hook !== nothing && downloader.easy_hook(easy, info) + easy_hook !== nothing && easy_hook(easy) # do the request add_handle(downloader.multi, easy)