fix: allow multiple set-cookie headers to be set before render (#2357)

closes #2346

The primary issue was the snippet `headers[key] = value`. This caused
only one `set-cookie` to make it through. Switching to a `Headers`
object allowed me to use `append` when appropriate, allowing for
multiple `set-cookie` entries.

I also cleaned up one of the tests to make use of steps, because I
originally broke it and couldn't immediately tell which part was
failing.
This commit is contained in:
Reed von Redwitz
2024-03-12 12:04:42 +01:00
committed by GitHub
parent b7281792a0
commit 5ec06350e2
5 changed files with 58 additions and 19 deletions
+3
View File
@@ -1,5 +1,8 @@
{
"lock": false,
"tasks": {
"start": "deno run -A --watch=static/,routes/ dev.ts"
},
"imports": {
"$fresh/": "../../",
"preact": "https://esm.sh/preact@10.19.6",
+2
View File
@@ -2,6 +2,7 @@
// This file SHOULD be checked into source version control.
// This file is automatically updated during development when running `dev.ts`.
import * as $cookiePasser from "./routes/cookiePasser.tsx";
import * as $head_style from "./routes/head_style.tsx";
import * as $header_arr from "./routes/header_arr.tsx";
import * as $header_instance from "./routes/header_instance.tsx";
@@ -12,6 +13,7 @@ import { type Manifest } from "$fresh/server.ts";
const manifest = {
routes: {
"./routes/cookiePasser.tsx": $cookiePasser,
"./routes/head_style.tsx": $head_style,
"./routes/header_arr.tsx": $header_arr,
"./routes/header_instance.tsx": $header_instance,
@@ -0,0 +1,18 @@
import { FreshContext, Handlers } from "$fresh/server.ts";
export const handler: Handlers = {
async GET(_req: Request, ctx: FreshContext) {
const headers = new Headers();
headers.append("Set-Cookie", "foo=bar");
headers.append("Set-Cookie", "baz=1234");
return await ctx.render({}, { headers });
},
};
export default function Home() {
return (
<div>
hello
</div>
);
}