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(cache): allow setting multiple set-cookie headers (bad practice) #1838

Merged
merged 3 commits into from
Oct 18, 2023
Merged
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
12 changes: 11 additions & 1 deletion src/runtime/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
createEvent,
EventHandler,
isEvent,
splitCookiesString,
} from "h3";
import type { EventHandlerRequest, EventHandlerResponse, H3Event } from "h3";
import { parseURL } from "ufo";
Expand Down Expand Up @@ -404,7 +405,16 @@ export function defineCachedEventHandler<
// Send status and headers
event.node.res.statusCode = response.code;
for (const name in response.headers) {
event.node.res.setHeader(name, response.headers[name]);
const value = response.headers[name];
if (name === "set-cookie") {
// TODO: Show warning and remove this header in the next major version of Nitro
event.node.res.appendHeader(
pi0 marked this conversation as resolved.
Show resolved Hide resolved
name,
splitCookiesString(value as string[])
);
} else {
event.node.res.setHeader(name, value);
}
}

// Send body
Expand Down