From f648b9c02d0728261d9abfacc402d4a765ba46f8 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sat, 10 Feb 2024 15:39:36 +0100 Subject: [PATCH] remove anti-pattern dispatcher hooks (#2723) --- docs/api/DiagnosticsChannel.md | 11 - docs/api/Dispatcher.md | 2 - docs/api/RedirectHandler.md | 8 - docs/api/RetryHandler.md | 2 - lib/client.js | 29 +-- lib/core/diagnostics.js | 1 - lib/core/request.js | 28 --- lib/core/util.js | 4 - lib/fetch/index.js | 4 +- lib/handler/DecoratorHandler.js | 4 - lib/handler/RedirectHandler.js | 6 - lib/handler/RetryHandler.js | 10 - test/http2.js | 5 +- test/jest/interceptor.test.js | 8 - test/mock-agent.js | 18 +- test/node-test/client-dispatch.js | 195 +----------------- .../diagnostics-channel/post-stream.js | 6 +- test/node-test/diagnostics-channel/post.js | 6 +- test/node-test/util.js | 10 - test/retry-handler.js | 26 +-- types/dispatcher.d.ts | 4 - 21 files changed, 12 insertions(+), 375 deletions(-) diff --git a/docs/api/DiagnosticsChannel.md b/docs/api/DiagnosticsChannel.md index 6e6ad6e4de8..23d88e2cb8d 100644 --- a/docs/api/DiagnosticsChannel.md +++ b/docs/api/DiagnosticsChannel.md @@ -27,17 +27,6 @@ diagnosticsChannel.channel('undici:request:create').subscribe(({ request }) => { Note: a request is only loosely completed to a given socket. - -## `undici:request:bodySent` - -```js -import diagnosticsChannel from 'diagnostics_channel' - -diagnosticsChannel.channel('undici:request:bodySent').subscribe(({ request }) => { - // request is the same object undici:request:create -}) -``` - ## `undici:request:headers` This message is published after the response headers have been received, i.e. the response has been completed. diff --git a/docs/api/Dispatcher.md b/docs/api/Dispatcher.md index 0c678fc8623..8252294ce29 100644 --- a/docs/api/Dispatcher.md +++ b/docs/api/Dispatcher.md @@ -209,11 +209,9 @@ 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. -* **onBodySent** `(chunk: string | Buffer | Uint8Array) => void` - Invoked when a body chunk is sent to the server. Not required. For a stream or iterable body this will be invoked for every chunk. For other body types, it will be invoked once after the body is sent. #### Example 1 - Dispatch GET request diff --git a/docs/api/RedirectHandler.md b/docs/api/RedirectHandler.md index 90a937e7c13..25aaa290414 100644 --- a/docs/api/RedirectHandler.md +++ b/docs/api/RedirectHandler.md @@ -86,11 +86,3 @@ Called when the request is complete. Parameters: - **trailers** `object` - The trailers received. - -#### `onBodySent(chunk)` - -Called when the request body is sent. - -Parameters: - -- **chunk** `Buffer` - The chunk of the request body sent. diff --git a/docs/api/RetryHandler.md b/docs/api/RetryHandler.md index 2323ce47911..9b5437db958 100644 --- a/docs/api/RetryHandler.md +++ b/docs/api/RetryHandler.md @@ -73,7 +73,6 @@ const handler = new RetryHandler( }, handler: { onConnect() {}, - onBodySent() {}, onHeaders(status, _rawHeaders, resume, _statusMessage) { // do something with headers }, @@ -98,7 +97,6 @@ const handler = new RetryHandler(dispatchOptions, { dispatch: client.dispatch.bind(client), handler: { onConnect() {}, - onBodySent() {}, onHeaders(status, _rawHeaders, resume, _statusMessage) {}, onData(chunk) {}, onComplete() {}, diff --git a/lib/client.js b/lib/client.js index 98adffdf182..f1e16b2e01f 100644 --- a/lib/client.js +++ b/lib/client.js @@ -726,7 +726,6 @@ class Parser { if (!request) { return -1 } - request.onResponseStarted() } onHeaderField (buf) { @@ -1606,7 +1605,6 @@ function write (client, request) { assert(contentLength === null, 'no body must not have content length') socket.write(`${header}\r\n`, 'latin1') } - request.onRequestSent() } else if (util.isBuffer(body)) { assert(contentLength === body.byteLength, 'buffer body must have content length') @@ -1614,8 +1612,6 @@ function write (client, request) { socket.write(`${header}content-length: ${contentLength}\r\n\r\n`, 'latin1') socket.write(body) socket.uncork() - request.onBodySent(body) - request.onRequestSent() if (!expectsPayload) { socket[kReset] = true } @@ -1789,7 +1785,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() @@ -1870,15 +1865,13 @@ function writeH2 (client, session, request) { function writeBodyH2 () { /* istanbul ignore else: assertion */ if (!body) { - request.onRequestSent() + // Do nothing... } else if (util.isBuffer(body)) { assert(contentLength === body.byteLength, 'buffer body must have content length') stream.cork() stream.write(body) stream.uncork() stream.end() - request.onBodySent(body) - request.onRequestSent() } else if (util.isBlobLike(body)) { if (typeof body.stream === 'function') { writeIterable({ @@ -1943,22 +1936,14 @@ function writeStream ({ h2stream, body, client, request, socket, contentLength, if (err) { util.destroy(body, err) util.destroy(h2stream, err) - } else { - request.onRequestSent() } } ) - pipe.on('data', onPipeData) pipe.once('end', () => { - pipe.removeListener('data', onPipeData) util.destroy(pipe) }) - function onPipeData (chunk) { - request.onBodySent(chunk) - } - return } @@ -2074,9 +2059,6 @@ async function writeBlob ({ h2stream, body, client, request, socket, contentLeng socket.uncork() } - request.onBodySent(buffer) - request.onRequestSent() - if (!expectsPayload) { socket[kReset] = true } @@ -2122,7 +2104,6 @@ async function writeIterable ({ h2stream, body, client, request, socket, content } const res = h2stream.write(chunk) - request.onBodySent(chunk) if (!res) { await waitForDrain() } @@ -2130,7 +2111,6 @@ async function writeIterable ({ h2stream, body, client, request, socket, content } catch (err) { h2stream.destroy(err) } finally { - request.onRequestSent() h2stream.end() h2stream .off('close', onDrain) @@ -2181,7 +2161,7 @@ class AsyncWriter { } write (chunk) { - const { socket, request, contentLength, client, bytesWritten, expectsPayload, header } = this + const { socket, contentLength, client, bytesWritten, expectsPayload, header } = this if (socket[kError]) { throw socket[kError] @@ -2229,8 +2209,6 @@ class AsyncWriter { socket.uncork() - request.onBodySent(chunk) - if (!ret) { if (socket[kParser].timeout && socket[kParser].timeoutType === TIMEOUT_HEADERS) { // istanbul ignore else: only for jest @@ -2244,8 +2222,7 @@ class AsyncWriter { } end () { - const { socket, contentLength, client, bytesWritten, expectsPayload, header, request } = this - request.onRequestSent() + const { socket, contentLength, client, bytesWritten, expectsPayload, header } = this socket[kWriting] = false diff --git a/lib/core/diagnostics.js b/lib/core/diagnostics.js index e1af3db6112..abe796c291c 100644 --- a/lib/core/diagnostics.js +++ b/lib/core/diagnostics.js @@ -14,7 +14,6 @@ const channels = { sendHeaders: diagnosticsChannel.channel('undici:client:sendHeaders'), // Request create: diagnosticsChannel.channel('undici:request:create'), - bodySent: diagnosticsChannel.channel('undici:request:bodySent'), headers: diagnosticsChannel.channel('undici:request:headers'), trailers: diagnosticsChannel.channel('undici:request:trailers'), error: diagnosticsChannel.channel('undici:request:error'), diff --git a/lib/core/request.js b/lib/core/request.js index 74e0ca16eaa..8577a96d604 100644 --- a/lib/core/request.js +++ b/lib/core/request.js @@ -201,30 +201,6 @@ class Request { } } - onBodySent (chunk) { - if (this[kHandler].onBodySent) { - try { - return this[kHandler].onBodySent(chunk) - } catch (err) { - this.abort(err) - } - } - } - - onRequestSent () { - if (channels.bodySent.hasSubscribers) { - channels.bodySent.publish({ request: this }) - } - - if (this[kHandler].onRequestSent) { - try { - return this[kHandler].onRequestSent() - } catch (err) { - this.abort(err) - } - } - } - onConnect (abort) { assert(!this.aborted) assert(!this.completed) @@ -237,10 +213,6 @@ class Request { } } - onResponseStarted () { - return this[kHandler].onResponseStarted?.() - } - onHeaders (statusCode, headers, resume, statusText) { assert(!this.aborted) assert(!this.completed) diff --git a/lib/core/util.js b/lib/core/util.js index 55bf9f49822..d4ef4b33430 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -323,10 +323,6 @@ function validateHandler (handler, method, upgrade) { throw new InvalidArgumentError('invalid onError method') } - if (typeof handler.onBodySent !== 'function' && handler.onBodySent !== undefined) { - throw new InvalidArgumentError('invalid onBodySent method') - } - if (upgrade || method === 'CONNECT') { if (typeof handler.onUpgrade !== 'function') { throw new InvalidArgumentError('invalid onUpgrade method') 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/lib/handler/DecoratorHandler.js b/lib/handler/DecoratorHandler.js index 9d70a767f1e..cbf0ddd4638 100644 --- a/lib/handler/DecoratorHandler.js +++ b/lib/handler/DecoratorHandler.js @@ -28,8 +28,4 @@ module.exports = class DecoratorHandler { onComplete (...args) { return this.handler.onComplete(...args) } - - onBodySent (...args) { - return this.handler.onBodySent(...args) - } } diff --git a/lib/handler/RedirectHandler.js b/lib/handler/RedirectHandler.js index 368ef520d76..2afbf9427ff 100644 --- a/lib/handler/RedirectHandler.js +++ b/lib/handler/RedirectHandler.js @@ -173,12 +173,6 @@ class RedirectHandler { this.handler.onComplete(trailers) } } - - onBodySent (chunk) { - if (this.handler.onBodySent) { - this.handler.onBodySent(chunk) - } - } } function parseLocation (statusCode, headers) { diff --git a/lib/handler/RetryHandler.js b/lib/handler/RetryHandler.js index 2a2f878c00f..5cf36c772af 100644 --- a/lib/handler/RetryHandler.js +++ b/lib/handler/RetryHandler.js @@ -74,12 +74,6 @@ class RetryHandler { }) } - onRequestSent () { - if (this.handler.onRequestSent) { - this.handler.onRequestSent() - } - } - onUpgrade (statusCode, headers, socket) { if (this.handler.onUpgrade) { this.handler.onUpgrade(statusCode, headers, socket) @@ -94,10 +88,6 @@ class RetryHandler { } } - onBodySent (chunk) { - if (this.handler.onBodySent) return this.handler.onBodySent(chunk) - } - static [kRetryHandlerDefaultRetry] (err, { state, opts }, cb) { const { statusCode, code, headers } = err const { method, retryOptions } = opts diff --git a/test/http2.js b/test/http2.js index 2daef09bd2c..3db608f5abe 100644 --- a/test/http2.js +++ b/test/http2.js @@ -804,7 +804,7 @@ test('Should handle h2 request with body (string or buffer) - dispatch', t => { stream.end('hello h2!') }) - t.plan(7) + t.plan(6) server.listen(0, () => { const client = new Client(`https://localhost:${server.address().port}`, { @@ -842,9 +842,6 @@ test('Should handle h2 request with body (string or buffer) - dispatch', t => { onData (chunk) { response.push(chunk) }, - onBodySent (body) { - t.equal(body.toString('utf-8'), expectedBody) - }, onComplete () { t.equal(Buffer.concat(response).toString('utf-8'), 'hello h2!') t.equal( diff --git a/test/jest/interceptor.test.js b/test/jest/interceptor.test.js index 9caa0758936..7c3d62251ea 100644 --- a/test/jest/interceptor.test.js +++ b/test/jest/interceptor.test.js @@ -143,14 +143,6 @@ describe('interceptors with NtlmRequestHandler', () => { return this.handler.onComplete(...args) } } - - onBodySent (...args) { - if (this.requestCount < 2) { - // Do nothing - } else { - return this.handler.onBodySent(...args) - } - } } let server diff --git a/test/mock-agent.js b/test/mock-agent.js index 42dfb9554cc..74758d98943 100644 --- a/test/mock-agent.js +++ b/test/mock-agent.js @@ -149,7 +149,7 @@ test('MockAgent - dispatch', t => { }) t.test('should throw if handler is not valid on redirect', (t) => { - t.plan(7) + t.plan(6) const baseUrl = 'http://localhost:9999' @@ -173,16 +173,6 @@ test('MockAgent - dispatch', t => { onConnect: 'INVALID' }), new InvalidArgumentError('invalid onConnect method')) - t.throws(() => mockAgent.dispatch({ - origin: baseUrl, - path: '/foo', - method: 'GET' - }, { - onError: (err) => { throw err }, - onConnect: () => {}, - onBodySent: 'INVALID' - }), new InvalidArgumentError('invalid onBodySent method')) - t.throws(() => mockAgent.dispatch({ origin: baseUrl, path: '/foo', @@ -190,7 +180,6 @@ test('MockAgent - dispatch', t => { }, { onError: (err) => { throw err }, onConnect: () => {}, - onBodySent: () => {}, onUpgrade: 'INVALID' }), new InvalidArgumentError('invalid onUpgrade method')) @@ -201,7 +190,6 @@ test('MockAgent - dispatch', t => { }, { onError: (err) => { throw err }, onConnect: () => {}, - onBodySent: () => {}, onHeaders: 'INVALID' }), new InvalidArgumentError('invalid onHeaders method')) @@ -212,7 +200,6 @@ test('MockAgent - dispatch', t => { }, { onError: (err) => { throw err }, onConnect: () => {}, - onBodySent: () => {}, onHeaders: () => {}, onData: 'INVALID' }), new InvalidArgumentError('invalid onData method')) @@ -224,7 +211,6 @@ test('MockAgent - dispatch', t => { }, { onError: (err) => { throw err }, onConnect: () => {}, - onBodySent: () => {}, onHeaders: () => {}, onData: () => {}, onComplete: 'INVALID' @@ -797,7 +783,7 @@ test('MockAgent - handle delays to simulate work', async (t) => { const response = await getResponse(body) t.equal(response, 'hello') const elapsedInMs = process.hrtime(start)[1] / 1e6 - t.ok(elapsedInMs >= 50, `Elapsed time is not greater than 50ms: ${elapsedInMs}`) + t.ok(elapsedInMs >= 49, `Elapsed time is not greater than 50ms: ${elapsedInMs}`) }) test('MockAgent - should persist requests', async (t) => { diff --git a/test/node-test/client-dispatch.js b/test/node-test/client-dispatch.js index b89bad7278b..921ce2570eb 100644 --- a/test/node-test/client-dispatch.js +++ b/test/node-test/client-dispatch.js @@ -1,10 +1,8 @@ 'use strict' const { test } = require('node:test') -const assert = require('node:assert/strict') const http = require('node:http') const { Client, Pool, errors } = require('../..') -const stream = require('node:stream') const { createSecureServer } = require('node:http2') const pem = require('https-pem') const { tspl } = require('@matteo.collina/tspl') @@ -678,183 +676,6 @@ test('dispatch pool onError missing', async (t) => { await p.completed }) -test('dispatch onBodySent not a function', async (t) => { - const p = tspl(t, { plan: 2 }) - const server = http.createServer((req, res) => { - res.end('ad') - }) - t.after(closeServerAsPromise(server)) - - server.listen(0, () => { - const client = new Pool(`http://localhost:${server.address().port}`) - t.after(() => { return client.close() }) - - client.dispatch({ - path: '/', - method: 'GET' - }, { - onBodySent: '42', - onConnect () {}, - onHeaders () {}, - onData () {}, - onError (err) { - p.strictEqual(err.code, 'UND_ERR_INVALID_ARG') - p.strictEqual(err.message, 'invalid onBodySent method') - } - }) - }) - - await p.completed -}) - -test('dispatch onBodySent buffer', async (t) => { - const p = tspl(t, { plan: 3 }) - - const server = http.createServer((req, res) => { - res.end('ad') - }) - t.after(closeServerAsPromise(server)) - - server.listen(0, () => { - const client = new Pool(`http://localhost:${server.address().port}`) - t.after(() => { return client.close() }) - const body = 'hello 🚀' - client.dispatch({ - path: '/', - method: 'POST', - body - }, { - onBodySent (chunk) { - p.strictEqual(chunk.toString(), body) - }, - onRequestSent () { - p.ok(1) - }, - onError (err) { - throw err - }, - onConnect () {}, - onHeaders () {}, - onData () {}, - onComplete () { - p.ok(1) - } - }) - }) - - await p.completed -}) - -test('dispatch onBodySent stream', async (t) => { - const p = tspl(t, { plan: 8 }) - const server = http.createServer((req, res) => { - res.end('ad') - }) - t.after(closeServerAsPromise(server)) - const chunks = ['he', 'llo', 'world', '🚀'] - const toSendBytes = chunks.reduce((a, b) => a + Buffer.byteLength(b), 0) - const body = stream.Readable.from(chunks) - server.listen(0, () => { - const client = new Pool(`http://localhost:${server.address().port}`) - t.after(() => { return client.close() }) - let sentBytes = 0 - let currentChunk = 0 - client.dispatch({ - path: '/', - method: 'POST', - body - }, { - onBodySent (chunk) { - p.strictEqual(chunks[currentChunk++], chunk) - sentBytes += Buffer.byteLength(chunk) - }, - onRequestSent () { - p.ok(1) - }, - onError (err) { - throw err - }, - onConnect () {}, - onHeaders () {}, - onData () {}, - onComplete () { - p.strictEqual(currentChunk, chunks.length) - p.strictEqual(sentBytes, toSendBytes) - p.ok(1) - } - }) - }) - - await p.completed -}) - -test('dispatch onBodySent async-iterable', (t, done) => { - const server = http.createServer((req, res) => { - res.end('ad') - }) - t.after(closeServerAsPromise(server)) - const chunks = ['he', 'llo', 'world', '🚀'] - const toSendBytes = chunks.reduce((a, b) => a + Buffer.byteLength(b), 0) - server.listen(0, () => { - const client = new Pool(`http://localhost:${server.address().port}`) - t.after(() => { return client.close() }) - let sentBytes = 0 - let currentChunk = 0 - client.dispatch({ - path: '/', - method: 'POST', - body: chunks - }, { - onBodySent (chunk) { - assert.strictEqual(chunks[currentChunk++], chunk) - sentBytes += Buffer.byteLength(chunk) - }, - onError (err) { - throw err - }, - onConnect () {}, - onHeaders () {}, - onData () {}, - onComplete () { - assert.strictEqual(currentChunk, chunks.length) - assert.strictEqual(sentBytes, toSendBytes) - done() - } - }) - }) -}) - -test('dispatch onBodySent throws error', (t, done) => { - const server = http.createServer((req, res) => { - res.end('ended') - }) - t.after(closeServerAsPromise(server)) - - server.listen(0, () => { - const client = new Pool(`http://localhost:${server.address().port}`) - t.after(() => { return client.close() }) - const body = 'hello' - client.dispatch({ - path: '/', - method: 'POST', - body - }, { - onBodySent (chunk) { - throw new Error('fail') - }, - onError (err) { - assert.ok(err instanceof Error) - assert.strictEqual(err.message, 'fail') - done() - }, - onConnect () {}, - onHeaders () {}, - onData () {}, - onComplete () {} - }) - }) -}) - test('dispatches in expected order', async (t) => { const server = http.createServer((req, res) => { res.end('ended') @@ -878,12 +699,6 @@ test('dispatches in expected order', async (t) => { onConnect () { dispatches.push('onConnect') }, - onBodySent () { - dispatches.push('onBodySent') - }, - onResponseStarted () { - dispatches.push('onResponseStarted') - }, onHeaders () { dispatches.push('onHeaders') }, @@ -892,7 +707,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', 'onHeaders', 'onData', 'onComplete']) }, onError (err) { p.ifError(err) @@ -935,12 +750,6 @@ test('dispatches in expected order for http2', async (t) => { onConnect () { dispatches.push('onConnect') }, - onBodySent () { - dispatches.push('onBodySent') - }, - onResponseStarted () { - dispatches.push('onResponseStarted') - }, onHeaders () { dispatches.push('onHeaders') }, @@ -949,7 +758,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', 'onHeaders', 'onData', 'onComplete']) }, onError (err) { p.ifError(err) diff --git a/test/node-test/diagnostics-channel/post-stream.js b/test/node-test/diagnostics-channel/post-stream.js index a50d5ea02c0..1be9b9e14b5 100644 --- a/test/node-test/diagnostics-channel/post-stream.js +++ b/test/node-test/diagnostics-channel/post-stream.js @@ -17,7 +17,7 @@ const { Client } = require('../../..') const { createServer } = require('node:http') test('Diagnostics channel - post stream', (t) => { - const assert = tspl(t, { plan: 33 }) + const assert = tspl(t, { plan: 32 }) const server = createServer((req, res) => { req.resume() res.setHeader('Content-Type', 'text/plain') @@ -116,10 +116,6 @@ test('Diagnostics channel - post stream', (t) => { assert.equal(response.statusText, 'OK') }) - diagnosticsChannel.channel('undici:request:bodySent').subscribe(({ request }) => { - assert.equal(_req, request) - }) - let endEmitted = false return new Promise((resolve) => { diff --git a/test/node-test/diagnostics-channel/post.js b/test/node-test/diagnostics-channel/post.js index 45368e3fdab..d8d7401daf3 100644 --- a/test/node-test/diagnostics-channel/post.js +++ b/test/node-test/diagnostics-channel/post.js @@ -16,7 +16,7 @@ const { Client } = require('../../../') const { createServer } = require('node:http') test('Diagnostics channel - post', (t) => { - const assert = tspl(t, { plan: 33 }) + const assert = tspl(t, { plan: 32 }) const server = createServer((req, res) => { req.resume() res.setHeader('Content-Type', 'text/plain') @@ -114,10 +114,6 @@ test('Diagnostics channel - post', (t) => { assert.equal(response.statusText, 'OK') }) - diagnosticsChannel.channel('undici:request:bodySent').subscribe(({ request }) => { - assert.equal(_req, request) - }) - let endEmitted = false return new Promise((resolve) => { diff --git a/test/node-test/util.js b/test/node-test/util.js index 9d18f98d596..ce15efb4a48 100644 --- a/test/node-test/util.js +++ b/test/node-test/util.js @@ -41,25 +41,17 @@ test('validateHandler', () => { assert.throws(() => util.validateHandler({ onConnect: () => {}, onError: () => {}, - onBodySent: null - }), InvalidArgumentError, 'invalid onBodySent method') - assert.throws(() => util.validateHandler({ - onConnect: () => {}, - onError: () => {}, - onBodySent: () => {}, onHeaders: null }), InvalidArgumentError, 'invalid onHeaders method') assert.throws(() => util.validateHandler({ onConnect: () => {}, onError: () => {}, - onBodySent: () => {}, onHeaders: () => {}, onData: null }), InvalidArgumentError, 'invalid onData method') assert.throws(() => util.validateHandler({ onConnect: () => {}, onError: () => {}, - onBodySent: () => {}, onHeaders: () => {}, onData: () => {}, onComplete: null @@ -67,13 +59,11 @@ test('validateHandler', () => { assert.throws(() => util.validateHandler({ onConnect: () => {}, onError: () => {}, - onBodySent: () => {}, onUpgrade: 'null' }, 'CONNECT'), InvalidArgumentError, 'invalid onUpgrade method') assert.throws(() => util.validateHandler({ onConnect: () => {}, onError: () => {}, - onBodySent: () => {}, onUpgrade: 'null' }, 'CONNECT', () => {}), InvalidArgumentError, 'invalid onUpgrade method') }) diff --git a/test/retry-handler.js b/test/retry-handler.js index d90ff5ebc45..dd56adee1a9 100644 --- a/test/retry-handler.js +++ b/test/retry-handler.js @@ -62,9 +62,6 @@ tap.test('Should retry status code', t => { onConnect () { t.pass() }, - onBodySent () { - t.pass() - }, onHeaders (status, _rawHeaders, resume, _statusMessage) { t.equal(status, 200) return true @@ -147,9 +144,6 @@ tap.test('Should use retry-after header for retries', t => { onConnect () { t.pass() }, - onBodySent () { - t.pass() - }, onHeaders (status, _rawHeaders, resume, _statusMessage) { t.equal(status, 200) return true @@ -233,9 +227,6 @@ tap.test('Should use retry-after header for retries (date)', t => { onConnect () { t.pass() }, - onBodySent () { - t.pass() - }, onHeaders (status, _rawHeaders, resume, _statusMessage) { t.equal(status, 200) return true @@ -316,9 +307,6 @@ tap.test('Should retry with defaults', t => { onConnect () { t.pass() }, - onBodySent () { - t.pass() - }, onHeaders (status, _rawHeaders, resume, _statusMessage) { t.equal(status, 200) return true @@ -401,7 +389,7 @@ tap.test('Should handle 206 partial content', t => { } } - t.plan(8) + t.plan(6) server.listen(0, () => { const client = new Client(`http://localhost:${server.address().port}`) @@ -410,15 +398,9 @@ tap.test('Should handle 206 partial content', t => { return client.dispatch(...args) }, handler: { - onRequestSent () { - t.pass() - }, onConnect () { t.pass() }, - onBodySent () { - t.pass() - }, onHeaders (status, _rawHeaders, resume, _statusMessage) { t.equal(status, 200) return true @@ -502,9 +484,6 @@ tap.test('Should handle 206 partial content - bad-etag', t => { onConnect () { t.pass() }, - onBodySent () { - t.pass() - }, onHeaders (status, _rawHeaders, resume, _statusMessage) { t.pass() return true @@ -649,9 +628,6 @@ tap.test('should not error if request is not meant to be retried', t => { onConnect () { t.pass() }, - onBodySent () { - t.pass() - }, onHeaders (status, _rawHeaders, resume, _statusMessage) { t.equal(status, 400) return true diff --git a/types/dispatcher.d.ts b/types/dispatcher.d.ts index 0872df0fc0b..943264285be 100644 --- a/types/dispatcher.d.ts +++ b/types/dispatcher.d.ts @@ -217,16 +217,12 @@ 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. */ onData?(chunk: Buffer): boolean; /** Invoked when response payload and trailers have been received and the request has completed. */ onComplete?(trailers: string[] | null): void; - /** Invoked when a body chunk is sent to the server. May be invoked multiple times for chunked requests */ - onBodySent?(chunkSize: number, totalBytesSent: number): void; } export type PipelineHandler = (data: PipelineHandlerData) => Readable; export type HttpMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';