feat: add status and headers overwrite for HandlerContext.render (#725)

This commit is contained in:
Leo Kettmeir
2023-05-31 10:09:53 +02:00
committed by GitHub
parent c172a70181
commit 060e2bb50d
5 changed files with 49 additions and 5 deletions
+4 -2
View File
@@ -34,7 +34,8 @@ import * as $27 from "./routes/not_found.ts";
import * as $28 from "./routes/params.tsx";
import * as $29 from "./routes/props/[id].tsx";
import * as $30 from "./routes/static.tsx";
import * as $31 from "./routes/wildcard.tsx";
import * as $31 from "./routes/status_overwrite.tsx";
import * as $32 from "./routes/wildcard.tsx";
import * as $$0 from "./islands/Counter.tsx";
import * as $$1 from "./islands/ReturningNull.tsx";
import * as $$2 from "./islands/RootFragment.tsx";
@@ -76,7 +77,8 @@ const manifest = {
"./routes/params.tsx": $28,
"./routes/props/[id].tsx": $29,
"./routes/static.tsx": $30,
"./routes/wildcard.tsx": $31,
"./routes/status_overwrite.tsx": $31,
"./routes/wildcard.tsx": $32,
},
islands: {
"./islands/Counter.tsx": $$0,
+14
View File
@@ -0,0 +1,14 @@
import { HandlerContext } from "$fresh/server.ts";
export default function Page() {
return <div>This is HTML</div>;
}
export const handler = {
GET(req: Request, { render }: HandlerContext) {
return render(undefined, {
status: 401,
headers: { "x-some-header": "foo" },
});
},
};
+12
View File
@@ -148,6 +148,18 @@ Deno.test("/intercept_args - GET html", async () => {
assertStringIncludes(body, "<div>intercepted</div>");
});
Deno.test("/status_overwrite", async () => {
const req = new Request("https://fresh.deno.dev/status_overwrite", {
headers: { "accept": "text/html" },
});
const resp = await router(req);
assert(resp);
assertEquals(resp.status, Status.Unauthorized);
assertEquals(resp.headers.get("x-some-header"), "foo");
const body = await resp.text();
assertStringIncludes(body, "<div>This is HTML</div>");
});
Deno.test("/api/get_only - NOTAMETHOD", async () => {
const resp = await router(
new Request("https://fresh.deno.dev/api/get_only", {