From d1e66bb8a64e1aaaefeec4bc9495b6d1fc8ebd9c Mon Sep 17 00:00:00 2001 From: Brian Beck Date: Tue, 11 Jun 2019 22:33:48 -0700 Subject: [PATCH] Include SSL timing (#6) --- index.js | 19 +++++++++++++++++-- test.js | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 9119fbe..8105ff5 100644 --- a/index.js +++ b/index.js @@ -148,6 +148,10 @@ function handleRequest(harEntryMap, request, options) { socket.on("connect", () => { entry._timestamps.connect = process.hrtime(); }); + + socket.on("secureConnect", () => { + entry._timestamps.secureConnect = process.hrtime(); + }); }); request.on("finish", () => { @@ -468,8 +472,19 @@ function withHar(baseFetch, defaults = {}) { 0.01 // Minimum value, see above. ); entry.timings.dns = getDuration(time.socket, time.lookup); - entry.timings.connect = getDuration(time.lookup, time.connect); - entry.timings.send = getDuration(time.connect, time.sent); + entry.timings.connect = getDuration( + time.lookup, + // For backwards compatibility with HAR 1.1, the `connect` timing + // includes `ssl` instead of being mutually exclusive. + time.secureConnect || time.connect + ); + if (time.secureConnect) { + entry.timings.ssl = getDuration(time.connect, time.secureConnect); + } + entry.timings.send = getDuration( + time.secureConnect || time.connect, + time.sent + ); entry.timings.wait = Math.max( // Seems like it might be possible to receive a response before the // request fires its `finish` event. This is just a hunch and it would diff --git a/test.js b/test.js index 1a8dbc2..f292047 100644 --- a/test.js +++ b/test.js @@ -33,7 +33,7 @@ describe("withHar", () => { dns: expect.any(Number), receive: expect.any(Number), send: expect.any(Number), - ssl: -1, + ssl: expect.any(Number), wait: expect.any(Number) }, cache: {