[PR #517] [MERGED] fix: add missing set/delete/clear/size/toString to RequestCookies #639

Closed
opened 2026-05-06 13:09:15 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/517
Author: @NathanDrake2406
Created: 3/13/2026
Status: Merged
Merged: 3/13/2026
Merged by: @james-elicx

Base: mainHead: fix/request-cookies-set-delete


📝 Commits (2)

  • b5f6fdd fix: add missing set/delete/clear/size/toString to RequestCookies
  • d1dae48 refactor: DRY up RequestCookies clear/toString/syncHeader

📊 Changes

2 files changed (+225 additions, -7 deletions)

View changed files

📝 packages/vinext/src/shims/server.ts (+57 -7)
📝 tests/shims.test.ts (+168 -0)

📄 Description

Summary

  • The RequestCookies class in server.ts (used by NextRequest.cookies in middleware) was missing set(), delete(), clear(), size, and toString() methods that @edge-runtime/cookies provides
  • Middleware calling cookies.set() or cookies.delete() to forward modified cookies downstream would fail at runtime
  • Caches the parsed cookie map in the constructor instead of re-parsing the Cookie header on every method call
  • Encodes values with encodeURIComponent when syncing back to the Cookie header, preventing round-trip data corruption
  • delete() accepts string | string[] and returns boolean | boolean[] matching @edge-runtime/cookies

Test plan

  • 16 new tests in RequestCookies API describe block covering:
    • set() — add, overwrite, object form, chaining
    • delete() — single name, array of names, return value (boolean/boolean[]), no-op for missing
    • clear() — removes all cookies and clears header
    • size — count, empty
    • toString() — serialization
    • Round-trip encoding with special characters (;, =, %)
    • Percent-encoded value preservation across mutations
    • set() then delete() interaction
  • All 680 shims tests pass
  • Pre-commit: format, lint, typecheck all green

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/517 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 3/13/2026 **Status:** ✅ Merged **Merged:** 3/13/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/request-cookies-set-delete` --- ### 📝 Commits (2) - [`b5f6fdd`](https://github.com/cloudflare/vinext/commit/b5f6fdd683fc146db48a5c91661f68367c9799ae) fix: add missing set/delete/clear/size/toString to RequestCookies - [`d1dae48`](https://github.com/cloudflare/vinext/commit/d1dae48b1706064ed57d3ca8f1252b9bb5e2b731) refactor: DRY up RequestCookies clear/toString/syncHeader ### 📊 Changes **2 files changed** (+225 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/shims/server.ts` (+57 -7) 📝 `tests/shims.test.ts` (+168 -0) </details> ### 📄 Description ## Summary - The `RequestCookies` class in `server.ts` (used by `NextRequest.cookies` in middleware) was missing `set()`, `delete()`, `clear()`, `size`, and `toString()` methods that `@edge-runtime/cookies` provides - Middleware calling `cookies.set()` or `cookies.delete()` to forward modified cookies downstream would fail at runtime - Caches the parsed cookie map in the constructor instead of re-parsing the `Cookie` header on every method call - Encodes values with `encodeURIComponent` when syncing back to the `Cookie` header, preventing round-trip data corruption - `delete()` accepts `string | string[]` and returns `boolean | boolean[]` matching `@edge-runtime/cookies` ## Test plan - [ ] 16 new tests in `RequestCookies API` describe block covering: - `set()` — add, overwrite, object form, chaining - `delete()` — single name, array of names, return value (`boolean`/`boolean[]`), no-op for missing - `clear()` — removes all cookies and clears header - `size` — count, empty - `toString()` — serialization - Round-trip encoding with special characters (`;`, `=`, `%`) - Percent-encoded value preservation across mutations - `set()` then `delete()` interaction - [ ] All 680 shims tests pass - [ ] Pre-commit: format, lint, typecheck all green --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:09:15 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#639
No description provided.