Skip to content

Commit 21d2553

Browse files
committed
fix: Handle location header array with a single value without emitting warning
Co-authored with @brunns Related to opennextjs#977
1 parent 1cbdc04 commit 21d2553

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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)