【发布时间】:2019-05-07 10:47:41
【问题描述】:
在 Play 2.6 之前,我有一些自定义操作,例如NoCache 操作,我只需要关心实现apply 方法,即
package actions
import play.api.http.HeaderNames
import play.api.mvc._
import scala.concurrent.Future
/**
* Custom Action composition implementation that disables client-side browser caching
* by changing the response header of the response adding multi-browser no-cache
* parameters. The composition can be done as follows:
* {{{
*
* def link = NoCache {
* deadbolt.SubjectPresent()() { implicit request =>
* Future {
* Ok(views.html.account.link(userService, auth))
* }
* }
* }
*
* }}}
*
* @param action The inner action
* @tparam A Action type
*/
case class NoCache[A](action: Action[A]) extends Action[A] with HeaderNames {
def apply(request: Request[A]): Future[Result] = {
action(request).map { result =>
result.withHeaders(
(CACHE_CONTROL -> "no-cache, no-store, must-revalidate"),
(PRAGMA -> "no-cache"),
(EXPIRES -> "0")
)
}
}
}
现在在 Play 2.6 中我遇到了一堆错误,因为 Action 现在需要覆盖 executionContext 和 parser。我在这个 2.6 中看不到任何东西,但更复杂,但无论如何......我设法使用 global 覆盖前者,但我看不到为后者提供简单实现的方法。
如何为我的自定义 Action 指定我不关心的 BodyParser?
import scala.concurrent.ExecutionContext.Implicits.global
override def executionContext = global
override val parser: BodyParser[A] = null // <<<<<< what else here?
【问题讨论】:
-
@ViktorKlang 感谢您的链接。我以前见过它,但找不到我的 OP 的答案。
标签: scala playframework playframework-2.6