[fix] adapter-cloudflare-workers: support setting multiple values to a header
ADD
.changeset/quiet-crews-hunt.md
+---
+'@sveltejs/adapter-cloudflare-workers': patch
+---
+
+Support assigning multiple values to a header

MODIFY
packages/adapter-cloudflare-workers/files/entry.js
packages/adapter-cloudflare-workers/files/entry.js
@@ -41,7 +41,7 @@ async function handle(event) {
if (rendered) {
return new Response(rendered.body, {
status: rendered.status,
- headers: rendered.headers
+ headers: makeHeaders(rendered.headers)
});
}
} catch (e) {
@@ -58,3 +58,22 @@ async function handle(event) {
async function read(request) {
return new Uint8Array(await request.arrayBuffer());
}
+
+/**
+ * @param {Record<string, string | string[]>} headers
+ * @returns {Request}
+ */
+function makeHeaders(headers) {
+ const result = new Headers();
+ for (const header in headers) {
+ const value = headers[header];
+ if (typeof value === 'string') {
+ result.set(header, value);
+ continue;
+ }
+ for (const sub of value) {
+ result.append(header, sub);
+ }
+ }
+ return result;
+}

[fix] adapter-cloudflare-workers: support setting multiple values to a header (#2313)