From ba508643e8b2daa4e7695b9229e4784d0ccc1a7d Mon Sep 17 00:00:00 2001 From: Chris Foster Date: Tue, 21 Sep 2021 17:13:17 +1000 Subject: [PATCH] Allow per-request setting of options on the Curl easy_handle This allows any of the more esoteric CURL options to be applied as necessary on a per-request basis. --- src/Downloads.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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)