score:9

Accepted answer

actually, a session is an immutable structure as well.

it's true that the session object that is stored in the request one has a + method, this latter is respecting the immutability paradigm by returning a new instance of session. keeping the request.session unchanged.

thinking a step further, we can assert on the fact that an updated session has only a sense when reused in another request-response transaction...

so the way to update a session is to update it while building the response (result in play), like that:

ok("just a test").withsession(request.session + ("token", "foobar"))

this will add the new session field in your cookie, that will be available in the next transaction (i.e. request-response).


Related Query

More Query from same tag