Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #131 and add test #132

Merged
merged 1 commit into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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