'use strict';
// See http://eprev.org/2017/01/04/the-importance-of-html-character-encoding/
const http = require('http');
http.createServer((request, response) => {
let charset;
switch (request.url) {
case '/charset-is-specified':
charset = 'utf-8';
case '/charset-is-not-specified':
response.writeHead(200, {
'Content-Type': charset ? 'text/html; charset=utf-8' : 'text/html',
});
// Early-head
response.write(`
Charset Encoding Test
`);
// The rest of the document
setTimeout(() => {
response.end('');
}, 1000);
break;
case '/scripts.js':
response.writeHead(200, {
'Content-Type': 'application/javascript',
});
response.end();
break;
case '/styles.css':
response.writeHead(200, {
'Content-Type': 'text/css',
});
response.end('');
break;
default:
response.writeHead(404, {
'Content-Type': 'text/plain',
});
response.end();
}
}).listen(4000);