fixing compression

This commit is contained in:
Rizky 2024-12-11 11:17:14 +07:00
parent f3d020b031
commit e93779ebf7
4 changed files with 16 additions and 13 deletions

BIN
bun.lockb

Binary file not shown.

BIN
data/sqlite/session.db Normal file

Binary file not shown.

View File

@ -87,21 +87,23 @@ export const createResponse = (
} }
} }
if (opt?.high_compression) { if (opt.cache_accept.toLowerCase().includes("gz")) {
if (!cached && opt.cache_accept.toLowerCase().includes("gz")) { if (opt?.high_compression) {
const content_hash = simpleHash(content); if (!cached) {
if (!g.cache.gz[content_hash]) { const content_hash = simpleHash(content);
g.cache.gz[content_hash] = Bun.gzipSync(content); if (!g.cache.gz[content_hash]) {
} g.cache.gz[content_hash] = Bun.gzipSync(content);
if (g.cache.gz[content_hash]) { }
cached = true; if (g.cache.gz[content_hash]) {
content = g.cache.gz[content_hash]; cached = true;
headers["content-encoding"] = "gzip"; content = g.cache.gz[content_hash];
headers["content-encoding"] = "gzip";
}
} }
} else {
content = Bun.gzipSync(content);
headers["content-encoding"] = "gzip";
} }
} else {
content = Bun.gzipSync(content);
headers["content-encoding"] = "gzip";
} }
} }

View File

@ -79,6 +79,7 @@ export const createServer = async () => {
const url = new URL(req.url) as URL; const url = new URL(req.url) as URL;
url.pathname = url.pathname.replace(/\/+/g, "/"); url.pathname = url.pathname.replace(/\/+/g, "/");
const prasi = {}; const prasi = {};
const index = prodIndex(g.deploy.config.site_id, prasi); const index = prodIndex(g.deploy.config.site_id, prasi);