Skip to content

Conversation

anonrig
Copy link
Contributor

@anonrig anonrig commented Oct 10, 2025

Let's make sure that we don't copy all of the headers, just to mutate it.

Part of #1002

Copy link

changeset-bot bot commented Oct 10, 2025

🦋 Changeset detected

Latest commit: a955067

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

This PR includes changesets to release 2 packages
Name Type
@opennextjs/aws Patch
app-pages-router 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

Copy link

pkg-pr-new bot commented Oct 10, 2025

Open in StackBlitz

pnpm add https://pkg.pr.new/@opennextjs/aws@1008

commit: ab980f0

Copy link
Contributor

@conico974 conico974 left a comment

Choose a reason for hiding this comment

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

We need to check, I might be wrong, but in some cases we can pass the result of a fetch directly here, and in this case the headers are immutable.

for (const cookie of cookies) {
responseHeaders.append("Set-Cookie", cookie);
}
headers["set-cookie"] = cookies.join(",");
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that's wrong.
I you have a=1,b=2 it will create a single a cookie with the value 1,b=2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

> let a = new Headers()
undefined
> a.append('set-cookie', 1)
undefined
> a.append('set-cookie', 2)
undefined
> a
Headers { 'set-cookie': '1, 2' }

This is true. Other than the missing extra space

Copy link
Contributor

Choose a reason for hiding this comment

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

image

Copy link
Contributor

Choose a reason for hiding this comment

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

^ with a space

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
headers["set-cookie"] = cookies.join(",");
headers["set-cookie"] = cookies.join(", ");

Copy link
Contributor

Choose a reason for hiding this comment

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

@anonrig Looks like the actual syntax would be: a="1";b="2" (quotes required)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. Let me fix it.

Copy link
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

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

see inline comments

@anonrig anonrig force-pushed the yagiz/avoid-creating-unnecessary-headers-instance branch from ad2c46b to a955067 Compare October 10, 2025 17:41
// Build headers array - set-cookie must be added separately for each cookie
const headerEntries: [string, string][] = Object.entries(headers);
for (const cookie of cookies) {
headerEntries.push(["set-cookie", cookie]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm.. while this might be more efficient I'm not convinced this is right. This is going to end up skipping any kind of validation on the value of cookie, which could end up causing problems elsewhere.

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.

4 participants