Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/runtime/internal/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default defineHandler((event) => {
const encodings = [
...encodingHeader
.split(",")
.map((e) => EncodingMap[e.trim() as keyof typeof EncodingMap])
.map((e) => EncodingMap[e.trim().split(";")[0].trim() as keyof typeof EncodingMap])
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
.filter(Boolean)
.sort(),
"",
Expand Down
23 changes: 23 additions & 0 deletions test/unit/static-middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,27 @@ describe("runtime static middleware", () => {
expect(event.res.headers.get("Vary")).toContain("Origin");
expect(event.res.headers.get("Vary")).toContain("Accept-Encoding");
});

it("matches compressed assets when accept-encoding has quality values", async () => {
getAsset.mockImplementation((id: string) => {
if (id === "/foo.css.gz") {
return {
etag: '"test"',
mtime: Date.now(),
type: "text/css",
encoding: "gzip",
size: 1,
};
}
return undefined;
});
isPublicAssetURL.mockReturnValue(true);
readAsset.mockResolvedValue("body");
const event = createEvent("/foo.css", "gzip; q=1.0, br; q=0.9");

await handler(event);

expect(readAsset).toHaveBeenCalledWith("/foo.css.gz");
expect(event.res.headers.get("Content-Encoding")).toBe("gzip");
});
});