From 64d36e25a16abdb2c47ef2f22d9e42ade4dd1ffe Mon Sep 17 00:00:00 2001 From: Panagiotis Georgakopoulos Date: Wed, 6 Dec 2023 13:19:57 +0200 Subject: [PATCH] test: test that HEAD requests don't have return a body --- test/server.jl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/server.jl b/test/server.jl index af1a98741..0ebd8096b 100644 --- a/test/server.jl +++ b/test/server.jl @@ -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