replace firstByteAdd with responseAt

This commit is contained in:
Simon Knott 2024-09-16 10:05:59 +02:00
parent 947942349a
commit 5d8ab8a33c
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC

View file

@ -315,16 +315,16 @@ export abstract class APIRequestContext extends SdkObject {
let tcpConnectionAt: number | undefined; let tcpConnectionAt: number | undefined;
let tlsHandshakeAt: number | undefined; let tlsHandshakeAt: number | undefined;
let requestFinishAt: number | undefined; let requestFinishAt: number | undefined;
let firstByteAt: number | undefined;
let endAt: number | undefined; let endAt: number | undefined;
const request = requestConstructor(url, requestOptions as any, async response => { const request = requestConstructor(url, requestOptions as any, async response => {
const responseAt = monotonicTime();
const notifyRequestFinished = (body?: Buffer) => { const notifyRequestFinished = (body?: Buffer) => {
// spec: http://www.softwareishard.com/blog/har-12-spec/#timings // spec: http://www.softwareishard.com/blog/har-12-spec/#timings
const timings: har.Timings = { const timings: har.Timings = {
send: requestFinishAt! - startAt, send: requestFinishAt! - startAt,
wait: firstByteAt! - requestFinishAt!, wait: responseAt - requestFinishAt!,
receive: endAt! - firstByteAt!, 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: (tlsHandshakeAt ?? tcpConnectionAt!) - startAt, // "If [ssl] is defined then the time is also included in the connect field "
ssl: tlsHandshakeAt ? tlsHandshakeAt - tcpConnectionAt! : -1, ssl: tlsHandshakeAt ? tlsHandshakeAt - tcpConnectionAt! : -1,
@ -475,10 +475,7 @@ export abstract class APIRequestContext extends SdkObject {
body.on('error', reject); body.on('error', reject);
} }
body.on('data', chunk => { body.on('data', chunk => chunks.push(chunk));
firstByteAt ??= monotonicTime();
chunks.push(chunk);
});
body.on('end', notifyBodyFinished); body.on('end', notifyBodyFinished);
}); });
request.on('error', error => reject(rewriteOpenSSLErrorIfNeeded(error))); request.on('error', error => reject(rewriteOpenSSLErrorIfNeeded(error)));