Skip to content

Commit

Permalink
fix #131 and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ericphanson committed Jul 13, 2021
1 parent cd002c3 commit 1446641
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Downloads"
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
authors = ["Stefan Karpinski <stefan@karpinski.org> and contributors"]
version = "1.5.1"
version = "1.5.2"

[deps]
ArgTools = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
Expand Down
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 1446641

Please sign in to comment.