fix: trailingSlash option (#1426)
This commit is contained in:
@@ -0,0 +1 @@
|
||||
bar
|
||||
@@ -1,3 +1,4 @@
|
||||
import { INTERNAL_PREFIX } from "../runtime.ts";
|
||||
import { ServerContext, Status } from "../server.ts";
|
||||
import { assert, assertEquals } from "./deps.ts";
|
||||
import manifest from "./fixture_router/fresh.gen.ts";
|
||||
@@ -30,3 +31,30 @@ Deno.test("forwards slash placed at the end of url", async () => {
|
||||
// forwarded location should be with trailing slash
|
||||
assertEquals(resp.headers.get("location"), targetUrl + "/");
|
||||
});
|
||||
|
||||
Deno.test("forwards slash placed at the end of url with hash and query string", async () => {
|
||||
const targetUrl = "https://fresh.deno.dev/about";
|
||||
const queryAndHash = "?demo=test#what";
|
||||
const resp = await router(new Request(targetUrl + queryAndHash));
|
||||
assert(resp);
|
||||
assertEquals(resp.status, Status.PermanentRedirect);
|
||||
// forwarded location should be with trailing slash
|
||||
assertEquals(resp.headers.get("location"), targetUrl + "/" + queryAndHash);
|
||||
});
|
||||
|
||||
Deno.test("forwards slash not placed at the end of url with prefix", async () => {
|
||||
const targetUrl = `https://fresh.deno.dev${INTERNAL_PREFIX}/no_redirect`;
|
||||
const resp = await router(new Request(targetUrl));
|
||||
assert(resp);
|
||||
// we should get a 404 and not a redirect
|
||||
assertEquals(resp.status, Status.NotFound);
|
||||
});
|
||||
|
||||
Deno.test("forwards slash not placed at the end of url for static file", async () => {
|
||||
const targetUrl = `https://fresh.deno.dev/foo.txt`;
|
||||
const resp = await router(new Request(targetUrl));
|
||||
assert(resp);
|
||||
// we should not be getting a redirect
|
||||
assertEquals(resp.status, Status.OK);
|
||||
assertEquals(await resp.text(), "bar");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user