Skip to content

Commit d1e66bb

Browse files
authored
Include SSL timing (#6)
1 parent 064212c commit d1e66bb

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

index.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ function handleRequest(harEntryMap, request, options) {
148148
socket.on("connect", () => {
149149
entry._timestamps.connect = process.hrtime();
150150
});
151+
152+
socket.on("secureConnect", () => {
153+
entry._timestamps.secureConnect = process.hrtime();
154+
});
151155
});
152156

153157
request.on("finish", () => {
@@ -468,8 +472,19 @@ function withHar(baseFetch, defaults = {}) {
468472
0.01 // Minimum value, see above.
469473
);
470474
entry.timings.dns = getDuration(time.socket, time.lookup);
471-
entry.timings.connect = getDuration(time.lookup, time.connect);
472-
entry.timings.send = getDuration(time.connect, time.sent);
475+
entry.timings.connect = getDuration(
476+
time.lookup,
477+
// For backwards compatibility with HAR 1.1, the `connect` timing
478+
// includes `ssl` instead of being mutually exclusive.
479+
time.secureConnect || time.connect
480+
);
481+
if (time.secureConnect) {
482+
entry.timings.ssl = getDuration(time.connect, time.secureConnect);
483+
}
484+
entry.timings.send = getDuration(
485+
time.secureConnect || time.connect,
486+
time.sent
487+
);
473488
entry.timings.wait = Math.max(
474489
// Seems like it might be possible to receive a response before the
475490
// request fires its `finish` event. This is just a hunch and it would

test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("withHar", () => {
3333
dns: expect.any(Number),
3434
receive: expect.any(Number),
3535
send: expect.any(Number),
36-
ssl: -1,
36+
ssl: expect.any(Number),
3737
wait: expect.any(Number)
3838
},
3939
cache: {

0 commit comments

Comments
 (0)