From adbb974f089d75d2f544f994c0db6551e5cef375 Mon Sep 17 00:00:00 2001 From: Eric Hanson <5846501+ericphanson@users.noreply.github.com> Date: Tue, 13 Jul 2021 23:58:18 +0200 Subject: [PATCH] fix #131 and add test (#132) --- src/Downloads.jl | 2 +- test/runtests.jl | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Downloads.jl b/src/Downloads.jl index 5e07a74..6b73be3 100644 --- a/src/Downloads.jl +++ b/src/Downloads.jl @@ -333,7 +333,7 @@ function request( end end else - set_body(easy, have_output) + set_body(easy, have_output && method != "HEAD") end method !== nothing && set_method(easy, method) progress !== nothing && enable_progress(easy) diff --git a/test/runtests.jl b/test/runtests.jl index fd4bb20..f43a033 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -61,6 +61,24 @@ include("setup.jl") @test resp.status == 200 end + # https://github.com/JuliaLang/Downloads.jl/issues/131 + @testset "head request" begin + url = server * "/image/jpeg" + output = IOBuffer() + resp = request(url; method="HEAD", output=output) + @test resp isa Response + @test resp.proto == "https" + @test resp.status == 200 + @test isempty(take!(output)) # no output from a `HEAD` + len = parse(Int, Dict(resp.headers)["content-length"]) + + # when we make a `GET` instead of a `HEAD`, we get a body with the content-length + # returned from the `HEAD` request. + resp = request(url; method="GET", output=output) + bytes = take!(output) + @test length(bytes) == len + end + @testset "put request" begin url = "$server/put" data = "Hello, world!"