-
Couldn't load subscription status.
- Fork 177
avoid creating unnecessary headers instance #1008
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@opennextjs/aws": patch | ||
| --- | ||
|
|
||
| Avoid creating unnecessary headers instance on every request |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,15 +41,16 @@ const handler: WrapperHandler<InternalEvent, InternalResult> = | |
| }): Writable { | ||
| const { statusCode, cookies, headers } = prelude; | ||
|
|
||
| const responseHeaders = new Headers(headers); | ||
| for (const cookie of cookies) { | ||
| responseHeaders.append("Set-Cookie", cookie); | ||
| } | ||
|
|
||
| // TODO(vicb): this is a workaround to make PPR work with `wrangler dev` | ||
| // See https://github.com/cloudflare/workers-sdk/issues/8004 | ||
| if (url.hostname === "localhost") { | ||
| responseHeaders.set("Content-Encoding", "identity"); | ||
| headers["content-encoding"] = "identity"; | ||
| } | ||
|
|
||
| // 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]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
|
|
||
| const { readable, writable } = new TransformStream({ | ||
|
|
@@ -60,7 +61,7 @@ const handler: WrapperHandler<InternalEvent, InternalResult> = | |
| const body = NULL_BODY_STATUSES.has(statusCode) ? null : readable; | ||
| const response = new Response(body, { | ||
| status: statusCode, | ||
| headers: responseHeaders, | ||
| headers: headerEntries, | ||
| }); | ||
| resolveResponse(response); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this now mutates the headers object coming from outside the function, which changes its behavior (it now has a side effect on the caller values).