From 301daf07ac8b03e871ca0040d4375cedd8882956 Mon Sep 17 00:00:00 2001 From: Vamshi Maskuri <117595548+varshith257@users.noreply.github.com> Date: Wed, 25 Sep 2024 19:13:56 +0530 Subject: [PATCH] Cache Control --- .../test/scala/zio/http/ConformanceSpec.scala | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/zio-http/jvm/src/test/scala/zio/http/ConformanceSpec.scala b/zio-http/jvm/src/test/scala/zio/http/ConformanceSpec.scala index 5c49f64d87..78fde503ef 100644 --- a/zio-http/jvm/src/test/scala/zio/http/ConformanceSpec.scala +++ b/zio-http/jvm/src/test/scala/zio/http/ConformanceSpec.scala @@ -683,6 +683,50 @@ object ConformanceSpec extends ZIOHttpSpec { responseInvalid.headers.get(Header.CacheControl.name).contains("""s-maxage="10""""), ) }, + test("Cache-Control should use quoted-string form for no-cache directive(response_directive_no_cache)") { + val validResponse = Response + .status(Status.Ok) + .addHeader(Header.Custom("Cache-Control", """no-cache="age"""")) + + val invalidResponse = Response + .status(Status.Ok) + .addHeader(Header.Custom("Cache-Control", "no-cache=age")) + + val app = Routes( + Method.GET / "valid" -> Handler.fromResponse(validResponse), + Method.GET / "invalid" -> Handler.fromResponse(invalidResponse), + ) + + for { + responseValid <- app.runZIO(Request.get("/valid")) + responseInvalid <- app.runZIO(Request.get("/invalid")) + } yield assertTrue( + responseValid.headers.get(Header.CacheControl.name).contains("""no-cache="age""""), + responseInvalid.headers.get(Header.CacheControl.name).contains("no-cache=age"), + ) + }, + test("Cache-Control should use quoted-string form for private directive(response_directive_private)") { + val validResponse = Response + .status(Status.Ok) + .addHeader(Header.Custom("Cache-Control", """private="x-frame-options"""")) + + val invalidResponse = Response + .status(Status.Ok) + .addHeader(Header.Custom("Cache-Control", "private=x-frame-options")) + + val app = Routes( + Method.GET / "valid" -> Handler.fromResponse(validResponse), + Method.GET / "invalid" -> Handler.fromResponse(invalidResponse), + ) + + for { + responseValid <- app.runZIO(Request.get("/valid")) + responseInvalid <- app.runZIO(Request.get("/invalid")) + } yield assertTrue( + responseValid.headers.get(Header.CacheControl.name).contains("""private="x-frame-options""""), + responseInvalid.headers.get(Header.CacheControl.name).contains("private=x-frame-options"), + ) + }, ), suite("conformance")( test("should not include Content-Length header for 204 No Content responses") {