diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-07-25 16:58:15 +0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-07-25 16:58:15 +0800 |
commit | 8a7a665f3d6cd386e57a55dcb003d25b76b14138 (patch) | |
tree | 82b439f0e3b3312586efef2fc0d1491095c01454 /cask/src/cask/endpoints | |
parent | 688e69c3ca8f5a39423557a20473b580632c2b33 (diff) | |
download | cask-8a7a665f3d6cd386e57a55dcb003d25b76b14138.tar.gz cask-8a7a665f3d6cd386e57a55dcb003d25b76b14138.tar.bz2 cask-8a7a665f3d6cd386e57a55dcb003d25b76b14138.zip |
collapse `CookieParam` into `Cookie`
Diffstat (limited to 'cask/src/cask/endpoints')
-rw-r--r-- | cask/src/cask/endpoints/Params.scala | 58 |
1 files changed, 45 insertions, 13 deletions
diff --git a/cask/src/cask/endpoints/Params.scala b/cask/src/cask/endpoints/Params.scala index 6ff9dc1..7a56085 100644 --- a/cask/src/cask/endpoints/Params.scala +++ b/cask/src/cask/endpoints/Params.scala @@ -1,27 +1,59 @@ package cask.endpoints -import cask.Cookie import cask.endpoints.ParamReader.NilParam +import io.undertow.server.handlers.CookieImpl class Subpath(val value: Seq[String]) object Subpath{ implicit object SubpathParam extends NilParam[Subpath]((ctx, label) => new Subpath(ctx.remaining)) - -} -class Cookies(val value: Map[String, Cookie]) -object Cookies{ - implicit object CookieParam extends NilParam[Cookies]((ctx, label) => { - import collection.JavaConverters._ - new Cookies(ctx.exchange.getRequestCookies.asScala.toMap.map{case (k, v) => (k, Cookie.fromUndertow(v))}) - }) } -object CookieParam{ - implicit object CookieParamParam extends NilParam[CookieParam]((ctx, label) => - new CookieParam(Cookie.fromUndertow(ctx.exchange.getRequestCookies().get(label))) + + +object Cookie{ + implicit object CookieParam extends NilParam[Cookie]((ctx, label) => + Cookie.fromUndertow(ctx.exchange.getRequestCookies().get(label)) ) + def fromUndertow(from: io.undertow.server.handlers.Cookie): Cookie = { + Cookie( + from.getName, + from.getValue, + from.getComment, + from.getDomain, + if (from.getExpires == null) null else from.getExpires.toInstant, + from.getMaxAge, + from.getPath, + from.getVersion, + from.isDiscard, + from.isHttpOnly, + from.isSecure + ) + } + def toUndertow(from: Cookie): io.undertow.server.handlers.Cookie = { + val out = new CookieImpl(from.name, from.value) + out.setComment(from.comment) + out.setDomain(from.domain) + out.setExpires(if (from.expires == null) null else java.util.Date.from(from.expires)) + out.setMaxAge(from.maxAge) + out.setPath(from.path) + out.setVersion(from.version) + out.setDiscard(from.discard) + out.setHttpOnly(from.httpOnly) + out.setSecure(from.secure) + } } +case class Cookie(name: String, + value: String, + comment: String = null, + domain: String = null, + expires: java.time.Instant = null, + maxAge: Integer = null, + path: String = null, + version: Int = 1, + discard: Boolean = false, + httpOnly: Boolean = false, + secure: Boolean = false) { -case class CookieParam(cookie: Cookie) +} object FormValue{ |