KTOR-9805 use in cookies a custom expires parser - #5878
Evgeny Usorov (eusorov) wants to merge 2 commits into
Conversation
|
CI failures are unrelated flakes in ktor-client-tests and 'Read timed out' on JS build. Pls rerun the affected builds |
Bruce Hamilton (bjhham)
left a comment
There was a problem hiding this comment.
Maybe in addition, it would make sense to include the "0" case in the default parser, since this is fairly common convention, and the parser already has quite a bit of leniency built in.
|
Happy to add it — One scoping question first: should it go in Two things worth flagging either way:
and also worth to mention that here KTOR-7964 the same was requested but then ticket was closed with a bulk closing action. |
|
It should go under |
added that behaviour |


KTOR-9805 HttpCookies: Allow configuring a custom Expires parser
Subsystem
Client,
ktor-client-core,ktor-httpMotivation
Some servers send nonstandard
Set-Cookiedates — commonlyExpires=0, meaning "delete this cookie now". Ktor can't parse those and leavesexpires = null. With noMax-Age, storage derives no lifetime and treats the cookie as a session cookie, holding it and resending it for the rest of the session — the opposite of what the server asked.HttpCookies.Configoffers no date hook, and widening the built-in parser isn't safe:0means epoch-delete to one server and is invalid to another, so the interpretation belongs to the application.Solution
Let the application supply the parser:
nullreturn can't silently reinstate a date the application rejected.nullor throwing leavesexpiresunset and keeps the cookie, preserving the KTOR-9235 contract that a bad date never fails the response;Max-Agestill takes precedence and storage is unchanged.HttpCookies.Config.expiresParser, plusparseServerSetCookieHeader(header, parser)andHttpMessage.setCookie(parser)inktor-httpfor use without the plugin.Max-Ageprecedence, and receive/store/resend.