Skip to content

Commit 1c909ea

Browse files
committed
Add time header to demo.
1 parent b22edd0 commit 1c909ea

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

public/index.html

+11-4
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,21 @@
2525
}
2626
}
2727

28-
const calibrator = new Calibrator();
28+
const calibrator_with_date = new Calibrator();
29+
const calibrator_with_custom_header = new Calibrator();
2930

30-
calibrator.beginRequest();
31+
calibrator_with_date.beginRequest();
32+
calibrator_with_custom_header.beginRequest();
3133
fetch("/endpoint").then((res) => {
32-
calibrator.endRequest(Date.parse(res.headers.get("Date")));
34+
calibrator_with_date.endRequest(Date.parse(res.headers.get("Date")));
35+
calibrator_with_custom_header.endRequest(
36+
+new Date(+res.headers.get("Response-Start")),
37+
+new Date(+res.headers.get("Response-End"))
38+
);
3339

3440
document.querySelector("pre").innerText = JSON.stringify({
35-
difference_in_seconds: calibrator.clockDifference() / 1000
41+
difference_in_seconds_using_date: calibrator_with_date.clockDifference() / 1000,
42+
difference_in_seconds_using_custom_header: calibrator_with_custom_header.clockDifference() / 1000
3643
}, null, 2);
3744
});
3845
})();

server.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ const http = require("http");
33
const path = require("path");
44

55
http.createServer((req, res) => {
6+
const response_start = Date.now();
7+
68
if (req.url === "/") {
79
return sendHtml(res);
810
}
911

1012
if (req.url === "/endpoint") {
11-
res.writeHead(200);
13+
res.writeHead(200, {
14+
"Response-Start": response_start,
15+
"Response-End": Date.now()
16+
});
1217
return res.end();
1318
}
1419

0 commit comments

Comments
 (0)