Skip to content

Commit

Permalink
test: test that HEAD requests don't have return a body
Browse files Browse the repository at this point in the history
  • Loading branch information
pankgeorg committed Dec 6, 2023
1 parent 98b1536 commit 64d36e2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,23 @@ end # @testset
@test occursin(r"^\*/\* text/plain HEAD / HTTP/1\.1 HEAD / 127\.0\.0\.1 \d+ - HTTP/1\.1 \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.* \d+/.*/\d{4}:\d{2}:\d{2}:\d{2}.* 200 0$", logs[4].message)
end

@testset "HEAD request without body" begin
sometext = "This is a big body that we don't want returned during a head"
handler = req -> begin
return HTTP.Response(200, [], sometext)
end
server = HTTP.serve!(handler; listenany=true)
port = HTTP.port(server)

response = HTTP.head("http://localhost:$port")
@test response.status == 200
@test String(response.body) == ""

response = HTTP.get("http://localhost:$port")
@test response.status == 200
@test String(response.body) == sometext

close(server)
end

end # module

0 comments on commit 64d36e2

Please sign in to comment.