fix(server): compress responses with correct content types (#44321)

This commit is contained in:
Brendan Allan
2026-08-23 14:18:20 +08:00
committed by GitHub
Unverified
parent b7167aaab0
commit b8fb894ec7
4 changed files with 42 additions and 7 deletions
+3 -1
View File
@@ -42,7 +42,9 @@ function serveUI(request: HttpServerRequest.HttpServerRequest, url: URL, assets:
"x-content-type-options": "nosniff",
}
return Effect.succeed(
request.method === "HEAD" ? HttpServerResponse.empty({ headers }) : HttpServerResponse.raw(file, { headers }),
request.method === "HEAD"
? HttpServerResponse.empty({ headers })
: HttpServerResponse.raw(file, { headers, contentType: headers["content-type"] }),
)
}
+2
View File
@@ -55,6 +55,7 @@ describe("web UI", () => {
const script = yield* Effect.promise(() => fetch(`${origin}/app.js`))
expect(yield* Effect.promise(() => script.text())).toBe("console.log('embedded')")
expect(script.headers.get("content-type")).toContain("javascript")
expect(script.headers.get("cache-control")).toBe("public, max-age=31536000, immutable")
const worker = yield* Effect.promise(() => fetch(`${origin}/sw.js`))
@@ -64,6 +65,7 @@ describe("web UI", () => {
expect(registration.headers.get("cache-control")).toBe("no-cache")
const font = yield* Effect.promise(() => fetch(`${origin}/font.woff2`))
expect(font.headers.get("content-type")).toBe("font/woff2")
expect(new Uint8Array(yield* Effect.promise(() => font.arrayBuffer()))).toEqual(
new Uint8Array([0, 1, 2, 255]),
)