Skip to content

Commit 29c9c3c

Browse files
committed
detect multi value headers automatically
1 parent faf758f commit 29c9c3c

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

packages/adapter-netlify/files/entry.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export async function handler(event) {
2929
return {
3030
isBase64Encoded: false,
3131
statusCode: rendered.status,
32-
...splitHeaders(headers, 'set-cookie'),
32+
...splitHeaders(headers),
3333
body: rendered.body
3434
};
3535
}
@@ -43,20 +43,18 @@ export async function handler(event) {
4343
/**
4444
* Splits headers into two categories: single value and multi value
4545
* @param {Record<string, string | string[]>} headers
46-
* @param {...string} fields
4746
* @returns {{
4847
* headers: Record<string, string>,
4948
* multiValueHeaders: Record<string, string[]>
5049
* }}
5150
*/
52-
function splitHeaders(headers, ...fields) {
53-
const h = { ...headers };
51+
function splitHeaders(headers) {
52+
const h = {};
5453
const m = {};
55-
for (const field of fields) {
56-
if (Array.isArray(h[field])) {
57-
m[field] = h[field];
58-
delete h[field];
59-
}
54+
for (const key in headers) {
55+
const value = headers[key];
56+
const target = Array.isArray(value) ? m : h;
57+
target[key] = value;
6058
}
6159
return {
6260
headers: h,

0 commit comments

Comments
 (0)