From 63c74a1196856a1746c51c2d1d72632d92b2860a Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 9 Feb 2024 10:49:58 +0100 Subject: [PATCH] remove onResponseStarted Refs: https://github.com/nodejs/undici/issues/2722 --- docs/api/Dispatcher.md | 1 - lib/client.js | 2 -- lib/core/request.js | 4 ---- lib/fetch/index.js | 4 +--- test/node-test/client-dispatch.js | 10 ++-------- types/dispatcher.d.ts | 2 -- 6 files changed, 3 insertions(+), 20 deletions(-) diff --git a/docs/api/Dispatcher.md b/docs/api/Dispatcher.md index 0c678fc8623..fd463bfea16 100644 --- a/docs/api/Dispatcher.md +++ b/docs/api/Dispatcher.md @@ -209,7 +209,6 @@ Returns: `Boolean` - `false` if dispatcher is busy and further dispatch calls wo * **onConnect** `(abort: () => void, context: object) => void` - Invoked before request is dispatched on socket. May be invoked multiple times when a request is retried when the request at the head of the pipeline fails. * **onError** `(error: Error) => void` - Invoked when an error has occurred. May not throw. * **onUpgrade** `(statusCode: number, headers: Buffer[], socket: Duplex) => void` (optional) - Invoked when request is upgraded. Required if `DispatchOptions.upgrade` is defined or `DispatchOptions.method === 'CONNECT'`. -* **onResponseStarted** `() => void` (optional) - Invoked when response is received, before headers have been read. * **onHeaders** `(statusCode: number, headers: Buffer[], resume: () => void, statusText: string) => boolean` - Invoked when statusCode and headers have been received. May be invoked multiple times due to 1xx informational headers. Not required for `upgrade` requests. * **onData** `(chunk: Buffer) => boolean` - Invoked when response payload data is received. Not required for `upgrade` requests. * **onComplete** `(trailers: Buffer[]) => void` - Invoked when response payload and trailers have been received and the request has completed. Not required for `upgrade` requests. diff --git a/lib/client.js b/lib/client.js index 98adffdf182..f59275fb37c 100644 --- a/lib/client.js +++ b/lib/client.js @@ -726,7 +726,6 @@ class Parser { if (!request) { return -1 } - request.onResponseStarted() } onHeaderField (buf) { @@ -1789,7 +1788,6 @@ function writeH2 (client, session, request) { stream.once('response', headers => { const { [HTTP2_HEADER_STATUS]: statusCode, ...realHeaders } = headers - request.onResponseStarted() if (request.onHeaders(Number(statusCode), realHeaders, stream.resume.bind(stream), '') === false) { stream.pause() diff --git a/lib/core/request.js b/lib/core/request.js index 74e0ca16eaa..fa10e795fb3 100644 --- a/lib/core/request.js +++ b/lib/core/request.js @@ -237,10 +237,6 @@ class Request { } } - onResponseStarted () { - return this[kHandler].onResponseStarted?.() - } - onHeaders (statusCode, headers, resume, statusText) { assert(!this.aborted) assert(!this.completed) diff --git a/lib/fetch/index.js b/lib/fetch/index.js index 4b89b4a48e3..ef6b5acb2c1 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -2113,15 +2113,13 @@ async function httpNetworkFetch ( timingInfo.finalNetworkRequestStartTime = coarsenedSharedCurrentTime(fetchParams.crossOriginIsolatedCapability) }, - onResponseStarted () { + onHeaders (status, rawHeaders, resume, statusText) { // Set timingInfo’s final network-response start time to the coarsened shared current // time given fetchParams’s cross-origin isolated capability, immediately after the // user agent’s HTTP parser receives the first byte of the response (e.g., frame header // bytes for HTTP/2 or response status line for HTTP/1.x). timingInfo.finalNetworkResponseStartTime = coarsenedSharedCurrentTime(fetchParams.crossOriginIsolatedCapability) - }, - onHeaders (status, rawHeaders, resume, statusText) { if (status < 200) { return } diff --git a/test/node-test/client-dispatch.js b/test/node-test/client-dispatch.js index b89bad7278b..a5696fa0837 100644 --- a/test/node-test/client-dispatch.js +++ b/test/node-test/client-dispatch.js @@ -881,9 +881,6 @@ test('dispatches in expected order', async (t) => { onBodySent () { dispatches.push('onBodySent') }, - onResponseStarted () { - dispatches.push('onResponseStarted') - }, onHeaders () { dispatches.push('onHeaders') }, @@ -892,7 +889,7 @@ test('dispatches in expected order', async (t) => { }, onComplete () { dispatches.push('onComplete') - p.deepStrictEqual(dispatches, ['onConnect', 'onBodySent', 'onResponseStarted', 'onHeaders', 'onData', 'onComplete']) + p.deepStrictEqual(dispatches, ['onConnect', 'onBodySent', 'onHeaders', 'onData', 'onComplete']) }, onError (err) { p.ifError(err) @@ -938,9 +935,6 @@ test('dispatches in expected order for http2', async (t) => { onBodySent () { dispatches.push('onBodySent') }, - onResponseStarted () { - dispatches.push('onResponseStarted') - }, onHeaders () { dispatches.push('onHeaders') }, @@ -949,7 +943,7 @@ test('dispatches in expected order for http2', async (t) => { }, onComplete () { dispatches.push('onComplete') - p.deepStrictEqual(dispatches, ['onConnect', 'onBodySent', 'onResponseStarted', 'onHeaders', 'onData', 'onComplete']) + p.deepStrictEqual(dispatches, ['onConnect', 'onBodySent', 'onHeaders', 'onData', 'onComplete']) }, onError (err) { p.ifError(err) diff --git a/types/dispatcher.d.ts b/types/dispatcher.d.ts index 0872df0fc0b..52b3bb43f70 100644 --- a/types/dispatcher.d.ts +++ b/types/dispatcher.d.ts @@ -217,8 +217,6 @@ declare namespace Dispatcher { onError?(err: Error): void; /** Invoked when request is upgraded either due to a `Upgrade` header or `CONNECT` method. */ onUpgrade?(statusCode: number, headers: Buffer[] | string[] | null, socket: Duplex): void; - /** Invoked when response is received, before headers have been read. **/ - onResponseStarted?(): void; /** Invoked when statusCode and headers have been received. May be invoked multiple times due to 1xx informational headers. */ onHeaders?(statusCode: number, headers: Buffer[] | string[] | null, resume: () => void, statusText: string): boolean; /** Invoked when response payload data is received. */