Skip to content

Instantly share code, notes, and snippets.

@casualjim
Created January 18, 2012 20:24
Show Gist options
  • Save casualjim/1635323 to your computer and use it in GitHub Desktop.
Save casualjim/1635323 to your computer and use it in GitHub Desktop.
trait CookieSupport extends Handler {
self: ScalatraKernel =>
import CookieSupport._
private val _cookieOptions = new DynamicVariable[CookieOptions](null)
implicit def cookieOptions: CookieOptions = _cookieOptions.value
private val _cookies = new DynamicVariable[SweetCookies](null)
def cookies = _cookies.value
abstract override def handle(req: HttpServletRequest, res: HttpServletResponse) {
_cookies.withValue(new SweetCookies(req.cookies, res)) {
_cookieOptions.withValue(CookieOptions(path = req.getContextPath)) {
super.handle(req, res)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment