scamper.http.cookies

Members list

Type members

Classlikes

sealed trait Cookie

Defines HTTP cookie.

Defines HTTP cookie.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
sealed trait CookieStore

Provides utilities for persistent cookies.

Provides utilities for persistent cookies.

Attributes

See also
Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Null.type
object CookieStore

Provides factory for CookieStore.

Provides factory for CookieStore.

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
sealed trait PersistentCookie extends Cookie

Persistent cookie in CookieStore.

Persistent cookie in CookieStore.

Attributes

Supertypes
trait Cookie
class Object
trait Matchable
class Any
trait PlainCookie extends Cookie

Defines HTTP request cookie.

Defines HTTP request cookie.

Attributes

See also
Companion
object
Supertypes
trait Cookie
class Object
trait Matchable
class Any
object PlainCookie

Provides factory for PlainCookie.

Provides factory for PlainCookie.

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
final class RequestCookies(request: HttpRequest) extends AnyVal

Adds standardized access to cookies in Cookie header.

Adds standardized access to cookies in Cookie header.

In HttpRequest, cookies are stringed together in the Cookie header. You can access them using extension methods provided by RequestCookies, with each cookie represented as PlainCookie.

import scala.language.implicitConversions

import scamper.http.RequestMethod.Registry.Get
import scamper.http.cookies.{ PlainCookie, toRequestCookies }
import scamper.http.stringToUri

// Build request with cookies
val req = Get("https://localhost:8080/motd").setCookies(
 PlainCookie("ID", "bG9zCg"), PlainCookie("Region", "SE-US")
)

// 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"))

Attributes

Supertypes
class AnyVal
trait Matchable
class Any
final class ResponseCookies(response: HttpResponse) extends AnyVal

Adds standardized access to cookies in Set-Cookie headers.

Adds standardized access to cookies in Set-Cookie headers.

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 scala.language.implicitConversions

import scamper.http.ResponseStatus.Registry.Ok
import scamper.http.cookies.{ SetCookie, toResponseCookies }
import scamper.http.stringToEntity

// Build response with cookies
val res = Ok("There is an answer.").setCookies(
 SetCookie("ID", "bG9zCg", path = Some("/motd"), secure = true),
 SetCookie("Region", "SE-US")
)

// 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"))

Attributes

Supertypes
class AnyVal
trait Matchable
class Any
trait SetCookie extends Cookie

Defines HTTP response cookie.

Defines HTTP response cookie.

Attributes

See also
Companion
object
Supertypes
trait Cookie
class Object
trait Matchable
class Any
object SetCookie

Provides factory for SetCookie.

Provides factory for SetCookie.

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
SetCookie.type

Givens

Givens

Adds standardized access to cookies in Cookie header.

Adds standardized access to cookies in Cookie header.

Attributes

Adds standardized access to cookies Set-Cookie headers.

Adds standardized access to cookies Set-Cookie headers.

Attributes