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 89dfbd7
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 51 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
39 changes: 29 additions & 10 deletions lib/core/request.js
Expand Up @@ -91,6 +91,8 @@ class Request {

this.abort = null

this.publicInterface = null

if (body == null) {
this.body = null
} else if (isStream(body)) {
Expand Down Expand Up @@ -187,10 +189,32 @@ class Request {
this[kHandler] = handler

if (channels.create.hasSubscribers) {
channels.create.publish({ request: this })
channels.create.publish({ request: this.getPublicInterface() })
}
}

getPublicInterface () {
const self = this
this.publicInterface ??= {
get origin () {
return self.origin
},
get method () {
return self.method
},
get path () {
return self.path
},
get headers () {
return self.headers
},
get completed () {
return self.completed
}
}
return this.publicInterface
}

onBodySent (chunk) {
if (this[kHandler].onBodySent) {
try {
Expand All @@ -203,7 +227,7 @@ class Request {

onRequestSent () {
if (channels.bodySent.hasSubscribers) {
channels.bodySent.publish({ request: this })
channels.bodySent.publish({ request: this.getPublicInterface() })
}

if (this[kHandler].onRequestSent) {
Expand Down Expand Up @@ -236,7 +260,7 @@ class Request {
assert(!this.completed)

if (channels.headers.hasSubscribers) {
channels.headers.publish({ request: this, response: { statusCode, headers, statusText } })
channels.headers.publish({ request: this.getPublicInterface(), headers, statusText, statusCode })
}

try {
Expand Down Expand Up @@ -272,7 +296,7 @@ class Request {

this.completed = true
if (channels.trailers.hasSubscribers) {
channels.trailers.publish({ request: this, trailers })
channels.trailers.publish({ request: this.getPublicInterface(), trailers })
}

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

if (channels.error.hasSubscribers) {
channels.error.publish({ request: this, error })
channels.error.publish({ request: this.getPublicInterface(), error })
}

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

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

function processHeader (request, key, val) {
Expand Down
2 changes: 1 addition & 1 deletion lib/dispatcher/client-h1.js
Expand Up @@ -993,7 +993,7 @@ function writeH1 (client, request) {
}

if (channels.sendHeaders.hasSubscribers) {
channels.sendHeaders.publish({ request, headers: header, socket })
channels.sendHeaders.publish({ request: request.getPublicInterface(), headers: header, socket })
}

/* istanbul ignore else: assertion */
Expand Down
14 changes: 6 additions & 8 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) => {
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 @@ -84,25 +82,25 @@ test('Diagnostics channel - get', (t) => {
assert.deepStrictEqual(headers, expectedHeaders.join('\r\n') + '\r\n')

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

View workflow job for this annotation

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

Diagnostics channel - get

Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected + 'GET / HTTP/1.1\r\nhost: localhost:32867\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'GET / HTTP/1.1\r\n' + - 'host: localhost:32867\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at process.emit (node:events:519:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + 'GET / HTTP/1.1\r\nhost: localhost:32867\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'GET / HTTP/1.1\r\n' + - 'host: localhost:32867\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at res.<computed> [as deepStrictEqual] (/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:82: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: 'GET / HTTP/1.1\r\nhost: localhost:32867\r\nconnection: keep-alive\r\nbar: bar\r\n', expected: 'GET / HTTP/1.1\r\nhost: localhost:32867\r\nconnection: keep-alive\r\nbar: bar\r\nhello: world\r\n', operator: 'deepStrictEqual' } }

Check failure on line 82 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]: Expected values to be strictly deep-equal: + actual - expected + 'GET / HTTP/1.1\r\nhost: localhost:36255\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'GET / HTTP/1.1\r\n' + - 'host: localhost:36255\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at process.emit (node:events:518:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + 'GET / HTTP/1.1\r\nhost: localhost:36255\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'GET / HTTP/1.1\r\n' + - 'host: localhost:36255\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at res.<computed> [as deepStrictEqual] (/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:82: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: 'GET / HTTP/1.1\r\nhost: localhost:36255\r\nconnection: keep-alive\r\nbar: bar\r\n', expected: 'GET / HTTP/1.1\r\nhost: localhost:36255\r\nconnection: keep-alive\r\nbar: bar\r\nhello: world\r\n', operator: 'deepStrictEqual' } }

Check failure on line 82 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]: Expected values to be strictly deep-equal: + actual - expected + 'GET / HTTP/1.1\r\nhost: localhost:41849\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'GET / HTTP/1.1\r\n' + - 'host: localhost:41849\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at process.emit (node:events:517:28) at node:diagnostics_channel:144:11 { failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + 'GET / HTTP/1.1\r\nhost: localhost:41849\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'GET / HTTP/1.1\r\n' + - 'host: localhost:41849\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at res.<computed> [as deepStrictEqual] (/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:82: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: 'GET / HTTP/1.1\r\nhost: localhost:41849\r\nconnection: keep-alive\r\nbar: bar\r\n', expected: 'GET / HTTP/1.1\r\nhost: localhost:41849\r\nconnection: keep-alive\r\nbar: bar\r\nhello: world\r\n', operator: 'deepStrictEqual' }, code: 'ERR_TEST_FAILURE' }

Check failure on line 82 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]: Expected values to be strictly deep-equal: + actual - expected + 'GET / HTTP/1.1\r\nhost: localhost:52109\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'GET / HTTP/1.1\r\n' + - 'host: localhost:52109\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at process.emit (node:events:518:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + 'GET / HTTP/1.1\r\nhost: localhost:52109\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'GET / HTTP/1.1\r\n' + - 'host: localhost:52109\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at res.<computed> [as deepStrictEqual] (/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:82: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: 'GET / HTTP/1.1\r\nhost: localhost:52109\r\nconnection: keep-alive\r\nbar: bar\r\n', expected: 'GET / HTTP/1.1\r\nhost: localhost:52109\r\nconnection: keep-alive\r\nbar: bar\r\nhello: world\r\n', operator: 'deepStrictEqual' } }

Check failure on line 82 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]: Expected values to be strictly deep-equal: + actual - expected + 'GET / HTTP/1.1\r\nhost: localhost:51986\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'GET / HTTP/1.1\r\n' + - 'host: localhost:51986\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at process.emit (node:events:517:28) at node:diagnostics_channel:144:11 { failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + 'GET / HTTP/1.1\r\nhost: localhost:51986\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'GET / HTTP/1.1\r\n' + - 'host: localhost:51986\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at res.<computed> [as deepStrictEqual] (/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:82: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: 'GET / HTTP/1.1\r\nhost: localhost:51986\r\nconnection: keep-alive\r\nbar: bar\r\n', expected: 'GET / HTTP/1.1\r\nhost: localhost:51986\r\nconnection: keep-alive\r\nbar: bar\r\nhello: world\r\n', operator: 'deepStrictEqual' }, code: 'ERR_TEST_FAILURE' }

Check failure on line 82 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]: Expected values to be strictly deep-equal: + actual - expected + 'GET / HTTP/1.1\r\nhost: localhost:53587\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'GET / HTTP/1.1\r\n' + - 'host: localhost:53587\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at process.emit (node:events:519:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + 'GET / HTTP/1.1\r\nhost: localhost:53587\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'GET / HTTP/1.1\r\n' + - 'host: localhost:53587\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at res.<computed> [as deepStrictEqual] (/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:82: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: 'GET / HTTP/1.1\r\nhost: localhost:53587\r\nconnection: keep-alive\r\nbar: bar\r\n', expected: 'GET / HTTP/1.1\r\nhost: localhost:53587\r\nconnection: keep-alive\r\nbar: bar\r\nhello: world\r\n', operator: 'deepStrictEqual' } }
})

diagnosticsChannel.channel('undici:request:headers').subscribe(({ request, response }) => {
diagnosticsChannel.channel('undici:request:headers').subscribe(({ request, headers, statusCode, statusText }) => {
assert.equal(_req, request)
assert.equal(response.statusCode, 200)
assert.equal(statusCode, 200)
const expectedHeaders = [
Buffer.from('Content-Type'),
Buffer.from('text/plain'),
Buffer.from('trailer'),
Buffer.from('foo'),
Buffer.from('Date'),
response.headers[5], // This is a date
headers[5], // This is a date
Buffer.from('Connection'),
Buffer.from('keep-alive'),
Buffer.from('Keep-Alive'),
Buffer.from('timeout=5'),
Buffer.from('Transfer-Encoding'),
Buffer.from('chunked')
]
assert.deepStrictEqual(response.headers, expectedHeaders)
assert.equal(response.statusText, 'OK')
assert.deepStrictEqual(headers, expectedHeaders)
assert.equal(statusText, 'OK')
})

let endEmitted = false
Expand Down
15 changes: 6 additions & 9 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) => {
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 Expand Up @@ -86,25 +83,25 @@ test('Diagnostics channel - post stream', (t) => {
assert.equal(headers, expectedHeaders.join('\r\n') + '\r\n')

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

View workflow job for this annotation

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

Diagnostics channel - post stream

Error [ERR_TEST_FAILURE]: 'POST / HTTP/1.1\r\nhost: localhost:33439\r\nconnection: keep-alive\r\nbar: bar\r\n' == 'POST / HTTP/1.1\r\n' + 'host: localhost:33439\r\n' + 'connection: keep-alive\r\n' + 'bar: bar\r\n' + 'hello: world\r\n' at process.emit (node:events:519:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: 'POST / HTTP/1.1\r\nhost: localhost:33439\r\nconnection: keep-alive\r\nbar: bar\r\n' == 'POST / HTTP/1.1\r\n' + 'host: localhost:33439\r\n' + 'connection: keep-alive\r\n' + 'bar: bar\r\n' + 'hello: world\r\n' 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:83: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: 'POST / HTTP/1.1\r\nhost: localhost:33439\r\nconnection: keep-alive\r\nbar: bar\r\n', expected: 'POST / HTTP/1.1\r\nhost: localhost:33439\r\nconnection: keep-alive\r\nbar: bar\r\nhello: world\r\n', operator: '==' } }

Check failure on line 83 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]: 'POST / HTTP/1.1\r\nhost: localhost:45617\r\nconnection: keep-alive\r\nbar: bar\r\n' == 'POST / HTTP/1.1\r\n' + 'host: localhost:45617\r\n' + 'connection: keep-alive\r\n' + 'bar: bar\r\n' + 'hello: world\r\n' at process.emit (node:events:518:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: 'POST / HTTP/1.1\r\nhost: localhost:45617\r\nconnection: keep-alive\r\nbar: bar\r\n' == 'POST / HTTP/1.1\r\n' + 'host: localhost:45617\r\n' + 'connection: keep-alive\r\n' + 'bar: bar\r\n' + 'hello: world\r\n' 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:83: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: 'POST / HTTP/1.1\r\nhost: localhost:45617\r\nconnection: keep-alive\r\nbar: bar\r\n', expected: 'POST / HTTP/1.1\r\nhost: localhost:45617\r\nconnection: keep-alive\r\nbar: bar\r\nhello: world\r\n', operator: '==' } }

Check failure on line 83 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]: 'POST / HTTP/1.1\r\nhost: localhost:38687\r\nconnection: keep-alive\r\nbar: bar\r\n' == 'POST / HTTP/1.1\r\n' + 'host: localhost:38687\r\n' + 'connection: keep-alive\r\n' + 'bar: bar\r\n' + 'hello: world\r\n' at process.emit (node:events:517:28) at node:diagnostics_channel:144:11 { failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: 'POST / HTTP/1.1\r\nhost: localhost:38687\r\nconnection: keep-alive\r\nbar: bar\r\n' == 'POST / HTTP/1.1\r\n' + 'host: localhost:38687\r\n' + 'connection: keep-alive\r\n' + 'bar: bar\r\n' + 'hello: world\r\n' 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:83: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: 'POST / HTTP/1.1\r\nhost: localhost:38687\r\nconnection: keep-alive\r\nbar: bar\r\n', expected: 'POST / HTTP/1.1\r\nhost: localhost:38687\r\nconnection: keep-alive\r\nbar: bar\r\nhello: world\r\n', operator: '==' }, code: 'ERR_TEST_FAILURE' }

Check failure on line 83 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]: 'POST / HTTP/1.1\r\nhost: localhost:52107\r\nconnection: keep-alive\r\nbar: bar\r\n' == 'POST / HTTP/1.1\r\n' + 'host: localhost:52107\r\n' + 'connection: keep-alive\r\n' + 'bar: bar\r\n' + 'hello: world\r\n' at process.emit (node:events:518:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: 'POST / HTTP/1.1\r\nhost: localhost:52107\r\nconnection: keep-alive\r\nbar: bar\r\n' == 'POST / HTTP/1.1\r\n' + 'host: localhost:52107\r\n' + 'connection: keep-alive\r\n' + 'bar: bar\r\n' + 'hello: world\r\n' 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:83: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: 'POST / HTTP/1.1\r\nhost: localhost:52107\r\nconnection: keep-alive\r\nbar: bar\r\n', expected: 'POST / HTTP/1.1\r\nhost: localhost:52107\r\nconnection: keep-alive\r\nbar: bar\r\nhello: world\r\n', operator: '==' } }

Check failure on line 83 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]: 'POST / HTTP/1.1\r\nhost: localhost:51984\r\nconnection: keep-alive\r\nbar: bar\r\n' == 'POST / HTTP/1.1\r\n' + 'host: localhost:51984\r\n' + 'connection: keep-alive\r\n' + 'bar: bar\r\n' + 'hello: world\r\n' at process.emit (node:events:517:28) at node:diagnostics_channel:144:11 { failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: 'POST / HTTP/1.1\r\nhost: localhost:51984\r\nconnection: keep-alive\r\nbar: bar\r\n' == 'POST / HTTP/1.1\r\n' + 'host: localhost:51984\r\n' + 'connection: keep-alive\r\n' + 'bar: bar\r\n' + 'hello: world\r\n' 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:83: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: 'POST / HTTP/1.1\r\nhost: localhost:51984\r\nconnection: keep-alive\r\nbar: bar\r\n', expected: 'POST / HTTP/1.1\r\nhost: localhost:51984\r\nconnection: keep-alive\r\nbar: bar\r\nhello: world\r\n', operator: '==' }, code: 'ERR_TEST_FAILURE' }

Check failure on line 83 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]: 'POST / HTTP/1.1\r\nhost: localhost:53585\r\nconnection: keep-alive\r\nbar: bar\r\n' == 'POST / HTTP/1.1\r\n' + 'host: localhost:53585\r\n' + 'connection: keep-alive\r\n' + 'bar: bar\r\n' + 'hello: world\r\n' at process.emit (node:events:519:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: 'POST / HTTP/1.1\r\nhost: localhost:53585\r\nconnection: keep-alive\r\nbar: bar\r\n' == 'POST / HTTP/1.1\r\n' + 'host: localhost:53585\r\n' + 'connection: keep-alive\r\n' + 'bar: bar\r\n' + 'hello: world\r\n' 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:83: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: 'POST / HTTP/1.1\r\nhost: localhost:53585\r\nconnection: keep-alive\r\nbar: bar\r\n', expected: 'POST / HTTP/1.1\r\nhost: localhost:53585\r\nconnection: keep-alive\r\nbar: bar\r\nhello: world\r\n', operator: '==' } }
})

