Skip to content

Commit

Permalink
fix: don't leak internal class
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Mar 31, 2024
1 parent 7485cd9 commit ffb7cb4
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 29 deletions.
2 changes: 0 additions & 2 deletions docs/docs/api/DiagnosticsChannel.md
Expand Up @@ -20,8 +20,6 @@ diagnosticsChannel.channel('undici:request:create').subscribe(({ request }) => {
console.log('method', request.method)
console.log('path', request.path)
console.log('headers') // array of strings, e.g: ['foo', 'bar']
request.addHeader('hello', 'world')
console.log('headers', request.headers) // e.g. ['foo', 'bar', 'hello', 'world']
})
```

Expand Down
51 changes: 41 additions & 10 deletions lib/core/request.js
Expand Up @@ -25,6 +25,8 @@ const { headerNameLowerCasedRecord } = require('./constants')
const invalidPathRegex = /[^\u0021-\u00ff]/

const kHandler = Symbol('handler')
const kRequest = Symbol('request')
const kResponse = Symbol('response')

class Request {
constructor (origin, {
Expand Down Expand Up @@ -152,6 +154,20 @@ class Request {

this.headers = []

this[kRequest] = {
method: this.method,
origin: this.origin,
path: this.path,
headers: this.headers,
completed: false
}
this[kResponse] = {
headers: null,
statusCode: 0,
statusText: '',
trailers: null
}

// Only for H2
this.expectContinue = expectContinue != null ? expectContinue : false

Expand Down Expand Up @@ -187,7 +203,9 @@ class Request {
this[kHandler] = handler

if (channels.create.hasSubscribers) {
channels.create.publish({ request: this })
channels.create.publish({
request: this[kRequest]
})
}
}

Expand All @@ -203,7 +221,9 @@ class Request {

onRequestSent () {
if (channels.bodySent.hasSubscribers) {
channels.bodySent.publish({ request: this })
channels.bodySent.publish({
request: this[kRequest]
})
}

if (this[kHandler].onRequestSent) {
Expand Down Expand Up @@ -235,8 +255,15 @@ class Request {
assert(!this.aborted)
assert(!this.completed)

this[kResponse].statusCode = statusCode
this[kResponse].headers = headers
this[kResponse].statusText = statusText

if (channels.headers.hasSubscribers) {
channels.headers.publish({ request: this, response: { statusCode, headers, statusText } })
channels.headers.publish({
request: this[kRequest],
response: this[kResponse]
})
}

try {
Expand Down Expand Up @@ -270,9 +297,15 @@ class Request {

assert(!this.aborted)

this[kResponse].trailers = trailers
this[kRequest].completed = true

this.completed = true
if (channels.trailers.hasSubscribers) {
channels.trailers.publish({ request: this, trailers })
channels.trailers.publish({
request: this[kRequest],
response: this[kResponse]
})
}

try {
Expand All @@ -287,7 +320,10 @@ class Request {
this.onFinally()

if (channels.error.hasSubscribers) {
channels.error.publish({ request: this, error })
channels.error.publish({
request: this[kRequest],
error
})
}

if (this.aborted) {
Expand All @@ -309,11 +345,6 @@ class Request {
this.endHandler = null
}
}

addHeader (key, value) {
processHeader(this, key, value)
return this
}
}

function processHeader (request, key, val) {
Expand Down
8 changes: 3 additions & 5 deletions test/node-test/diagnostics-channel/get.js
Expand Up @@ -7,7 +7,7 @@ const { Client } = require('../../..')
const { createServer } = require('node:http')

test('Diagnostics channel - get', (t) => {

Check failure on line 9 in test/node-test/diagnostics-channel/get.js

View workflow job for this annotation

GitHub Actions / test (20, ubuntu-latest) / Test with Node.js 20 on ubuntu-latest

Diagnostics channel - get

Error [ERR_TEST_FAILURE]: { completed: false, headers: [ 'bar', 'bar' ], method: 'GET', origin: 'http://localhost:37319', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: undefined, callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, trailer... at process.emit (node:events:518:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: { completed: false, headers: [ 'bar', 'bar' ], method: 'GET', origin: 'http://localhost:37319', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: undefined, callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, trailer... at res.<computed> [as equal] (/home/runner/work/undici/undici/node_modules/@matteo.collina/tspl/tspl.js:52:35) at /home/runner/work/undici/undici/test/node-test/diagnostics-channel/get.js:71:12 at Channel.publish (node:diagnostics_channel:142:9) at writeH1 (/home/runner/work/undici/undici/lib/dispatcher/client-h1.js:996:26) at Object.write (/home/runner/work/undici/undici/lib/dispatcher/client-h1.js:750:14) at _resume (/home/runner/work/undici/undici/lib/dispatcher/client.js:604:50) at resume (/home/runner/work/undici/undici/lib/dispatcher/client.js:529:3) at Client.<computed> (/home/runner/work/undici/undici/lib/dispatcher/client.js:259:31) at connect (/home/runner/work/undici/undici/lib/dispatcher/client.js:514:18) { generatedMessage: true, code: 'ERR_ASSERTION', actual: [Object], expected: [Request], operator: '==' } }

Check failure on line 9 in test/node-test/diagnostics-channel/get.js

View workflow job for this annotation

GitHub Actions / test (18, ubuntu-latest) / Test with Node.js 18 on ubuntu-latest

Diagnostics channel - get

Error [ERR_TEST_FAILURE]: { completed: false, headers: [ 'bar', 'bar' ], method: 'GET', origin: 'http://localhost:43971', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: undefined, callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, trailer... at process.emit (node:events:517:28) at node:diagnostics_channel:144:11 { failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: { completed: false, headers: [ 'bar', 'bar' ], method: 'GET', origin: 'http://localhost:43971', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: undefined, callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, trailer... at res.<computed> [as equal] (/home/runner/work/undici/undici/node_modules/@matteo.collina/tspl/tspl.js:52:35) at /home/runner/work/undici/undici/test/node-test/diagnostics-channel/get.js:71:12 at Channel.publish (node:diagnostics_channel:141:9) at writeH1 (/home/runner/work/undici/undici/lib/dispatcher/client-h1.js:996:26) at Object.write (/home/runner/work/undici/undici/lib/dispatcher/client-h1.js:750:14) at _resume (/home/runner/work/undici/undici/lib/dispatcher/client.js:604:50) at resume (/home/runner/work/undici/undici/lib/dispatcher/client.js:529:3) at Client.<computed> (/home/runner/work/undici/undici/lib/dispatcher/client.js:259:31) at connect (/home/runner/work/undici/undici/lib/dispatcher/client.js:514:18) { generatedMessage: true, code: 'ERR_ASSERTION', actual: [Object], expected: [Request], operator: '==' }, code: 'ERR_TEST_FAILURE' }

Check failure on line 9 in test/node-test/diagnostics-channel/get.js

View workflow job for this annotation

GitHub Actions / test (18, macos-latest) / Test with Node.js 18 on macos-latest

Diagnostics channel - get

Error [ERR_TEST_FAILURE]: { completed: false, headers: [ 'bar', 'bar' ], method: 'GET', origin: 'http://localhost:52006', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: undefined, callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, trailer... at process.emit (node:events:517:28) at node:diagnostics_channel:144:11 { failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: { completed: false, headers: [ 'bar', 'bar' ], method: 'GET', origin: 'http://localhost:52006', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: undefined, callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, trailer... at res.<computed> [as equal] (/Users/runner/work/undici/undici/node_modules/@matteo.collina/tspl/tspl.js:52:35) at /Users/runner/work/undici/undici/test/node-test/diagnostics-channel/get.js:71:12 at Channel.publish (node:diagnostics_channel:141:9) at writeH1 (/Users/runner/work/undici/undici/lib/dispatcher/client-h1.js:996:26) at Object.write (/Users/runner/work/undici/undici/lib/dispatcher/client-h1.js:750:14) at _resume (/Users/runner/work/undici/undici/lib/dispatcher/client.js:604:50) at resume (/Users/runner/work/undici/undici/lib/dispatcher/client.js:529:3) at Client.<computed> (/Users/runner/work/undici/undici/lib/dispatcher/client.js:259:31) at connect (/Users/runner/work/undici/undici/lib/dispatcher/client.js:514:18) { generatedMessage: true, code: 'ERR_ASSERTION', actual: [Object], expected: [Request], operator: '==' }, code: 'ERR_TEST_FAILURE' }

Check failure on line 9 in test/node-test/diagnostics-channel/get.js

View workflow job for this annotation

GitHub Actions / test (20, macos-latest) / Test with Node.js 20 on macos-latest

Diagnostics channel - get

Error [ERR_TEST_FAILURE]: { completed: false, headers: [ 'bar', 'bar' ], method: 'GET', origin: 'http://localhost:52106', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: undefined, callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, trailer... at process.emit (node:events:518:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: { completed: false, headers: [ 'bar', 'bar' ], method: 'GET', origin: 'http://localhost:52106', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: undefined, callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, trailer... at res.<computed> [as equal] (/Users/runner/work/undici/undici/node_modules/@matteo.collina/tspl/tspl.js:52:35) at /Users/runner/work/undici/undici/test/node-test/diagnostics-channel/get.js:71:12 at Channel.publish (node:diagnostics_channel:142:9) at writeH1 (/Users/runner/work/undici/undici/lib/dispatcher/client-h1.js:996:26) at Object.write (/Users/runner/work/undici/undici/lib/dispatcher/client-h1.js:750:14) at _resume (/Users/runner/work/undici/undici/lib/dispatcher/client.js:604:50) at resume (/Users/runner/work/undici/undici/lib/dispatcher/client.js:529:3) at Client.<computed> (/Users/runner/work/undici/undici/lib/dispatcher/client.js:259:31) at connect (/Users/runner/work/undici/undici/lib/dispatcher/client.js:514:18) { generatedMessage: true, code: 'ERR_ASSERTION', actual: [Object], expected: [Request], operator: '==' } }

Check failure on line 9 in test/node-test/diagnostics-channel/get.js

View workflow job for this annotation

GitHub Actions / test (21, macos-latest) / Test with Node.js 21 on macos-latest

Diagnostics channel - get

Error [ERR_TEST_FAILURE]: { completed: false, headers: [ 'bar', 'bar' ], method: 'GET', origin: 'http://localhost:54221', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: undefined, callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, trailer... at process.emit (node:events:519:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: { completed: false, headers: [ 'bar', 'bar' ], method: 'GET', origin: 'http://localhost:54221', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: undefined, callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, trailer... at res.<computed> [as equal] (/Users/runner/work/undici/undici/node_modules/@matteo.collina/tspl/tspl.js:52:35) at /Users/runner/work/undici/undici/test/node-test/diagnostics-channel/get.js:71:12 at Channel.publish (node:diagnostics_channel:142:9) at writeH1 (/Users/runner/work/undici/undici/lib/dispatcher/client-h1.js:996:26) at Object.write (/Users/runner/work/undici/undici/lib/dispatcher/client-h1.js:750:14) at _resume (/Users/runner/work/undici/undici/lib/dispatcher/client.js:604:50) at resume (/Users/runner/work/undici/undici/lib/dispatcher/client.js:529:3) at Client.<computed> (/Users/runner/work/undici/undici/lib/dispatcher/client.js:259:31) at connect (/Users/runner/work/undici/undici/lib/dispatcher/client.js:514:18) { generatedMessage: true, code: 'ERR_ASSERTION', actual: [Object], expected: [Request], operator: '==' } }
const assert = tspl(t, { plan: 32 })
const assert = tspl(t, { plan: 31 })
const server = createServer((req, res) => {
res.setHeader('Content-Type', 'text/plain')
res.setHeader('trailer', 'foo')
Expand All @@ -33,8 +33,6 @@ test('Diagnostics channel - get', (t) => {
assert.equal(request.method, 'GET')
assert.equal(request.path, '/')
assert.deepStrictEqual(request.headers, ['bar', 'bar'])
request.addHeader('hello', 'world')
assert.deepStrictEqual(request.headers, ['bar', 'bar', 'hello', 'world'])
})

let _connector
Expand Down Expand Up @@ -108,13 +106,13 @@ test('Diagnostics channel - get', (t) => {
let endEmitted = false

return new Promise((resolve) => {
diagnosticsChannel.channel('undici:request:trailers').subscribe(({ request, trailers }) => {
diagnosticsChannel.channel('undici:request:trailers').subscribe(({ request, response }) => {
assert.equal(request.completed, true)
assert.equal(_req, request)
// This event is emitted after the last chunk has been added to the body stream,
// not when it was consumed by the application
assert.equal(endEmitted, false)
assert.deepStrictEqual(trailers, [Buffer.from('foo'), Buffer.from('oof')])
assert.deepStrictEqual(response.trailers, [Buffer.from('foo'), Buffer.from('oof')])
resolve()
})

Expand Down
5 changes: 1 addition & 4 deletions test/node-test/diagnostics-channel/post-stream.js
Expand Up @@ -8,7 +8,7 @@ const { Client } = require('../../..')
const { createServer } = require('node:http')

test('Diagnostics channel - post stream', (t) => {

Check failure on line 10 in test/node-test/diagnostics-channel/post-stream.js

View workflow job for this annotation

GitHub Actions / test (20, ubuntu-latest) / Test with Node.js 20 on ubuntu-latest

Diagnostics channel - post stream

Error [ERR_TEST_FAILURE]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:42483', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: Readable { [Symbol(kCapture)]: false, [Symbol(shapeMode)]: true, _destroy: [Function (anonymous)], _events: { close: undefined, data: undefined, end: undefined, erro... at process.emit (node:events:518:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:42483', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: Readable { [Symbol(kCapture)]: false, [Symbol(shapeMode)]: true, _destroy: [Function (anonymous)], _events: { close: undefined, data: undefined, end: undefined, erro... at res.<computed> [as equal] (/home/runner/work/undici/undici/node_modules/@matteo.collina/tspl/tspl.js:52:35) at /home/runner/work/undici/undici/test/node-test/diagnostics-channel/post-stream.js:72:12 at Channel.publish (node:diagnostics_channel:142:9) at writeH1 (/home/runner/work/undici/undici/lib/dispatcher/client-h1.js:996:26) at Object.write (/home/runner/work/undici/undici/lib/dispatcher/client-h1.js:750:14) at _resume (/home/runner/work/undici/undici/lib/dispatcher/client.js:604:50) at resume (/home/runner/work/undici/undici/lib/dispatcher/client.js:529:3) at Client.<computed> (/home/runner/work/undici/undici/lib/dispatcher/client.js:259:31) at connect (/home/runner/work/undici/undici/lib/dispatcher/client.js:514:18) { generatedMessage: true, code: 'ERR_ASSERTION', actual: [Object], expected: [Request], operator: '==' } }

Check failure on line 10 in test/node-test/diagnostics-channel/post-stream.js

View workflow job for this annotation

GitHub Actions / test (18, ubuntu-latest) / Test with Node.js 18 on ubuntu-latest

Diagnostics channel - post stream

Error [ERR_TEST_FAILURE]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:36621', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: Readable { [Symbol(kCapture)]: false, _destroy: [Function (anonymous)], _events: [Object: null prototype] { error: [ [Function (anonymous)], [Function (anonymous)] ] ... at process.emit (node:events:517:28) at node:diagnostics_channel:144:11 { failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:36621', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: Readable { [Symbol(kCapture)]: false, _destroy: [Function (anonymous)], _events: [Object: null prototype] { error: [ [Function (anonymous)], [Function (anonymous)] ] ... at res.<computed> [as equal] (/home/runner/work/undici/undici/node_modules/@matteo.collina/tspl/tspl.js:52:35) at /home/runner/work/undici/undici/test/node-test/diagnostics-channel/post-stream.js:72:12 at Channel.publish (node:diagnostics_channel:141:9) at writeH1 (/home/runner/work/undici/undici/lib/dispatcher/client-h1.js:996:26) at Object.write (/home/runner/work/undici/undici/lib/dispatcher/client-h1.js:750:14) at _resume (/home/runner/work/undici/undici/lib/dispatcher/client.js:604:50) at resume (/home/runner/work/undici/undici/lib/dispatcher/client.js:529:3) at Client.<computed> (/home/runner/work/undici/undici/lib/dispatcher/client.js:259:31) at connect (/home/runner/work/undici/undici/lib/dispatcher/client.js:514:18) { generatedMessage: true, code: 'ERR_ASSERTION', actual: [Object], expected: [Request], operator: '==' }, code: 'ERR_TEST_FAILURE' }

Check failure on line 10 in test/node-test/diagnostics-channel/post-stream.js

View workflow job for this annotation

GitHub Actions / test (18, macos-latest) / Test with Node.js 18 on macos-latest

Diagnostics channel - post stream

Error [ERR_TEST_FAILURE]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:52004', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: Readable { [Symbol(kCapture)]: false, _destroy: [Function (anonymous)], _events: [Object: null prototype] { error: [ [Function (anonymous)], [Function (anonymous)] ] ... at process.emit (node:events:517:28) at node:diagnostics_channel:144:11 { failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:52004', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: Readable { [Symbol(kCapture)]: false, _destroy: [Function (anonymous)], _events: [Object: null prototype] { error: [ [Function (anonymous)], [Function (anonymous)] ] ... at res.<computed> [as equal] (/Users/runner/work/undici/undici/node_modules/@matteo.collina/tspl/tspl.js:52:35) at /Users/runner/work/undici/undici/test/node-test/diagnostics-channel/post-stream.js:72:12 at Channel.publish (node:diagnostics_channel:141:9) at writeH1 (/Users/runner/work/undici/undici/lib/dispatcher/client-h1.js:996:26) at Object.write (/Users/runner/work/undici/undici/lib/dispatcher/client-h1.js:750:14) at _resume (/Users/runner/work/undici/undici/lib/dispatcher/client.js:604:50) at resume (/Users/runner/work/undici/undici/lib/dispatcher/client.js:529:3) at Client.<computed> (/Users/runner/work/undici/undici/lib/dispatcher/client.js:259:31) at connect (/Users/runner/work/undici/undici/lib/dispatcher/client.js:514:18) { generatedMessage: true, code: 'ERR_ASSERTION', actual: [Object], expected: [Request], operator: '==' }, code: 'ERR_TEST_FAILURE' }

Check failure on line 10 in test/node-test/diagnostics-channel/post-stream.js

View workflow job for this annotation

GitHub Actions / test (20, macos-latest) / Test with Node.js 20 on macos-latest

Diagnostics channel - post stream

Error [ERR_TEST_FAILURE]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:52104', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: Readable { [Symbol(kCapture)]: false, [Symbol(shapeMode)]: true, _destroy: [Function (anonymous)], _events: { close: undefined, data: undefined, end: undefined, erro... at process.emit (node:events:518:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:52104', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: Readable { [Symbol(kCapture)]: false, [Symbol(shapeMode)]: true, _destroy: [Function (anonymous)], _events: { close: undefined, data: undefined, end: undefined, erro... at res.<computed> [as equal] (/Users/runner/work/undici/undici/node_modules/@matteo.collina/tspl/tspl.js:52:35) at /Users/runner/work/undici/undici/test/node-test/diagnostics-channel/post-stream.js:72:12 at Channel.publish (node:diagnostics_channel:142:9) at writeH1 (/Users/runner/work/undici/undici/lib/dispatcher/client-h1.js:996:26) at Object.write (/Users/runner/work/undici/undici/lib/dispatcher/client-h1.js:750:14) at _resume (/Users/runner/work/undici/undici/lib/dispatcher/client.js:604:50) at resume (/Users/runner/work/undici/undici/lib/dispatcher/client.js:529:3) at Client.<computed> (/Users/runner/work/undici/undici/lib/dispatcher/client.js:259:31) at connect (/Users/runner/work/undici/undici/lib/dispatcher/client.js:514:18) { generatedMessage: true, code: 'ERR_ASSERTION', actual: [Object], expected: [Request], operator: '==' } }

Check failure on line 10 in test/node-test/diagnostics-channel/post-stream.js

View workflow job for this annotation

GitHub Actions / test (21, macos-latest) / Test with Node.js 21 on macos-latest

Diagnostics channel - post stream

Error [ERR_TEST_FAILURE]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:54219', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: Readable { [Symbol(kCapture)]: false, [Symbol(shapeMode)]: true, _destroy: [Function (anonymous)], _events: { close: undefined, data: undefined, end: undefined, erro... at process.emit (node:events:519:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:54219', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: Readable { [Symbol(kCapture)]: false, [Symbol(shapeMode)]: true, _destroy: [Function (anonymous)], _events: { close: undefined, data: undefined, end: undefined, erro... at res.<computed> [as equal] (/Users/runner/work/undici/undici/node_modules/@matteo.collina/tspl/tspl.js:52:35) at /Users/runner/work/undici/undici/test/node-test/diagnostics-channel/post-stream.js:72:12 at Channel.publish (node:diagnostics_channel:142:9) at writeH1 (/Users/runner/work/undici/undici/lib/dispatcher/client-h1.js:996:26) at Object.write (/Users/runner/work/undici/undici/lib/dispatcher/client-h1.js:750:14) at _resume (/Users/runner/work/undici/undici/lib/dispatcher/client.js:604:50) at resume (/Users/runner/work/undici/undici/lib/dispatcher/client.js:529:3) at Client.<computed> (/Users/runner/work/undici/undici/lib/dispatcher/client.js:259:31) at connect (/Users/runner/work/undici/undici/lib/dispatcher/client.js:514:18) { generatedMessage: true, code: 'ERR_ASSERTION', actual: [Object], expected: [Request], operator: '==' } }
const assert = tspl(t, { plan: 33 })
const assert = tspl(t, { plan: 31 })
const server = createServer((req, res) => {
req.resume()
res.setHeader('Content-Type', 'text/plain')
Expand All @@ -34,9 +34,6 @@ test('Diagnostics channel - post stream', (t) => {
assert.equal(request.method, 'POST')
assert.equal(request.path, '/')
assert.deepStrictEqual(request.headers, ['bar', 'bar'])
request.addHeader('hello', 'world')
assert.deepStrictEqual(request.headers, ['bar', 'bar', 'hello', 'world'])
assert.deepStrictEqual(request.body, body)
})

let _connector
Expand Down
5 changes: 1 addition & 4 deletions test/node-test/diagnostics-channel/post.js
Expand Up @@ -7,7 +7,7 @@ const { Client } = require('../../../')
const { createServer } = require('node:http')

test('Diagnostics channel - post', (t) => {

Check failure on line 9 in test/node-test/diagnostics-channel/post.js

View workflow job for this annotation

GitHub Actions / test (20, ubuntu-latest) / Test with Node.js 20 on ubuntu-latest

Diagnostics channel - post

Error [ERR_TEST_FAILURE]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:38519', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: 'hello world', callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, tra... at process.emit (node:events:518:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:38519', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: 'hello world', callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, tra... at res.<computed> [as equal] (/home/runner/work/undici/undici/node_modules/@matteo.collina/tspl/tspl.js:52:35) at /home/runner/work/undici/undici/test/node-test/diagnostics-channel/post.js:70:12 at Channel.publish (node:diagnostics_channel:142:9) at writeH1 (/home/runner/work/undici/undici/lib/dispatcher/client-h1.js:996:26) at Object.write (/home/runner/work/undici/undici/lib/dispatcher/client-h1.js:750:14) at _resume (/home/runner/work/undici/undici/lib/dispatcher/client.js:604:50) at resume (/home/runner/work/undici/undici/lib/dispatcher/client.js:529:3) at Client.<computed> (/home/runner/work/undici/undici/lib/dispatcher/client.js:259:31) at connect (/home/runner/work/undici/undici/lib/dispatcher/client.js:514:18) { generatedMessage: true, code: 'ERR_ASSERTION', actual: [Object], expected: [Request], operator: '==' } }

Check failure on line 9 in test/node-test/diagnostics-channel/post.js

View workflow job for this annotation

GitHub Actions / test (18, ubuntu-latest) / Test with Node.js 18 on ubuntu-latest

Diagnostics channel - post

Error [ERR_TEST_FAILURE]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:36391', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: 'hello world', callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, tra... at process.emit (node:events:517:28) at node:diagnostics_channel:144:11 { failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:36391', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: 'hello world', callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, tra... at res.<computed> [as equal] (/home/runner/work/undici/undici/node_modules/@matteo.collina/tspl/tspl.js:52:35) at /home/runner/work/undici/undici/test/node-test/diagnostics-channel/post.js:70:12 at Channel.publish (node:diagnostics_channel:141:9) at writeH1 (/home/runner/work/undici/undici/lib/dispatcher/client-h1.js:996:26) at Object.write (/home/runner/work/undici/undici/lib/dispatcher/client-h1.js:750:14) at _resume (/home/runner/work/undici/undici/lib/dispatcher/client.js:604:50) at resume (/home/runner/work/undici/undici/lib/dispatcher/client.js:529:3) at Client.<computed> (/home/runner/work/undici/undici/lib/dispatcher/client.js:259:31) at connect (/home/runner/work/undici/undici/lib/dispatcher/client.js:514:18) { generatedMessage: true, code: 'ERR_ASSERTION', actual: [Object], expected: [Request], operator: '==' }, code: 'ERR_TEST_FAILURE' }

Check failure on line 9 in test/node-test/diagnostics-channel/post.js

View workflow job for this annotation

GitHub Actions / test (18, macos-latest) / Test with Node.js 18 on macos-latest

Diagnostics channel - post

Error [ERR_TEST_FAILURE]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:51940', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: 'hello world', callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, tra... at process.emit (node:events:517:28) at node:diagnostics_channel:144:11 { failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:51940', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: 'hello world', callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, tra... at res.<computed> [as equal] (/Users/runner/work/undici/undici/node_modules/@matteo.collina/tspl/tspl.js:52:35) at /Users/runner/work/undici/undici/test/node-test/diagnostics-channel/post.js:70:12 at Channel.publish (node:diagnostics_channel:141:9) at writeH1 (/Users/runner/work/undici/undici/lib/dispatcher/client-h1.js:996:26) at Object.write (/Users/runner/work/undici/undici/lib/dispatcher/client-h1.js:750:14) at _resume (/Users/runner/work/undici/undici/lib/dispatcher/client.js:604:50) at resume (/Users/runner/work/undici/undici/lib/dispatcher/client.js:529:3) at Client.<computed> (/Users/runner/work/undici/undici/lib/dispatcher/client.js:259:31) at connect (/Users/runner/work/undici/undici/lib/dispatcher/client.js:514:18) { generatedMessage: true, code: 'ERR_ASSERTION', actual: [Object], expected: [Request], operator: '==' }, code: 'ERR_TEST_FAILURE' }

Check failure on line 9 in test/node-test/diagnostics-channel/post.js

View workflow job for this annotation

GitHub Actions / test (20, macos-latest) / Test with Node.js 20 on macos-latest

Diagnostics channel - post

Error [ERR_TEST_FAILURE]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:52077', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: 'hello world', callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, tra... at process.emit (node:events:518:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:52077', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: 'hello world', callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, tra... at res.<computed> [as equal] (/Users/runner/work/undici/undici/node_modules/@matteo.collina/tspl/tspl.js:52:35) at /Users/runner/work/undici/undici/test/node-test/diagnostics-channel/post.js:70:12 at Channel.publish (node:diagnostics_channel:142:9) at writeH1 (/Users/runner/work/undici/undici/lib/dispatcher/client-h1.js:996:26) at Object.write (/Users/runner/work/undici/undici/lib/dispatcher/client-h1.js:750:14) at _resume (/Users/runner/work/undici/undici/lib/dispatcher/client.js:604:50) at resume (/Users/runner/work/undici/undici/lib/dispatcher/client.js:529:3) at Client.<computed> (/Users/runner/work/undici/undici/lib/dispatcher/client.js:259:31) at connect (/Users/runner/work/undici/undici/lib/dispatcher/client.js:514:18) { generatedMessage: true, code: 'ERR_ASSERTION', actual: [Object], expected: [Request], operator: '==' } }

Check failure on line 9 in test/node-test/diagnostics-channel/post.js

View workflow job for this annotation

GitHub Actions / test (21, macos-latest) / Test with Node.js 21 on macos-latest

Diagnostics channel - post

Error [ERR_TEST_FAILURE]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:54192', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: 'hello world', callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, tra... at process.emit (node:events:519:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: { completed: false, headers: [ 'bar', 'bar' ], method: 'POST', origin: 'http://localhost:54192', path: '/' } == Request { [Symbol(handler)]: RequestHandler { [Symbol(async_id_symbol)]: 47, [Symbol(destroyed)]: { destroyed: false }, [Symbol(kListener)]: null, [Symbol(kSignal)]: null, [Symbol(trigger_async_id_symbol)]: 28, abort: [Function (anonymous)], body: 'hello world', callback: [Function (anonymous)], context: undefined, highWaterMark: undefined, onInfo: null, opaque: null, res: null, responseHeaders: null, throwOnError: undefined, tra... at res.<computed> [as equal] (/Users/runner/work/undici/undici/node_modules/@matteo.collina/tspl/tspl.js:52:35) at /Users/runner/work/undici/undici/test/node-test/diagnostics-channel/post.js:70:12 at Channel.publish (node:diagnostics_channel:142:9) at writeH1 (/Users/runner/work/undici/undici/lib/dispatcher/client-h1.js:996:26) at Object.write (/Users/runner/work/undici/undici/lib/dispatcher/client-h1.js:750:14) at _resume (/Users/runner/work/undici/undici/lib/dispatcher/client.js:604:50) at resume (/Users/runner/work/undici/undici/lib/dispatcher/client.js:529:3) at Client.<computed> (/Users/runner/work/undici/undici/lib/dispatcher/client.js:259:31) at connect (/Users/runner/work/undici/undici/lib/dispatcher/client.js:514:18) { generatedMessage: true, code: 'ERR_ASSERTION', actual: [Object], expected: [Request], operator: '==' } }
const assert = tspl(t, { plan: 33 })
const assert = tspl(t, { plan: 31 })
const server = createServer((req, res) => {
req.resume()
res.setHeader('Content-Type', 'text/plain')
Expand All @@ -32,9 +32,6 @@ test('Diagnostics channel - post', (t) => {
assert.equal(request.method, 'POST')
assert.equal(request.path, '/')
assert.deepStrictEqual(request.headers, ['bar', 'bar'])
request.addHeader('hello', 'world')
assert.deepStrictEqual(request.headers, ['bar', 'bar', 'hello', 'world'])
assert.deepStrictEqual(request.body, Buffer.from('hello world'))
})

let _connector
Expand Down
3 changes: 0 additions & 3 deletions test/types/diagnostics-channel.test-d.ts
Expand Up @@ -8,9 +8,6 @@ const request = {
method: "GET" as const,
path: "",
headers: "",
addHeader: (key: string, value: string) => {
return request;
},
};

const response = {
Expand Down
1 change: 0 additions & 1 deletion types/diagnostics-channel.d.ts
Expand Up @@ -10,7 +10,6 @@ declare namespace DiagnosticsChannel {
method?: Dispatcher.HttpMethod;
path: string;
headers: string;
addHeader(key: string, value: string): Request;
}
interface Response {
statusCode: number;
Expand Down

0 comments on commit ffb7cb4

Please sign in to comment.