[cli] add charset to content-type headers for vc dev (#9364)

Adds `charset: utf8` to the `content-type` header
This commit is contained in:
Ethan Arrowood
2023-02-01 18:07:08 -07:00
committed by GitHub
parent a4d16c681a
commit 804a3863e7
3 changed files with 5 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
import { lookup as lookupMimeType } from 'mime-types'; import { contentType } from 'mime-types';
export default function getMimeType(fileName: string) { export default function getMimeType(fileName: string) {
return lookupMimeType(fileName) || 'application/octet-stream'; return contentType(fileName) || 'application/octet-stream';
} }

View File

@@ -1129,10 +1129,10 @@ export default class DevServer {
}); });
body = `${json}\n`; body = `${json}\n`;
} else if (accept.includes('html')) { } else if (accept.includes('html')) {
res.setHeader('content-type', 'text/html'); res.setHeader('content-type', 'text/html; charset=utf-8');
body = redirectTemplate({ location, statusCode }); body = redirectTemplate({ location, statusCode });
} else { } else {
res.setHeader('content-type', 'text/plain'); res.setHeader('content-type', 'text/plain; charset=utf-8');
body = `Redirecting to ${location} (${statusCode})\n`; body = `Redirecting to ${location} (${statusCode})\n`;
} }
res.end(body); res.end(body);

View File

@@ -686,6 +686,7 @@ test('[vercel dev] should support static files with zero config', async () => {
expect(body).toEqual('bye:user'); expect(body).toEqual('bye:user');
res = await fetch(`http://localhost:${port}/`); res = await fetch(`http://localhost:${port}/`);
expect(res.headers.get('content-type')).toBe('text/html; charset=utf-8');
body = await res.text(); body = await res.text();
expect(body.startsWith('<h1>goodbye world</h1>')).toBeTruthy(); expect(body.startsWith('<h1>goodbye world</h1>')).toBeTruthy();
} finally { } finally {