Skip to content

Commit

Permalink
fix(cookies): use Headers#getSetCookie when available (#540)
Browse files Browse the repository at this point in the history
Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com>
  • Loading branch information
balazsorban44 and Kikobeats committed Sep 5, 2023
1 parent 14c8a70 commit fb34f31
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
6 changes: 6 additions & 0 deletions .changeset/unlucky-sloths-explode.md
@@ -0,0 +1,6 @@
---
'@edge-runtime/primitives': patch
'@edge-runtime/cookies': patch
---

use `Headers#getSetCookie` when available
11 changes: 5 additions & 6 deletions packages/cookies/src/response-cookies.ts
Expand Up @@ -19,15 +19,14 @@ export class ResponseCookies {
constructor(responseHeaders: Headers) {
this._headers = responseHeaders

const setCookie =
// @ts-expect-error See https://github.com/whatwg/fetch/issues/973
responseHeaders.getAll?.('set-cookie') ??
responseHeaders.get('set-cookie') ??
[]
const setCookie = responseHeaders.getSetCookie?.()
responseHeaders.get('set-cookie') ?? []

const cookieStrings = Array.isArray(setCookie)
? setCookie
: splitCookiesString(setCookie)
: // TODO: remove splitCookiesString when `getSetCookie` adoption is high enough in Node.js
// https://developer.mozilla.org/en-US/docs/Web/API/Headers/getSetCookie#browser_compatibility
splitCookiesString(setCookie)

for (const cookieString of cookieStrings) {
const parsed = parseSetCookie(cookieString)
Expand Down
24 changes: 12 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 comment on commit fb34f31

@vercel
Copy link

@vercel vercel bot commented on fb34f31 Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

edge-runtime – ./

edge-runtime.vercel.app
edge-runtime-git-main.vercel.sh
edge-runtime.vercel.sh

Please sign in to comment.