Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/fresh/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class Context<State> {
* ctx.redirect("//evil.com/");
* ```
*/
redirect(pathOrUrl: string, status = 302): Response {
redirect(pathOrUrl: string, status = 307): Response {
let location = pathOrUrl;

// Disallow protocol relative URLs
Expand Down
15 changes: 9 additions & 6 deletions packages/fresh/src/context_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,27 @@ import { BUILD_ID } from "@fresh/build-id";
import { parseHtml } from "../tests/test_utils.tsx";

Deno.test("FreshReqContext.prototype.redirect", () => {
// Default status is now 307 to preserve HTTP method on redirect
// See: https://github.com/denoland/fresh/issues/2632
let res = Context.prototype.redirect("/");
expect(res.status).toEqual(302);
expect(res.status).toEqual(307);
expect(res.headers.get("Location")).toEqual("/");

res = Context.prototype.redirect("//evil.com");
expect(res.status).toEqual(302);
expect(res.status).toEqual(307);
expect(res.headers.get("Location")).toEqual("/evil.com");

res = Context.prototype.redirect("//evil.com/foo//bar");
expect(res.status).toEqual(302);
expect(res.status).toEqual(307);
expect(res.headers.get("Location")).toEqual("/evil.com/foo/bar");

res = Context.prototype.redirect("https://deno.com");
expect(res.status).toEqual(302);
expect(res.status).toEqual(307);
expect(res.headers.get("Location")).toEqual("https://deno.com");

res = Context.prototype.redirect("/", 307);
expect(res.status).toEqual(307);
// Explicit 302 still works for backward compatibility
res = Context.prototype.redirect("/", 302);
expect(res.status).toEqual(302);
});

Deno.test("render asset()", async () => {
Expand Down
Loading