Skip to content

Commit

Permalink
Include SSL timing (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
exogen committed Jun 12, 2019
1 parent 064212c commit d1e66bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit d1e66bb

Please sign in to comment.