Mostly so that it's easier to cut the next patch release for Fresh.
This reverts commit e3508c3054.
This commit is contained in:
+6
-27
@@ -114,31 +114,6 @@ export async function getServerContext(state: InternalFreshState) {
|
||||
);
|
||||
}
|
||||
|
||||
function redirectTo(pathOrUrl: string = "/", status = 302): Response {
|
||||
let location = pathOrUrl;
|
||||
|
||||
// Disallow protocol relative URLs
|
||||
if (pathOrUrl !== "/" && pathOrUrl.startsWith("/")) {
|
||||
let idx = pathOrUrl.indexOf("?");
|
||||
if (idx === -1) {
|
||||
idx = pathOrUrl.indexOf("#");
|
||||
}
|
||||
|
||||
const pathname = idx > -1 ? pathOrUrl.slice(0, idx) : pathOrUrl;
|
||||
const search = idx > -1 ? pathOrUrl.slice(idx) : "";
|
||||
|
||||
// Remove double slashes to prevent open redirect vulnerability.
|
||||
location = `${pathname.replaceAll(/\/+/g, "/")}${search}`;
|
||||
}
|
||||
|
||||
return new Response(null, {
|
||||
status,
|
||||
headers: {
|
||||
location,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export class ServerContext {
|
||||
#renderFn: RenderFunction;
|
||||
#plugins: Plugin[];
|
||||
@@ -308,7 +283,6 @@ export class ServerContext {
|
||||
ctx.data = data;
|
||||
return await renderNotFound(req, ctx);
|
||||
},
|
||||
redirect: redirectTo,
|
||||
route: "",
|
||||
get pattern() {
|
||||
return ctx.route;
|
||||
@@ -635,7 +609,12 @@ export class ServerContext {
|
||||
if (key !== null && BUILD_ID !== key) {
|
||||
url.searchParams.delete(ASSET_CACHE_BUST_KEY);
|
||||
const location = url.pathname + url.search;
|
||||
return redirectTo(location, 307);
|
||||
return new Response(null, {
|
||||
status: 307,
|
||||
headers: {
|
||||
location,
|
||||
},
|
||||
});
|
||||
}
|
||||
const headers = new Headers({
|
||||
"content-type": contentType,
|
||||
|
||||
+1
-2
@@ -157,7 +157,7 @@ export type PageProps<T = any, S = Record<string, unknown>> = Omit<
|
||||
S,
|
||||
T
|
||||
>,
|
||||
"render" | "next" | "renderNotFound" | "redirect"
|
||||
"render" | "next" | "renderNotFound"
|
||||
>;
|
||||
|
||||
export interface StaticFile {
|
||||
@@ -206,7 +206,6 @@ export interface FreshContext<
|
||||
) => Response | Promise<Response>;
|
||||
Component: ComponentType<unknown>;
|
||||
next: () => Promise<Response>;
|
||||
redirect: (path: string, statusCode?: number) => Response;
|
||||
}
|
||||
/**
|
||||
* Context passed to async route components.
|
||||
|
||||
Reference in New Issue
Block a user