Skip to content

Commit

Permalink
Cache Control
Browse files Browse the repository at this point in the history
  • Loading branch information
varshith257 committed Sep 25, 2024
1 parent c940544 commit 301daf0
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions zio-http/jvm/src/test/scala/zio/http/ConformanceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit 301daf0

Please sign in to comment.