我正在开发一个Scala Play应用程序,需要许多Controller操作,通过在响应的HTTP头中设置参数来禁用浏览器的缓存。我决定创建一个NoCache复合动作,因为我也在使用DeadBolt2(并且需要一个DeadBolt2的AuthenticatedRequest[_]),所以它看起来是这样的:
package action
import be.objectify.deadbolt.scala.AuthenticatedRequest
import play.api.http.HeaderNames
import play.api.mvc._
import scala.concurrent.Future
import scala.util.Success
case class NoCache[A](action: Action[A]) extends Action[A] with HeaderNames {
def apply(request: AuthenticatedRequest[A]): Future[Result] = {
action(request).andThen {
case Success(result) => result.withHeaders(
(CACHE_CONTROL -> "no-cache, no-store, must-revalidate"),
(PRAGMA -> "no-cache"),
(EXPIRES -> "0")
)
}
}
lazy val parser = action.parser
}但是在尝试将此Action混合到我的Controller action实现中时,它将不会编译。
def link = deadbolt.SubjectPresent()() andThen NoCache() { implicit request =>或
def link = NoCache(deadbolt.SubjectPresent()()) { implicit request =>但我看不到如何组合它们。
https://stackoverflow.com/questions/41321197
复制相似问题