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 notifyRequestFinished = (body?: Buffer) => {
|
||||||
const endAt = monotonicTime();
|
const endAt = monotonicTime();
|
||||||
// spec: http://www.softwareishard.com/blog/har-12-spec/#timings
|
// spec: http://www.softwareishard.com/blog/har-12-spec/#timings
|
||||||
|
const connectEnd = tlsHandshakeAt ?? tcpConnectionAt;
|
||||||
const timings: har.Timings = {
|
const timings: har.Timings = {
|
||||||
send: requestFinishAt! - startAt,
|
send: requestFinishAt! - startAt,
|
||||||
wait: responseAt - requestFinishAt!,
|
wait: responseAt - requestFinishAt!,
|
||||||
receive: endAt - responseAt,
|
receive: endAt - responseAt,
|
||||||
dns: dnsLookupAt ? dnsLookupAt - startAt : -1,
|
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,
|
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 = {
|
const requestFinishedEvent: APIRequestFinishedEvent = {
|
||||||
requestEvent,
|
requestEvent,
|
||||||
httpVersion: response.httpVersion,
|
httpVersion: response.httpVersion,
|
||||||
|
|
@ -496,17 +491,16 @@ export abstract class APIRequestContext extends SdkObject {
|
||||||
request.on('close', () => eventsHelper.removeEventListeners(listeners));
|
request.on('close', () => eventsHelper.removeEventListeners(listeners));
|
||||||
|
|
||||||
request.on('socket', socket => {
|
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) {
|
if (request.reusedSocket) {
|
||||||
reusedSocketAt = monotonicTime();
|
reusedSocketAt = monotonicTime();
|
||||||
dnsLookupAt = startAt;
|
return;
|
||||||
tcpConnectionAt = startAt;
|
|
||||||
} else {
|
|
||||||
dnsLookupAt = happyEyeBallsTimings.dnsLookupAt;
|
|
||||||
tcpConnectionAt ??= happyEyeBallsTimings.tcpConnectionAt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// non-happy-eyeballs sockets
|
||||||
listeners.push(
|
listeners.push(
|
||||||
eventsHelper.addEventListener(socket, 'lookup', () => { dnsLookupAt = monotonicTime(); }),
|
eventsHelper.addEventListener(socket, 'lookup', () => { dnsLookupAt = monotonicTime(); }),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue