Skip to content

Keep store cookies readable as DefaultCookie - #2413

Open
mkurz wants to merge 1 commit into
AsyncHttpClient:mainfrom
mkurz:fix/store-cookies-as-default-cookies
Open

mkurz wants to merge 1 commit into
AsyncHttpClient:mainfrom
mkurz:fix/store-cookies-as-default-cookies

Conversation

@mkurz

@mkurz mkurz commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Motivation: Since #2409, released in 3.0.15, the client marks the cookies it adds to a request from its cookie store, so that it can drop them when a filter replays or retargets the request. The mark was a plain Cookie wrapper. Code reading Request.getCookies(), for example a request filter, a signature calculator or a handler, therefore got a different type than before: a cast to DefaultCookie failed, and the SameSite and Partitioned attributes of a store cookie could not be read.

Modification:

  • The mark now extends DefaultCookie. Every attribute delegates to the store's cookie, as before.
  • When the store's cookie is a DefaultCookie, SameSite and Partitioned delegate to it too. A cookie store that hands out another Cookie implementation has no such attributes to delegate to, so the mark holds them itself.
  • The documentation of FilterContext.getRequest() now states two consequences of the rules Rebind store cookies when a filter replays or retargets #2409 introduced:
    • A request sent to the same origin in place of the current one does not get back the store's cookies under the names it no longer carries, since a filter is taken to have removed them. So a request built from scratch gets only the store's cookies of other names.
    • Every cookie object a caller or a filter adds counts as theirs and is not taken from the store again, even a copy of a store cookie or the store's own instance.

Result:

  • A store cookie reads as a DefaultCookie again, as in 3.0.14, with the store's SameSite and Partitioned values, and writes still reach the store's cookie.
  • It is still a wrapper: it is not the store's own instance, and not of a custom DefaultCookie subclass the store may use. Equality, ordering and toString are unchanged.
  • Nothing changes on the wire, and Rebind store cookies when a filter replays or retargets #2409's behaviour is otherwise unchanged.

AI disclosure

Claude Code on behalf of Matthias Kurz. The commit includes Co-Authored-By per AGENTS.md.

Test plan

All on JDK 11. Docker was not running, so the skipped tests include the Testcontainers proxy tests.

  • ./mvnw -B -ntp -Dgpg.skip=true clean verify: 2,494 tests, 0 failures, 22 skipped; Revapi passed against 3.0.15.
  • Focused cookie, redirect, filter and replay suites: 117 tests, 0 failures. That run was on main before the release commits.
  • The fix reverted (StoreCookies as on main): the three new tests fail.
    • Two check a store DefaultCookie: one in StoreCookiesTest, one with a request filter over HTTPS.
    • One checks a store cookie of another Cookie type, which keeps SameSite and Partitioned on the mark and writes the rest through.
  • The new tests 5 times, all green; that was before the third test was added.

Since AsyncHttpClient#2409, the client marks the cookies it takes from its cookie
store, and a filter or handler reading a request's cookies gets the
mark instead of the store's DefaultCookie. A cast to DefaultCookie
then fails, and the SameSite and Partitioned attributes the store
holds cannot be read. The mark now extends DefaultCookie and also
delegates those attributes to the store's cookie, so the request
reads as before. Equality, ordering and write-through to the store's
cookie are unchanged.

FilterContext now states two consequences of telling store cookies
by the mark: a request sent to the same origin in place of another
does not get back the store's cookies under the names it dropped, so
one built from scratch gets only those of other names; and every
cookie object a caller or a filter adds is theirs, even the store's
own instance.

Claude Code on behalf of Matthias Kurz

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mkurz

mkurz commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@hyperxpro the failing job is unrelated to this pull request - it's maven central rate limiting problem. can you restart the job? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant