2014-02-20 19 views
2

我的問題是SimpleResult似乎不允許讀訪問其會話,只能寫訪問(withSession)。Play for Scala:在ActionBuilder中,是否可以修改包裝動作結果的會話?

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. 
    } 
} 

我錯過了什麼?

回答

1

這似乎在2.2.x中是不可能的,但在2.3.x版本play.api.mvc.Result有2種新的方法addingToSessionremovingFromSession允許從結果添加和刪除會話值。

... 
resultFuture map (_.addingToSession(myKey -> myValue)(request)) 
... 

所以上面的問題可以通過來解決

相關問題