0.2.1 onlyoffice修复
This commit is contained in:
+17
-1
@@ -29,6 +29,19 @@ const stripHopByHopHeaders = (headers: Headers) => {
|
||||
}
|
||||
};
|
||||
|
||||
const pickCacheControl = (pathParts: string[], contentType: string, method: string) => {
|
||||
const m = String(method || "").toUpperCase();
|
||||
if (m !== "GET" && m !== "HEAD") return "no-store";
|
||||
if (contentType.includes("text/html")) return "no-store";
|
||||
|
||||
const p = `/${(pathParts ?? []).join("/")}`.toLowerCase();
|
||||
// 说明:/cache 主要是 ONLYOFFICE 运行期二进制缓存,适合短缓存提升性能,但不宜过长。
|
||||
if (p.includes("editor.bin") || p.endsWith(".bin")) {
|
||||
return "public, max-age=3600, stale-while-revalidate=600";
|
||||
}
|
||||
return "public, max-age=300, stale-while-revalidate=300";
|
||||
};
|
||||
|
||||
const proxyCache = async (request: NextRequest, pathParts: string[]) => {
|
||||
const incomingUrl = new URL(request.url);
|
||||
const target = new URL(
|
||||
@@ -60,6 +73,10 @@ const proxyCache = async (request: NextRequest, pathParts: string[]) => {
|
||||
stripHopByHopHeaders(outHeaders);
|
||||
outHeaders.delete("content-encoding");
|
||||
outHeaders.delete("content-length");
|
||||
outHeaders.set("cache-control", pickCacheControl(pathParts, upstream.headers.get("content-type") || "", request.method));
|
||||
outHeaders.delete("pragma");
|
||||
outHeaders.delete("expires");
|
||||
outHeaders.delete("set-cookie");
|
||||
|
||||
return new NextResponse(upstream.body, {
|
||||
status: upstream.status,
|
||||
@@ -83,4 +100,3 @@ export async function OPTIONS(request: NextRequest, ctx: RouteCtx) {
|
||||
const { path } = await ctx.params;
|
||||
return proxyCache(request, path ?? []);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user