Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions apps/server/src/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@ describe("assetResponseHeaders", () => {
"X-Content-Type-Options": "nosniff",
});
});

it("declares utf-8 for HTML assets so non-ASCII content renders correctly", () => {
expect(assetResponseHeaders("/workspace/page.html")).toHaveProperty(
"Content-Type",
"text/html; charset=utf-8",
);
expect(assetResponseHeaders("/workspace/PAGE.HTM")).toHaveProperty(
"Content-Type",
"text/html; charset=utf-8",
);
});
});
6 changes: 5 additions & 1 deletion apps/server/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ const DESKTOP_RENDERER_ORIGINS = ["t3code://app", "t3code-dev://app"];
const SVG_CONTENT_SECURITY_POLICY = "default-src 'none'; style-src 'unsafe-inline'; sandbox";

export function assetResponseHeaders(filePath: string): Record<string, string> {
const lowerPath = filePath.toLowerCase();
return {
"Cache-Control": "private, max-age=3600",
"X-Content-Type-Options": "nosniff",
...(filePath.toLowerCase().endsWith(".svg")
...(lowerPath.endsWith(".html") || lowerPath.endsWith(".htm")
? { "Content-Type": "text/html; charset=utf-8" }
: {}),
...(lowerPath.endsWith(".svg")
? { "Content-Security-Policy": SVG_CONTENT_SECURITY_POLICY }
: {}),
};
Expand Down
Loading