file_server: get file and fileInfo concurrently (#3486)

This commit is contained in:
Weijia Wang 2019-12-12 15:59:46 +08:00 committed by Ry Dahl
parent 7f27f649cc
commit df7d8288d9

View file

@ -82,8 +82,7 @@ async function serveFile(
req: ServerRequest, req: ServerRequest,
filePath: string filePath: string
): Promise<Response> { ): Promise<Response> {
const file = await open(filePath); const [file, fileInfo] = await Promise.all([open(filePath), stat(filePath)]);
const fileInfo = await stat(filePath);
const headers = new Headers(); const headers = new Headers();
headers.set("content-length", fileInfo.len.toString()); headers.set("content-length", fileInfo.len.toString());
headers.set("content-type", "text/plain"); headers.set("content-type", "text/plain");