Skip to content

Commit adbb974

Browse files
authored
fix #131 and add test (#132)
1 parent cd002c3 commit adbb974

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Downloads.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ function request(
333333
end
334334
end
335335
else
336-
set_body(easy, have_output)
336+
set_body(easy, have_output && method != "HEAD")
337337
end
338338
method !== nothing && set_method(easy, method)
339339
progress !== nothing && enable_progress(easy)

test/runtests.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,24 @@ include("setup.jl")
6161
@test resp.status == 200
6262
end
6363

64+
# https://github.com/JuliaLang/Downloads.jl/issues/131
65+
@testset "head request" begin
66+
url = server * "/image/jpeg"
67+
output = IOBuffer()
68+
resp = request(url; method="HEAD", output=output)
69+
@test resp isa Response
70+
@test resp.proto == "https"
71+
@test resp.status == 200
72+
@test isempty(take!(output)) # no output from a `HEAD`
73+
len = parse(Int, Dict(resp.headers)["content-length"])
74+
75+
# when we make a `GET` instead of a `HEAD`, we get a body with the content-length
76+
# returned from the `HEAD` request.
77+
resp = request(url; method="GET", output=output)
78+
bytes = take!(output)
79+
@test length(bytes) == len
80+
end
81+
6482
@testset "put request" begin
6583
url = "$server/put"
6684
data = "Hello, world!"

0 commit comments

Comments
 (0)