Skip to content

Commit

Permalink
fix #131 and add test (#132)
Browse files Browse the repository at this point in the history
(cherry picked from commit adbb974)
  • Loading branch information
ericphanson authored and StefanKarpinski committed Mar 24, 2022
1 parent 2c0be5b commit 3da2f26
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Downloads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand Down

0 comments on commit 3da2f26

Please sign in to comment.