From 848d374fc563fa9dc6b4d5e6e5be5ad2022652a7 Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Fri, 6 Aug 2021 21:43:37 +0200 Subject: [PATCH] Improve inferability of download() (#133) --- src/Curl/Easy.jl | 10 ++++++---- src/Curl/Multi.jl | 2 +- src/Downloads.jl | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Curl/Easy.jl b/src/Curl/Easy.jl index 7e2d466..0dd1108 100644 --- a/src/Curl/Easy.jl +++ b/src/Curl/Easy.jl @@ -252,11 +252,13 @@ function get_response_info(easy::Easy) for hdr in easy.res_hdrs if contains(hdr, r"^\s*$") # ignore - elseif (m = match(r"^(HTTP/\d+(?:.\d+)?\s+\d+\b.*?)\s*$", hdr)) !== nothing - message = m.captures[1] + elseif (m = match(r"^(HTTP/\d+(?:.\d+)?\s+\d+\b.*?)\s*$", hdr); m) !== nothing + message = m.captures[1]::SubString{String} empty!(headers) - elseif (m = match(r"^(\S[^:]*?)\s*:\s*(.*?)\s*$", hdr)) !== nothing - push!(headers, lowercase(m.captures[1]) => m.captures[2]) + elseif (m = match(r"^(\S[^:]*?)\s*:\s*(.*?)\s*$", hdr); m) !== nothing + key = lowercase(m.captures[1]::SubString{String}) + val = m.captures[2]::SubString{String} + push!(headers, key => val) else @warn "malformed HTTP header" url status header=hdr end diff --git a/src/Curl/Multi.jl b/src/Curl/Multi.jl index 238aa4a..eb16d00 100644 --- a/src/Curl/Multi.jl +++ b/src/Curl/Multi.jl @@ -55,7 +55,7 @@ end function remove_handle(multi::Multi, easy::Easy) lock(multi.lock) do @check curl_multi_remove_handle(multi.handle, easy.handle) - deleteat!(multi.easies, findlast(==(easy), multi.easies)) + deleteat!(multi.easies, findlast(==(easy), multi.easies)::Int) !isempty(multi.easies) && return cleanup_cb = @cfunction(cleanup_callback, Cvoid, (Ptr{Cvoid},)) if multi.grace <= 0 diff --git a/src/Downloads.jl b/src/Downloads.jl index 6b73be3..6a6c5cb 100644 --- a/src/Downloads.jl +++ b/src/Downloads.jl @@ -228,7 +228,7 @@ function download( progress = progress, verbose = verbose, downloader = downloader, - ) + )::Response status_ok(response.proto, response.status) && return output throw(RequestError(url, Curl.CURLE_OK, "", response)) end