2

我的问题是 SimpleResult 似乎不允许对其会话进行读取访问,仅允许写入访问(withSession)。

object MyAction extends ActionBuilder[MyRequest] {

    def invokeBlock[A](
        request: Request[A],
        block: (MyRequest[A]) => Future[SimpleResult]
    ): Future[SimpleResult] = {
        // do stuff, create x, y
        val resultFuture = block(MyRequest(x, y, request)
        // Now I want to modify resultFuture's session,
        // keeping any changes block might have done to request.session.
        // And I'd rather not parse result's headers by hand to do that.
    }
}

我错过了什么?

4

1 回答 1

1

这在 2.2.x 中似乎是不可能的,但在 2.3.x 中play.api.mvc.Result有 2 个新方法addToSession和removeFromSession允许从Result添加和删除会话值。

所以上述问题可以通过以下方式解决:

...
resultFuture map (_.addingToSession(myKey -> myValue)(request))
...
于 2014-10-23T09:16:13.910 回答