middleware.noCache.middleware.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sjsls_3 Show documentation
Show all versions of sjsls_3 Show documentation
An experimental live server for scala JS projects
The newest version!
package io.github.quafadas.sjsls
import org.http4s.Header
import org.http4s.HttpRoutes
import org.http4s.Request
import org.typelevel.ci.CIStringSyntax
import scribe.Scribe
import cats.data.Kleisli
import cats.data.OptionT
import cats.effect.*
import cats.effect.IO
import cats.syntax.all.*
object NoCacheMiddlware:
def apply(service: HttpRoutes[IO])(logger: Scribe[IO]): HttpRoutes[IO] = Kleisli {
(req: Request[IO]) =>
OptionT.liftF(logger.trace("No cache middleware")) >>
OptionT.liftF(logger.trace(req.toString)) >>
service(req).map {
resp =>
resp.putHeaders(
Header.Raw(ci"Cache-Control", "no-cache")
)
}
}
end NoCacheMiddlware
© 2015 - 2024 Weber Informatics LLC | Privacy Policy