From 5bcb957264d0de0185a7c46966ed1a42118f02ef Mon Sep 17 00:00:00 2001 From: Vamshi Maskuri <117595548+varshith257@users.noreply.github.com> Date: Tue, 24 Sep 2024 16:16:02 +0530 Subject: [PATCH] 304 NOT MODIFIED --- .../src/test/scala/zio/http/ServerSpec.scala | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/zio-http/jvm/src/test/scala/zio/http/ServerSpec.scala b/zio-http/jvm/src/test/scala/zio/http/ServerSpec.scala index 372e527a5d..406d4fe7bc 100644 --- a/zio-http/jvm/src/test/scala/zio/http/ServerSpec.scala +++ b/zio-http/jvm/src/test/scala/zio/http/ServerSpec.scala @@ -805,23 +805,19 @@ object ServerSpec extends RoutesRunnableSpec { val route1xxProcess = Method.GET / "processing" -> Handler.fromResponse(Response(status = Status.Processing)) val route204NoContent = Method.GET / "no-content" -> Handler.fromResponse(Response(status = Status.NoContent)) - // Combining routes into a single application val app = Routes(route1xxContinue, route1xxSwitch, route1xxProcess, route204NoContent) - // Creating corresponding requests val requestContinue = Request.get("/continue") val requestSwitch = Request.get("/switching-protocols") val requestProcess = Request.get("/processing") val requestNoContent = Request.get("/no-content") for { - // Executing requests responseContinue <- app.runZIO(requestContinue) responseSwitch <- app.runZIO(requestSwitch) responseProcess <- app.runZIO(requestProcess) responseNoContent <- app.runZIO(requestNoContent) - // Asserting that no responses have a Content-Length header } yield assertTrue( !responseContinue.headers.contains(Header.ContentLength.name), !responseSwitch.headers.contains(Header.ContentLength.name), @@ -837,6 +833,24 @@ object ServerSpec extends RoutesRunnableSpec { for { response <- app.runZIO(request) } yield assertTrue(!response.headers.contains(Header.ContentLength.name)) + } + + test("should not send content for 304 Not Modified responses") { + val app = Routes( + Method.GET / "not-modified" -> Handler.fromResponse( + Response.status(Status.NotModified), + ), + ) + + val request = Request.get("/not-modified") + + for { + response <- app.runZIO(request) + } yield assertTrue( + response.status == Status.NotModified, + response.body.isEmpty, + !response.headers.contains(Header.ContentLength.name), + !response.headers.contains(Header.TransferEncoding.name), + ) } }