Skip to content

Commit b5319f5

Browse files
committed
redirect Response with multiple Set-Cookie headers
1 parent d887855 commit b5319f5

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/start": patch
3+
---
4+
5+
redirect Response with multiple Set-Cookie headers

packages/start/src/server/handler.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import middleware from "solid-start:middleware";
21
import { defineHandler, getCookie, H3, type H3Event, redirect, setCookie } from "h3";
32
import { join } from "pathe";
43
import type { JSX } from "solid-js";
54
import { sharedConfig } from "solid-js";
65
import { getRequestEvent, renderToStream, renderToString } from "solid-js/web";
6+
import middleware from "solid-start:middleware";
77

88
import { createRoutes } from "../router.tsx";
99
import { decorateHandler, decorateMiddleware } from "./fetchEvent.ts";
1010
import { getSsrManifest } from "./manifest/ssr-manifest.ts";
1111
import { matchAPIRoute } from "./routes.ts";
1212
import { handleServerFunction } from "./server-functions-handler.ts";
1313
import type {
14-
APIEvent,
15-
FetchEvent,
16-
HandlerOptions,
17-
PageEvent,
14+
APIEvent,
15+
FetchEvent,
16+
HandlerOptions,
17+
PageEvent,
1818
} from "./types.ts";
1919
import { getExpectedRedirectStatus } from "./util.ts";
2020

@@ -235,15 +235,32 @@ function produceResponseWithEventHeaders(res: Response) {
235235

236236
// Response.redirect returns an immutable value, so we clone on any redirect just in case
237237
if(300 <= res.status && res.status < 400) {
238+
const cookies = res.headers.getSetCookie?.() ?? [];
239+
const headers = new Headers();
240+
res.headers.forEach((value, key) => {
241+
if (key.toLowerCase() !== 'set-cookie') {
242+
headers.set(key, value);
243+
}
244+
});
245+
for (const cookie of cookies) {
246+
headers.append('Set-Cookie', cookie);
247+
}
238248
ret = new Response(res.body, {
239249
status: res.status,
240250
statusText: res.statusText,
241-
headers: Object.fromEntries(res.headers.entries())
251+
headers,
242252
});
243253
}
244254

255+
const eventCookies = event.response.headers.getSetCookie?.() ?? [];
256+
for (const cookie of eventCookies) {
257+
ret.headers.append('Set-Cookie', cookie);
258+
}
259+
245260
for(const [name, value] of event.response.headers) {
246-
ret.headers.set(name, value);
261+
if (name.toLowerCase() !== 'set-cookie') {
262+
ret.headers.set(name, value);
263+
}
247264
}
248265

249266
return ret

0 commit comments

Comments
 (0)