scoop:scoop.http:0.1.0
src/cookie/expiry.scoop
Selected production source · src/cookie/expiry.scoop
1
package scoop.http3
import scoop.time.Instant5
internal 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 -> None13
case Some(val date) -> {14
val limit = cookieDeadline(now, maximum)15
Some(if (date > limit) limit else date)16
}17
}18
}20
private fun cookieDeadline(now: Instant, seconds: Long): Instant =21
if (seconds > Instant.MAX.epochSeconds - now.epochSeconds) Instant.MAX22
else Instant.fromEpochSeconds(now.epochSeconds + seconds, now.nanosecondsOfSecond.toLong())