Skip to content

Commit

Permalink
fix JuliaLang#131 and add test (JuliaLang#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericphanson authored Jul 13, 2021
1 parent cd002c3 commit adbb974
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 adbb974

Please sign in to comment.