ensure utf8 encoding when serving html (#2654)
* ensure utf8 encoding on servers * Create spicy-tomatoes-act.md * Update spicy-tomatoes-act.md Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
parent
2e5c3b5126
commit
a0fc5cb5ff
3 changed files with 9 additions and 4 deletions
5
.changeset/spicy-tomatoes-act.md
Normal file
5
.changeset/spicy-tomatoes-act.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
Fix an issue where utf8 encoding was skipped in the dev server.
|
|
@ -18,7 +18,8 @@ async function handle(req, res) {
|
|||
const html = await app.render(req, route);
|
||||
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/html',
|
||||
'Content-Type': 'text/html; charset=utf-8',
|
||||
'Content-Length': Buffer.byteLength(html, 'utf-8'),
|
||||
});
|
||||
res.end(html);
|
||||
} else if (/^\/api\//.test(req.url)) {
|
||||
|
|
|
@ -3,7 +3,6 @@ import type http from 'http';
|
|||
import type { AstroConfig, ManifestData, RouteData } from '../@types/astro';
|
||||
import { info, LogOptions } from '../core/logger.js';
|
||||
import { createRouteManifest, matchRoute } from '../core/routing/index.js';
|
||||
import mime from 'mime';
|
||||
import stripAnsi from 'strip-ansi';
|
||||
import { createSafeError } from '../core/util.js';
|
||||
import { ssr } from '../core/render/dev/index.js';
|
||||
|
@ -30,8 +29,8 @@ function removeViteHttpMiddleware(server: vite.Connect.Server) {
|
|||
|
||||
function writeHtmlResponse(res: http.ServerResponse, statusCode: number, html: string) {
|
||||
res.writeHead(statusCode, {
|
||||
'Content-Type': mime.getType('.html') as string,
|
||||
'Content-Length': Buffer.byteLength(html, 'utf8'),
|
||||
'Content-Type': 'text/html; charset=utf-8',
|
||||
'Content-Length': Buffer.byteLength(html, 'utf-8'),
|
||||
});
|
||||
res.write(html);
|
||||
res.end();
|
||||
|
|
Loading…
Reference in a new issue