Skip to content

Commit 499de6a

Browse files
donnabelseybrunns
andauthored
fix: Handle location header array with a single value without emitting warning (#1016)
Co-authored-by: Simon Brunning <[email protected]>
1 parent 1cbdc04 commit 499de6a

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

.changeset/slimy-squids-juggle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/aws": patch
3+
---
4+
5+
fix: Handle location header array with a single value without emitting warning

packages/open-next/src/http/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const parseHeaders = (
2323
* and https://github.com/opennextjs/opennextjs-aws/pull/977#issuecomment-3261763114
2424
*/
2525
if (keyLower === "location" && Array.isArray(value)) {
26-
if (value[0] === value[1]) {
26+
if (value.length === 1 || value[0] === value[1]) {
2727
result[keyLower] = value[0];
2828
} else {
2929
logger.warn(

packages/tests-unit/tests/http/utils.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,20 @@ describe("parseHeaders", () => {
6565
"x-opennext": "is-so-cool",
6666
});
6767
});
68+
69+
it("handles location header array with a single value", () => {
70+
const headers = parseHeaders({
71+
location: ["/target"],
72+
"x-custom-header": "customValue",
73+
"x-multiple-values": ["value1", "value2"],
74+
"x-undefined-header": undefined,
75+
"x-opennext": "is-so-cool",
76+
} as unknown as http.OutgoingHttpHeaders);
77+
expect(headers).toEqual({
78+
location: "/target",
79+
"x-custom-header": "customValue",
80+
"x-multiple-values": "value1,value2",
81+
"x-opennext": "is-so-cool",
82+
});
83+
});
6884
});

0 commit comments

Comments
 (0)