Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Aug 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-crews-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-cloudflare-workers': patch
---

Support assigning multiple values to a header
21 changes: 20 additions & 1 deletion packages/adapter-cloudflare-workers/files/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}