fix: ctx.render headers not working (#1927)

This commit is contained in:
Marvin Hagemeister
2023-10-12 23:30:18 +02:00
committed by GitHub
parent 8d90c0ec81
commit bb8921ac85
10 changed files with 165 additions and 2 deletions
+17 -1
View File
@@ -1422,9 +1422,25 @@ function sendResponse(
headers["content-security-policy"] = directive;
}
}
if (options.headers) {
if (Array.isArray(options.headers)) {
for (let i = 0; i < options.headers.length; i++) {
const item = options.headers[i];
headers[item[0]] = item[1];
}
} else if (options.headers instanceof Headers) {
options.headers.forEach((value, key) => {
headers[key] = value;
});
} else {
Object.assign(headers, options.headers);
}
}
return new Response(body, {
status: options.status,
statusText: options.statusText,
headers: options.headers ? { ...headers, ...options.headers } : headers,
headers,
});
}