Support utf8 in file_server (#3495)

This commit is contained in:
木杉 2019-12-14 16:03:30 +08:00 committed by Ry Dahl
parent d8e60309d2
commit 7e116dd70d
2 changed files with 3 additions and 3 deletions

View file

@ -106,7 +106,7 @@ async function serveFile(
const [file, fileInfo] = await Promise.all([open(filePath), stat(filePath)]);
const headers = new Headers();
headers.set("content-length", fileInfo.len.toString());
headers.set("content-type", "text/plain");
headers.set("content-type", "text/plain; charset=utf-8");
const res = {
status: 200,

View file

@ -36,6 +36,8 @@ test(async function serveFile(): Promise<void> {
const res = await fetch("http://localhost:4500/README.md");
assert(res.headers.has("access-control-allow-origin"));
assert(res.headers.has("access-control-allow-headers"));
assert(res.headers.has("content-type"));
assert(res.headers.get("content-type").includes("charset=utf-8"));
const downloadedFile = await res.text();
const localFile = new TextDecoder().decode(
await Deno.readFile("README.md")
@ -111,8 +113,6 @@ test(async function servePermissionDenied(): Promise<void> {
await errReader.readLine(),
"run again with the --allow-read flag"
);
} catch (e) {
throw e;
} finally {
deniedServer.close();
deniedServer.stdout!.close();