Skip to content

Instantly share code, notes, and snippets.

@canwe
Forked from manuelbernhardt/gist:1868295
Created January 11, 2014 06:40
Show Gist options
  • Save canwe/8367831 to your computer and use it in GitHub Desktop.
Save canwe/8367831 to your computer and use it in GitHub Desktop.
val newSession = additionalSessionParams.foldLeft[Session](request.session) { _ + _ }
val r: PlainResult = action(request).asInstanceOf[PlainResult]
// workaround since withSession calls aren't composable it seems
val innerSession = r.header.headers.get(SET_COOKIE).map(cookies => Session.decodeFromCookie(Cookies.decode(cookies).find(_.name == Session.COOKIE_NAME)))
if(innerSession.isDefined) {
// there really should be an API method for adding sessions
val combined = innerSession.get.data.foldLeft(newSession) { _ + _ }
r.withSession(combined)
} else {
r.withSession(newSession)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment