-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.js
27 lines (21 loc) · 784 Bytes
/
demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const http = require('http');
let now = false;
const y = Math.random().toString(36).slice(2);
let n = 0;
http.createServer(async (request, response) => {
// await new Promise(resolve => setTimeout(resolve, ++n * 3000));
// response.setHeader('last-modified', y);
response.setHeader('cache-control', 'max-age=60');
if (request.headers['if-none-match'] === y) {
console.log(304);
response.statusCode = 304;
response.end();
return;
}
// response.statusCode = 451;
response.setHeader('etag', y);
// response.setHeader('cache-control', 'public');
// response.setHeader('cache-control', 'must-revalidate');
response.end('<a href="/">' + Math.random() + '</a>');
// console.log(request.url);
}).listen(8888);