Skip to content

Conversation

@luojiyin1987
Copy link

Summary

  • Implement cookie deduplication based on RFC 6265 Section 4.1
  • Cookies with the same identity (name + domain + path) are now deduplicated, keeping only the last value set
  • Domain comparison is case-insensitive per RFC 6265

Fixes #4445

Changes

  • parseSetCookieHeader: Parse Set-Cookie string to extract name/domain/path
  • getSetCookies: Get all Set-Cookie headers (with fallback for older environments)
  • isSameCookie: Compare cookie identity using composite key
  • replaceSetCookieHeaders: Remove existing cookies with matching identity
  • Updated setCookie and setSignedCookie to dedupe before setting

Test plan

  • Same name cookies are deduped to last value
  • Different domain cookies with same name are preserved
  • Different path cookies with same name are preserved
  • Mixed cookies dedupe correctly
  • All existing cookie tests pass

🤖 Generated with Claude Code

@codecov
Copy link

codecov bot commented Dec 14, 2025

Codecov Report

❌ Patch coverage is 54.41176% with 62 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.12%. Comparing base (fe278e9) to head (a091ebf).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/helper/cookie/index.ts 54.41% 62 Missing ⚠️

❌ Your patch check has failed because the patch coverage (54.41%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4576      +/-   ##
==========================================
- Coverage   91.56%   91.12%   -0.45%     
==========================================
  Files         172      172              
  Lines       11255    11391     +136     
  Branches     3265     3289      +24     
==========================================
+ Hits        10306    10380      +74     
- Misses        948     1010      +62     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

luojiyin1987 and others added 3 commits December 15, 2025 10:24
  - Add tests for setSignedCookie deduplication with secure/host prefixes
  - Add tests for domain case-insensitivity per RFC 6265
  - Add tests for getSetCookies fallback when getSetCookie unavailable
  - Add tests for getSignedCookie with secure/host prefixes
  - Add edge case tests for cookies with different domains/paths
  - Improve patch coverage from 54.41% to 99.47%
- Remove risky Headers.prototype mock tests (race condition in parallel)
- Add cookie name case-sensitivity test
- Add tests for flags (HttpOnly/Secure/SameSite) not affecting identity
- Add tests for MaxAge not affecting identity
- Add tests for prefix vs no-prefix not being deduped
- Add tests for __Secure- vs __Host- prefix not being deduped
- Add complex combination and special character tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add helper functions: readSetCookies, cookieNameValue, responseCookies
- Add createStubContext() to avoid modifying global Headers.prototype
- Add expectCookieSetEqual() for order-independent cookie comparison
- Replace string assertions with array-based cookie assertions
- Improve type safety with HeadersWithSetCookie type

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
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.

setCookie on the same key multiple times is not deduped

1 participant