diff --git a/.changeset/slimy-squids-juggle.md b/.changeset/slimy-squids-juggle.md new file mode 100644 index 000000000..b610db5cb --- /dev/null +++ b/.changeset/slimy-squids-juggle.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/aws": patch +--- + +fix: Handle location header array with a single value without emitting warning diff --git a/packages/open-next/src/http/util.ts b/packages/open-next/src/http/util.ts index de3b07de6..19f479b97 100644 --- a/packages/open-next/src/http/util.ts +++ b/packages/open-next/src/http/util.ts @@ -23,7 +23,7 @@ export const parseHeaders = ( * and https://github.com/opennextjs/opennextjs-aws/pull/977#issuecomment-3261763114 */ if (keyLower === "location" && Array.isArray(value)) { - if (value[0] === value[1]) { + if (value.length === 1 || value[0] === value[1]) { result[keyLower] = value[0]; } else { logger.warn( diff --git a/packages/tests-unit/tests/http/utils.test.ts b/packages/tests-unit/tests/http/utils.test.ts index 34f0717dc..79670c555 100644 --- a/packages/tests-unit/tests/http/utils.test.ts +++ b/packages/tests-unit/tests/http/utils.test.ts @@ -65,4 +65,20 @@ describe("parseHeaders", () => { "x-opennext": "is-so-cool", }); }); + + it("handles location header array with a single value", () => { + const headers = parseHeaders({ + location: ["/target"], + "x-custom-header": "customValue", + "x-multiple-values": ["value1", "value2"], + "x-undefined-header": undefined, + "x-opennext": "is-so-cool", + } as unknown as http.OutgoingHttpHeaders); + expect(headers).toEqual({ + location: "/target", + "x-custom-header": "customValue", + "x-multiple-values": "value1,value2", + "x-opennext": "is-so-cool", + }); + }); });