Scala Play 2.5动作合成与死锁-2动作
我正在处理Scala Play应用程序,需要许多控制器操作,通过在响应的HTTP头中设置参数来禁用浏览器缓存。我决定创建一个Scala Play 2.5动作合成与死锁-2动作,scala,playframework,deadbolt-2,Scala,Playframework,Deadbolt 2,我正在处理Scala Play应用程序,需要许多控制器操作,通过在响应的HTTP头中设置参数来禁用浏览器缓存。我决定创建一个NoCache复合动作,因为我也在使用Deadbolt-2(并且需要Deadbolt-2的AuthenticatedRequest[\u]),它看起来像这样: package action import be.objectify.deadbolt.scala.AuthenticatedRequest import play.api.http.HeaderNames imp
NoCache
复合动作,因为我也在使用Deadbolt-2(并且需要Deadbolt-2的AuthenticatedRequest[\u]
),它看起来像这样:
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
}
但如果尝试将此操作混合到控制器操作实现中,则不会编译
def link = deadbolt.SubjectPresent()() andThen NoCache() { implicit request =>
或
但是看不到如何组合它们…我发现如何在单个动作中组合它们:
def index = NoCache {
deadbolt.WithAuthRequest()() { implicit request =>
Future {
Ok(views.html.index(userService))
}
}
}
但是,我仍然没有找到如何将
NoCache
应用于整个控制器类。找到解决方案了吗?我也有同样的问题,把游戏动作和死锁动作结合起来
def index = NoCache {
deadbolt.WithAuthRequest()() { implicit request =>
Future {
Ok(views.html.index(userService))
}
}
}