Skip to content

Commit

Permalink
fix: SerializableCookie.hostOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
muedsa committed Nov 28, 2024
1 parent 0c24a28 commit 23ed8b5
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions api/src/main/java/com/muedsa/tvbox/tool/SerializableCookie.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,22 @@ data class SerializableCookie(
hostOnly = cookie.hostOnly,
)

fun from(cookie: HttpCookie): SerializableCookie = SerializableCookie(
name = cookie.name,
value = cookie.value,
expiresAt = if (cookie.maxAge == -1L) 253402300799999L else System.currentTimeMillis() + cookie.maxAge * 1000,
domain = cookie.domain,
path = cookie.path,
secure = cookie.secure,
httpOnly = cookie.isHttpOnly,
persistent = true,
hostOnly = false,
)
fun from(cookie: HttpCookie): SerializableCookie {
val hostOnly = cookie.domain.startsWith(".")
val domain = if (hostOnly) {
cookie.domain.removePrefix(".")
} else cookie.domain
return SerializableCookie(
name = cookie.name,
value = cookie.value,
expiresAt = if (cookie.maxAge == -1L) 253402300799999L else System.currentTimeMillis() + cookie.maxAge * 1000,
domain = domain,
path = cookie.path,
secure = cookie.secure,
httpOnly = cookie.isHttpOnly,
persistent = true,
hostOnly = hostOnly,
)
}
}
}

0 comments on commit 23ed8b5

Please sign in to comment.