Skip to content
Merged
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
48 changes: 34 additions & 14 deletions test/fetch/client-node-max-header-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,44 @@

const { tspl } = require('@matteo.collina/tspl')
const { exec } = require('node:child_process')
const { test } = require('node:test')
const { once } = require('node:events')
const { createServer } = require('node:http')
const { test, describe, before, after } = require('node:test')

const command = 'node -e "require(\'./undici-fetch.js\').fetch(\'https://httpbin.org/get\')"'
describe('fetch respects --max-http-header-size', () => {
let server

test("respect Node.js' --max-http-header-size", async (t) => {
t = tspl(t, { plan: 6 })
before(async () => {
server = createServer((req, res) => {
res.writeHead(200, 'OK', {
'Content-Length': 2
})
res.write('OK')
res.end()
}).listen(0)

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')
await once(server, 'listening')
})

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

test("respect Node.js' --max-http-header-size", async (t) => {
t = tspl(t, { plan: 6 })

const command = 'node -e "require(\'./undici-fetch.js\').fetch(\'http://localhost:' + server.address().port + '\')"'

await t.completed
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
})
})
Loading