【问题标题】:Scala Play 2.5 Action composition with Deadbolt-2 actions带有 Deadbolt-2 动作的 Scala Play 2.5 动作组合
【发布时间】:2016-12-25 12:39:53
【问题描述】:

我正在开发一个 Scala Play 应用程序,并且需要通过在响应的 HTTP 标头中设置参数来禁用浏览器缓存的许多控制器操作。我决定创建一个NoCache 复合动作,因为我也在使用 Deadbolt-2(并且需要一个 Deadbolt-2 的 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
}

但是它不会编译尝试将这个动作混合到我的控制器动作实现中,例如

def link = deadbolt.SubjectPresent()() andThen NoCache() { implicit request =>

def link = NoCache(deadbolt.SubjectPresent()()) { implicit request =>

但不知道如何组合它们...

【问题讨论】:

  • 您找到解决方案了吗?我在用 DeadboltActions 编写 Play Actions 时遇到同样的问题

标签: scala playframework deadbolt-2


【解决方案1】:

我找到了如何为单个操作执行此操作:

def index = NoCache {
  deadbolt.WithAuthRequest()() { implicit request =>
    Future {
      Ok(views.html.index(userService))
    }
  }
} 

但是,我仍然没有找到如何将NoCache 应用于整个控制器类。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 2014-09-26
    • 1970-01-01
    相关资源
    最近更新 更多