refactor
This commit is contained in:
parent
a14a7d2837
commit
2e139dafb6
|
|
@ -320,22 +320,17 @@ export abstract class APIRequestContext extends SdkObject {
|
|||
const notifyRequestFinished = (body?: Buffer) => {
|
||||
const endAt = monotonicTime();
|
||||
// spec: http://www.softwareishard.com/blog/har-12-spec/#timings
|
||||
const connectEnd = tlsHandshakeAt ?? tcpConnectionAt;
|
||||
const timings: har.Timings = {
|
||||
send: requestFinishAt! - startAt,
|
||||
wait: responseAt - requestFinishAt!,
|
||||
receive: endAt - responseAt,
|
||||
dns: dnsLookupAt ? dnsLookupAt - startAt : -1,
|
||||
connect: (tlsHandshakeAt ?? tcpConnectionAt!) - startAt, // "If [ssl] is defined then the time is also included in the connect field "
|
||||
connect: connectEnd ? connectEnd - startAt : -1, // "If [ssl] is defined then the time is also included in the connect field "
|
||||
ssl: tlsHandshakeAt ? tlsHandshakeAt - tcpConnectionAt! : -1,
|
||||
blocked: -1,
|
||||
blocked: reusedSocketAt ? reusedSocketAt - startAt : -1,
|
||||
};
|
||||
|
||||
if (request.reusedSocket) {
|
||||
timings.blocked = reusedSocketAt! - startAt;
|
||||
timings.connect = -1;
|
||||
timings.dns = -1;
|
||||
}
|
||||
|
||||
const requestFinishedEvent: APIRequestFinishedEvent = {
|
||||
requestEvent,
|
||||
httpVersion: response.httpVersion,
|
||||
|
|
@ -496,16 +491,15 @@ export abstract class APIRequestContext extends SdkObject {
|
|||
request.on('close', () => eventsHelper.removeEventListeners(listeners));
|
||||
|
||||
request.on('socket', socket => {
|
||||
// happy eyeballs don't emit lookup and connect events, so we use our custom ones
|
||||
const happyEyeBallsTimings = timingForSocket(socket);
|
||||
if (request.reusedSocket) {
|
||||
reusedSocketAt = monotonicTime();
|
||||
dnsLookupAt = startAt;
|
||||
tcpConnectionAt = startAt;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
// happy eyeballs don't emit lookup and connect events, so we use our custom ones
|
||||
const happyEyeBallsTimings = timingForSocket(socket);
|
||||
dnsLookupAt = happyEyeBallsTimings.dnsLookupAt;
|
||||
tcpConnectionAt ??= happyEyeBallsTimings.tcpConnectionAt;
|
||||
}
|
||||
|
||||
// non-happy-eyeballs sockets
|
||||
listeners.push(
|
||||
|
|
|
|||
Loading…
Reference in a new issue