Scoop API

scoop:scoop.http:0.1.0

src/cookie/expiry.scoop

Selected production source · src/cookie/expiry.scoop

1package scoop.http
3import scoop.time.Instant
5internal fun cookieExpiry(expires: Instant?, maxAge: Long?, now: Instant, maximum: Long): Instant? {
6 if (maximum < 0L) throw IllegalArgumentException(Some("negative Cookie lifetime limit"))
7 when (maxAge) {
8 case Some(val seconds) -> return Some(if (seconds <= 0L) Instant.MIN else cookieDeadline(now, if (seconds > maximum) maximum else seconds))
9 case None -> {}
10 }
11 return when (expires) {
12 case None -> None
13 case Some(val date) -> {
14 val limit = cookieDeadline(now, maximum)
15 Some(if (date > limit) limit else date)
16 }
17 }
20private fun cookieDeadline(now: Instant, seconds: Long): Instant =
21 if (seconds > Instant.MAX.epochSeconds - now.epochSeconds) Instant.MAX
22 else Instant.fromEpochSeconds(now.epochSeconds + seconds, now.nanosecondsOfSecond.toLong())