Introduced StaticHeaders
middleware in http4s 0.18.15 so this library is now deprecated.
import org.http4s.server.headers.StaticHeaders
// New Way to define the service in 0.18.15
StaticHeaders.`no-cache`(service)
This is a middleware that adds a Cache-Control: no-cache
to every response returned by the HttpService[F]
.
Care should be taken that all responses are correctly calculated as it will allow any unmatched responses through without modification.
To use http4s-middleware-nocache in an existing SBT project with Scala 2.11 or a later version, add the following dependency to your
build.sbt
:
libraryDependencies += "io.chrisdavenport" %% "http4s-middleware-nocache" % "<version>"
First some imports
import org.http4s._
import org.http4s.dsl.io._
import io.chrisdavenport.http4s.server.middleware.nocache.NoCache
val service = HttpService[IO]{
case GET -> Root => Ok()
}
val req = Request[IO](Method.GET, Uri.uri("http://localhost:8080"))
val result = service(req)
result.unsafeRunSync