diagnosticsChannel.channel('undici:request:headers').subscribe(({ request, response }) => {
diagnosticsChannel.channel('undici:request:headers').subscribe(({ request, headers, statusCode, statusText }) => {
assert.equal(_req, request)
assert.equal(response.statusCode, 200)
assert.equal(statusCode, 200)
const expectedHeaders = [
Buffer.from('Content-Type'),
Buffer.from('text/plain'),
Buffer.from('trailer'),
Buffer.from('foo'),
Buffer.from('Date'),
response.headers[5], // This is a date
headers[5], // This is a date
Buffer.from('Connection'),
Buffer.from('keep-alive'),
Buffer.from('Keep-Alive'),
Buffer.from('timeout=5'),
Buffer.from('Transfer-Encoding'),
Buffer.from('chunked')
]
assert.deepStrictEqual(response.headers, expectedHeaders)
assert.equal(response.statusText, 'OK')
assert.deepStrictEqual(headers, expectedHeaders)
assert.equal(statusText, 'OK')
})

diagnosticsChannel.channel('undici:request:bodySent').subscribe(({ request }) => {
Expand Down
15 changes: 6 additions & 9 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) => {
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 Expand Up @@ -84,25 +81,25 @@ test('Diagnostics channel - post', (t) => {
assert.deepStrictEqual(headers, expectedHeaders.join('\r\n') + '\r\n')

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

View workflow job for this annotation

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

Diagnostics channel - post

Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected + 'POST / HTTP/1.1\r\nhost: localhost:38805\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'POST / HTTP/1.1\r\n' + - 'host: localhost:38805\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at process.emit (node:events:519:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + 'POST / HTTP/1.1\r\nhost: localhost:38805\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'POST / HTTP/1.1\r\n' + - 'host: localhost:38805\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at res.<computed> [as deepStrictEqual] (/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:81: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: 'POST / HTTP/1.1\r\nhost: localhost:38805\r\nconnection: keep-alive\r\nbar: bar\r\n', expected: 'POST / HTTP/1.1\r\nhost: localhost:38805\r\nconnection: keep-alive\r\nbar: bar\r\nhello: world\r\n', operator: 'deepStrictEqual' } }

Check failure on line 81 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]: Expected values to be strictly deep-equal: + actual - expected + 'POST / HTTP/1.1\r\nhost: localhost:43605\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'POST / HTTP/1.1\r\n' + - 'host: localhost:43605\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at process.emit (node:events:518:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + 'POST / HTTP/1.1\r\nhost: localhost:43605\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'POST / HTTP/1.1\r\n' + - 'host: localhost:43605\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at res.<computed> [as deepStrictEqual] (/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:81: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: 'POST / HTTP/1.1\r\nhost: localhost:43605\r\nconnection: keep-alive\r\nbar: bar\r\n', expected: 'POST / HTTP/1.1\r\nhost: localhost:43605\r\nconnection: keep-alive\r\nbar: bar\r\nhello: world\r\n', operator: 'deepStrictEqual' } }

Check failure on line 81 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]: Expected values to be strictly deep-equal: + actual - expected + 'POST / HTTP/1.1\r\nhost: localhost:34159\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'POST / HTTP/1.1\r\n' + - 'host: localhost:34159\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at process.emit (node:events:517:28) at node:diagnostics_channel:144:11 { failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + 'POST / HTTP/1.1\r\nhost: localhost:34159\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'POST / HTTP/1.1\r\n' + - 'host: localhost:34159\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at res.<computed> [as deepStrictEqual] (/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:81: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: 'POST / HTTP/1.1\r\nhost: localhost:34159\r\nconnection: keep-alive\r\nbar: bar\r\n', expected: 'POST / HTTP/1.1\r\nhost: localhost:34159\r\nconnection: keep-alive\r\nbar: bar\r\nhello: world\r\n', operator: 'deepStrictEqual' }, code: 'ERR_TEST_FAILURE' }

Check failure on line 81 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]: Expected values to be strictly deep-equal: + actual - expected + 'POST / HTTP/1.1\r\nhost: localhost:52105\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'POST / HTTP/1.1\r\n' + - 'host: localhost:52105\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at process.emit (node:events:518:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + 'POST / HTTP/1.1\r\nhost: localhost:52105\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'POST / HTTP/1.1\r\n' + - 'host: localhost:52105\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at res.<computed> [as deepStrictEqual] (/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:81: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: 'POST / HTTP/1.1\r\nhost: localhost:52105\r\nconnection: keep-alive\r\nbar: bar\r\n', expected: 'POST / HTTP/1.1\r\nhost: localhost:52105\r\nconnection: keep-alive\r\nbar: bar\r\nhello: world\r\n', operator: 'deepStrictEqual' } }

Check failure on line 81 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]: Expected values to be strictly deep-equal: + actual - expected + 'POST / HTTP/1.1\r\nhost: localhost:51982\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'POST / HTTP/1.1\r\n' + - 'host: localhost:51982\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at process.emit (node:events:517:28) at node:diagnostics_channel:144:11 { failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + 'POST / HTTP/1.1\r\nhost: localhost:51982\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'POST / HTTP/1.1\r\n' + - 'host: localhost:51982\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at res.<computed> [as deepStrictEqual] (/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:81: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: 'POST / HTTP/1.1\r\nhost: localhost:51982\r\nconnection: keep-alive\r\nbar: bar\r\n', expected: 'POST / HTTP/1.1\r\nhost: localhost:51982\r\nconnection: keep-alive\r\nbar: bar\r\nhello: world\r\n', operator: 'deepStrictEqual' }, code: 'ERR_TEST_FAILURE' }

Check failure on line 81 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]: Expected values to be strictly deep-equal: + actual - expected + 'POST / HTTP/1.1\r\nhost: localhost:53583\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'POST / HTTP/1.1\r\n' + - 'host: localhost:53583\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at process.emit (node:events:519:28) at node:diagnostics_channel:145:11 { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + 'POST / HTTP/1.1\r\nhost: localhost:53583\r\nconnection: keep-alive\r\nbar: bar\r\n' - 'POST / HTTP/1.1\r\n' + - 'host: localhost:53583\r\n' + - 'connection: keep-alive\r\n' + - 'bar: bar\r\n' + - 'hello: world\r\n' at res.<computed> [as deepStrictEqual] (/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:81: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: 'POST / HTTP/1.1\r\nhost: localhost:53583\r\nconnection: keep-alive\r\nbar: bar\r\n', expected: 'POST / HTTP/1.1\r\nhost: localhost:53583\r\nconnection: keep-alive\r\nbar: bar\r\nhello: world\r\n', operator: 'deepStrictEqual' } }
})

