readable and data are mutually exclusive

This commit is contained in:
Simon Knott 2024-09-14 12:15:54 +02:00
parent 513b1c2ab3
commit 7e2acc513d
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC

View file

@ -319,8 +319,6 @@ export abstract class APIRequestContext extends SdkObject {
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 => {
response.once('readable', () => { firstByteAt = monotonicTime(); });
const notifyRequestFinished = (body?: Buffer) => { const notifyRequestFinished = (body?: Buffer) => {
const timings: har.Timings = { const timings: har.Timings = {
send: requestFinishAt! - startAt, send: requestFinishAt! - startAt,
@ -476,7 +474,10 @@ export abstract class APIRequestContext extends SdkObject {
body.on('error', reject); body.on('error', reject);
} }
body.on('data', chunk => chunks.push(chunk)); body.on('data', 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)));