Skip to content

Commit 15f41f2

Browse files
ronagKhafraDev
authored andcommitted
remove anti-pattern dispatcher hooks (nodejs#2723)
1 parent dd98299 commit 15f41f2

File tree

13 files changed

+17
-302
lines changed

13 files changed

+17
-302
lines changed

docs/docs/api/RedirectHandler.md

-8
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,3 @@ Called when the request is complete.
8686
Parameters:
8787

8888
- **trailers** `object` - The trailers received.
89-
90-
#### `onBodySent(chunk)`
91-
92-
Called when the request body is sent.
93-
94-
Parameters:
95-
96-
- **chunk** `Buffer` - The chunk of the request body sent.

lib/core/diagnostics.js

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const channels = {
1414
sendHeaders: diagnosticsChannel.channel('undici:client:sendHeaders'),
1515
// Request
1616
create: diagnosticsChannel.channel('undici:request:create'),
17-
bodySent: diagnosticsChannel.channel('undici:request:bodySent'),
1817
headers: diagnosticsChannel.channel('undici:request:headers'),
1918
trailers: diagnosticsChannel.channel('undici:request:trailers'),
2019
error: diagnosticsChannel.channel('undici:request:error'),

lib/core/request.js

-28
Original file line numberDiff line numberDiff line change
@@ -192,30 +192,6 @@ class Request {
192192
}
193193
}
194194

195-
onBodySent (chunk) {
196-
if (this[kHandler].onBodySent) {
197-
try {
198-
return this[kHandler].onBodySent(chunk)
199-
} catch (err) {
200-
this.abort(err)
201-
}
202-
}
203-
}
204-
205-
onRequestSent () {
206-
if (channels.bodySent.hasSubscribers) {
207-
channels.bodySent.publish({ request: this })
208-
}
209-
210-
if (this[kHandler].onRequestSent) {
211-
try {
212-
return this[kHandler].onRequestSent()
213-
} catch (err) {
214-
this.abort(err)
215-
}
216-
}
217-
}
218-
219195
onConnect (abort) {
220196
assert(!this.aborted)
221197
assert(!this.completed)
@@ -228,10 +204,6 @@ class Request {
228204
}
229205
}
230206

231-
onResponseStarted () {
232-
return this[kHandler].onResponseStarted?.()
233-
}
234-
235207
onHeaders (statusCode, headers, resume, statusText) {
236208
assert(!this.aborted)
237209
assert(!this.completed)

lib/core/util.js

-4
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,6 @@ function validateHandler (handler, method, upgrade) {
413413
throw new InvalidArgumentError('invalid onError method')
414414
}
415415

416-
if (typeof handler.onBodySent !== 'function' && handler.onBodySent !== undefined) {
417-
throw new InvalidArgumentError('invalid onBodySent method')
418-
}
419-
420416
if (upgrade || method === 'CONNECT') {
421417
if (typeof handler.onUpgrade !== 'function') {
422418
throw new InvalidArgumentError('invalid onUpgrade method')

test/http2.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,11 @@ test('Should handle h2 request with body (string or buffer) - dispatch', async t
819819
stream.end('hello h2!')
820820
})
821821

822+
<<<<<<< HEAD
822823
t = tspl(t, { plan: 9 })
824+
=======
825+
t = tspl(t, { plan: 6 })
826+
>>>>>>> ddabe919... remove anti-pattern dispatcher hooks (#2723)
823827

824828
server.listen(0, () => {
825829
const client = new Client(`https://localhost:${server.address().port}`, {
@@ -859,9 +863,6 @@ test('Should handle h2 request with body (string or buffer) - dispatch', async t
859863
onData (chunk) {
860864
response.push(chunk)
861865
},
862-
onBodySent (body) {
863-
t.strictEqual(body.toString('utf-8'), expectedBody)
864-
},
865866
onComplete () {
866867
t.strictEqual(Buffer.concat(response).toString('utf-8'), 'hello h2!')
867868
t.strictEqual(

test/jest/interceptor.test.js

-8
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,6 @@ describe('interceptors with NtlmRequestHandler', () => {
143143
return this.handler.onComplete(...args)
144144
}
145145
}
146-
147-
onBodySent (...args) {
148-
if (this.requestCount < 2) {
149-
// Do nothing
150-
} else {
151-
return this.handler.onBodySent(...args)
152-
}
153-
}
154146
}
155147
let server
156148

test/mock-agent.js

+6-15
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ describe('MockAgent - dispatch', () => {
144144
})
145145

146146
test('should throw if handler is not valid on redirect', (t) => {
147-
t = tspl(t, { plan: 7 })
147+
t = tspl(t, { plan: 6 })
148148

149149
const baseUrl = 'http://localhost:9999'
150150

@@ -168,24 +168,13 @@ describe('MockAgent - dispatch', () => {
168168
onConnect: 'INVALID'
169169
}), new InvalidArgumentError('invalid onConnect method'))
170170

171-
t.throws(() => mockAgent.dispatch({
172-
origin: baseUrl,
173-
path: '/foo',
174-
method: 'GET'
175-
}, {
176-
onError: (err) => { throw err },
177-
onConnect: () => {},
178-
onBodySent: 'INVALID'
179-
}), new InvalidArgumentError('invalid onBodySent method'))
180-
181171
t.throws(() => mockAgent.dispatch({
182172
origin: baseUrl,
183173
path: '/foo',
184174
method: 'CONNECT'
185175
}, {
186176
onError: (err) => { throw err },
187177
onConnect: () => {},
188-
onBodySent: () => {},
189178
onUpgrade: 'INVALID'
190179
}), new InvalidArgumentError('invalid onUpgrade method'))
191180

@@ -196,7 +185,6 @@ describe('MockAgent - dispatch', () => {
196185
}, {
197186
onError: (err) => { throw err },
198187
onConnect: () => {},
199-
onBodySent: () => {},
200188
onHeaders: 'INVALID'
201189
}), new InvalidArgumentError('invalid onHeaders method'))
202190

@@ -207,7 +195,6 @@ describe('MockAgent - dispatch', () => {
207195
}, {
208196
onError: (err) => { throw err },
209197
onConnect: () => {},
210-
onBodySent: () => {},
211198
onHeaders: () => {},
212199
onData: 'INVALID'
213200
}), new InvalidArgumentError('invalid onData method'))
@@ -219,7 +206,6 @@ describe('MockAgent - dispatch', () => {
219206
}, {
220207
onError: (err) => { throw err },
221208
onConnect: () => {},
222-
onBodySent: () => {},
223209
onHeaders: () => {},
224210
onData: () => {},
225211
onComplete: 'INVALID'
@@ -789,8 +775,13 @@ test('MockAgent - handle delays to simulate work', async (t) => {
789775

790776
const response = await getResponse(body)
791777
t.strictEqual(response, 'hello')
778+
<<<<<<< HEAD
792779
const elapsedInMs = Math.ceil(process.hrtime(start)[1] / 1e6)
793780
t.ok(elapsedInMs >= 50, `Elapsed time is not greater than 50ms: ${elapsedInMs}`)
781+
=======
782+
const elapsedInMs = process.hrtime(start)[1] / 1e6
783+
t.ok(elapsedInMs >= 49, `Elapsed time is not greater than 50ms: ${elapsedInMs}`)
784+
>>>>>>> ddabe919... remove anti-pattern dispatcher hooks (#2723)
794785
})
795786

796787
test('MockAgent - should persist requests', async (t) => {

0 commit comments

Comments
 (0)