diagnosticsChannel.channel('undici:request:headers').subscribe(({ request, response }) => {
diagnosticsChannel.channel('undici:request:headers').subscribe(({ request, headers, statusCode, statusText }) => {
assert.equal(_req, request)
assert.equal(response.statusCode, 200)
assert.equal(statusCode, 200)
const expectedHeaders = [
Buffer.from('Content-Type'),
Buffer.from('text/plain'),
Buffer.from('trailer'),
Buffer.from('foo'),
Buffer.from('Date'),
response.headers[5], // This is a date
headers[5], // This is a date
Buffer.from('Connection'),
Buffer.from('keep-alive'),
Buffer.from('Keep-Alive'),
Buffer.from('timeout=5'),
Buffer.from('Transfer-Encoding'),
Buffer.from('chunked')
]
assert.deepStrictEqual(response.headers, expectedHeaders)
assert.equal(response.statusText, 'OK')
assert.deepStrictEqual(headers, expectedHeaders)
assert.equal(statusText, 'OK')
})

diagnosticsChannel.channel('undici:request:bodySent').subscribe(({ request }) => {
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
14 changes: 5 additions & 9 deletions types/diagnostics-channel.d.ts
Expand Up @@ -6,16 +6,10 @@ import Dispatcher from "./dispatcher";
declare namespace DiagnosticsChannel {
interface Request {
origin?: string | URL;
completed: boolean;
method?: Dispatcher.HttpMethod;
path: string;
headers: string;
addHeader(key: string, value: string): Request;
}
interface Response {
statusCode: number;
statusText: string;
headers: Array<Buffer>;
headers: any;
completed: boolean;
}
type Error = unknown;
interface ConnectParams {
Expand All @@ -34,7 +28,9 @@ declare namespace DiagnosticsChannel {
}
export interface RequestHeadersMessage {
request: Request;
response: Response;
headers: Array<Buffer>;
statusCode: number;
statusText: string;
}
export interface RequestTrailersMessage {
request: Request;
Expand Down

0 comments on commit 89dfbd7

Please sign in to comment.