package cookies
Provides specialized access to message cookies.
Request Cookies
In HttpRequest, cookies are stringed together in the Cookie header. You can access them using the extension methods provided by RequestCookies, with each cookie represented as PlainCookie.
import scamper.Implicits.stringToUri import scamper.RequestMethod.Registry.GET import scamper.cookies.{ PlainCookie, RequestCookies } // Build request with cookies val req = GET("https://localhost:8080/motd").withCookies( PlainCookie("ID", "bG9zCg"), PlainCookie("Region", "SE-US") ) // Access and print all cookies req.cookies.foreach(println) // Get cookies by name val id: Option[PlainCookie] = req.getCookie("ID") val region: Option[PlainCookie] = req.getCookie("Region") // Get cookie values by name assert(req.getCookieValue("ID").contains("bG9zCg")) assert(req.getCookieValue("Region").contains("SE-US"))
Response Cookies
In HttpResponse, the cookies are a collection of Set-Cookie header values. Specialized access is provided by ResponseCookies, with each cookie represented as SetCookie.
import scamper.Implicits.stringToEntity import scamper.ResponseStatus.Registry.Ok import scamper.cookies.{ ResponseCookies, SetCookie } // Build response with cookies val res = Ok("There is an answer.").withCookies( SetCookie("ID", "bG9zCg", path = Some("/motd"), secure = true), SetCookie("Region", "SE-US") ) // Access and print all cookies res.cookies.foreach(println) // Get cookies by name val id: Option[SetCookie] = res.getCookie("ID") val region: Option[SetCookie] = res.getCookie("Region") // Get attributes of ID cookie val path: String = id.flatMap(_.path).getOrElse("/") val secure: Boolean = id.map(_.secure).getOrElse(false) // Get cookie values by name assert(res.getCookieValue("ID").contains("bG9zCg")) assert(res.getCookieValue("Region").contains("SE-US"))
- Alphabetic
- By Inheritance
- cookies
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- sealed trait Cookie extends AnyRef
HTTP Cookie
- trait PlainCookie extends Cookie
HTTP request cookie
HTTP request cookie
- See also
- implicit final class RequestCookies extends AnyVal
Provides access to request cookies in
Cookie
header. - implicit final class ResponseCookies extends AnyVal
Provides access to response cookies in
Set-Cookie
headers. - trait SetCookie extends Cookie
HTTP response cookie
HTTP response cookie
- See also
Value Members
- object PlainCookie
PlainCookie factory
- object SetCookie
SetCookie factory