Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cookies): be able to split set-cookie without getAll #255

Merged
merged 2 commits into from
Feb 7, 2023

Conversation

balazsorban44
Copy link
Member

@balazsorban44 balazsorban44 commented Feb 6, 2023

Currently, if a user sets multiple cookies in a series, only the second cookie is set in the set-cookie header.

When this is merged, I will update https://github.com/vercel/next.js/tree/canary/packages/next/src/server/web/spec-extension/cookies to drop the code and use the pre-compiled version of this package again.

Slack thread 1, Slack thread 2

@changeset-bot
Copy link

changeset-bot bot commented Feb 6, 2023

🦋 Changeset detected

Latest commit: efb3789

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@edge-runtime/cookies Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Feb 6, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
edge-runtime ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 6, 2023 at 11:13PM (UTC)

Copy link
Member

@feugy feugy left a comment

Choose a reason for hiding this comment

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

Works well!

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

Choose a reason for hiding this comment

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

praise: Thanks for removing this hard dependency on getAll()!! I banged onto it while working on isomorphic, but I had to stop for changing priorities. Thanks a million!

* Based on: https://github.com/google/j2objc/commit/16820fdbc8f76ca0c33472810ce0cb03d20efe25
* Credits to: https://github.com/tomball for original and https://github.com/chrusart for JavaScript implementation
*/
function splitCookiesString(cookiesString: string) {
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: we already have this function in packages/node-utils/src/edge-to-node/headers. Can we share it between the two packages? maybe a third package called internals-utils? @Kikobeats, @javivelasco, what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

yes, we can create a package for that, also for testing it properly.

Copy link
Member

@feugy feugy left a comment

Choose a reason for hiding this comment

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

Seen with @Kikobeats, let's merge this as is, we'll do the code sharing in subsequent work.

Thanks again!

@Kikobeats Kikobeats merged commit e8e5d5f into vercel:main Feb 7, 2023
@github-actions github-actions bot mentioned this pull request Feb 7, 2023
jridgewell pushed a commit to jridgewell/edge-runtime that referenced this pull request Jun 23, 2023
)

* fix(cookies): be able to split `set-cookie` without `getAll`

* Update pnpm-lock.yaml
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.

3 participants