Skip to content

Commit

Permalink
detect multi value headers automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanJPNM committed Jul 14, 2021
1 parent faf758f commit 29c9c3c
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions packages/adapter-netlify/files/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function handler(event) {
return {
isBase64Encoded: false,
statusCode: rendered.status,
...splitHeaders(headers, 'set-cookie'),
...splitHeaders(headers),
body: rendered.body
};
}
Expand All @@ -43,20 +43,18 @@ export async function handler(event) {
/**
* Splits headers into two categories: single value and multi value
* @param {Record<string, string | string[]>} headers
* @param {...string} fields
* @returns {{
* headers: Record<string, string>,
* multiValueHeaders: Record<string, string[]>
* }}
*/
function splitHeaders(headers, ...fields) {
const h = { ...headers };
function splitHeaders(headers) {
const h = {};
const m = {};
for (const field of fields) {
if (Array.isArray(h[field])) {
m[field] = h[field];
delete h[field];
}
for (const key in headers) {
const value = headers[key];
const target = Array.isArray(value) ? m : h;
target[key] = value;
}
return {
headers: h,
Expand Down

0 comments on commit 29c9c3c

Please sign in to comment.