fix
This commit is contained in:
parent
5e90332489
commit
904585868a
|
|
@ -54,7 +54,7 @@ export const createResponse = (
|
|||
cache_accept?: string;
|
||||
headers?: any;
|
||||
res?: any;
|
||||
br?: boolean;
|
||||
high_compression?: boolean;
|
||||
}
|
||||
) => {
|
||||
const status =
|
||||
|
|
@ -64,7 +64,10 @@ export const createResponse = (
|
|||
const headers = { ...(opt?.headers || {}) } as Record<string, string>;
|
||||
if (opt?.cache_accept) {
|
||||
let cached = false;
|
||||
if (opt?.br && opt.cache_accept.toLowerCase().includes("br")) {
|
||||
if (
|
||||
opt?.high_compression &&
|
||||
opt.cache_accept.toLowerCase().includes("br")
|
||||
) {
|
||||
const content_hash = simpleHash(content);
|
||||
|
||||
if (!g.cache.br[content_hash]) {
|
||||
|
|
@ -78,6 +81,7 @@ export const createResponse = (
|
|||
}
|
||||
}
|
||||
|
||||
if (opt?.high_compression) {
|
||||
if (!cached && opt.cache_accept.toLowerCase().includes("gz")) {
|
||||
const content_hash = simpleHash(content);
|
||||
|
||||
|
|
@ -91,6 +95,10 @@ export const createResponse = (
|
|||
headers["content-encoding"] = "gzip";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
content = Bun.gzipSync(content);
|
||||
headers["content-encoding"] = "gzip";
|
||||
}
|
||||
}
|
||||
|
||||
let res = new Response(
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ export const serveWeb = async (arg: {
|
|||
const type = mime.getType(arg.pathname);
|
||||
return createResponse(arg.content, {
|
||||
cache_accept: arg.cache_accept,
|
||||
br: true,
|
||||
high_compression: true,
|
||||
headers: !type ? undefined : { "content-type": type },
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue