Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions test/fetch/client-node-max-header-size.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
'use strict'

const { execSync } = require('node:child_process')
const { tspl } = require('@matteo.collina/tspl')
const { exec } = require('node:child_process')
const { test } = require('node:test')
const assert = require('node:assert')

const command = 'node -e "require(\'./undici-fetch.js\').fetch(\'https://httpbin.org/get\')"'

test("respect Node.js' --max-http-header-size", async () => {
assert.throws(
() => execSync(`${command} --max-http-header-size=1`),
/UND_ERR_HEADERS_OVERFLOW/,
'max-http-header-size=1 should throw'
)
test("respect Node.js' --max-http-header-size", async (t) => {
t = tspl(t, { plan: 6 })

assert.doesNotThrow(
() => execSync(command),
/UND_ERR_HEADERS_OVERFLOW/,
'default max-http-header-size should not throw'
)
exec(`${command} --max-http-header-size=1`, { stdio: 'pipe' }, (err, stdout, stderr) => {
t.strictEqual(err.code, 1)
t.strictEqual(stdout, '')
t.match(stderr, /UND_ERR_HEADERS_OVERFLOW/, '--max-http-header-size=1 should throw')
})

exec(command, { stdio: 'pipe' }, (err, stdout, stderr) => {
t.ifError(err)
t.strictEqual(stdout, '')
t.strictEqual(stderr, '', 'default max-http-header-size should not throw')
})

await t.completed
})
5 changes: 4 additions & 1 deletion test/utils/node-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
const util = require('node:util')

function closeServerAsPromise (server) {
return () => util.promisify(server.close.bind(server))()
return () => {
server.closeIdleConnections()
return util.promisify(server.close.bind(server))()
}
}

function closeClientAndServerAsPromise (client, server) {
Expand Down