Skip to content
Closed
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
5 changes: 0 additions & 5 deletions lib/dispatcher/client-h1.js
Original file line number Diff line number Diff line change
Expand Up @@ -1088,11 +1088,6 @@ function writeH1 (client, request) {
headers.push('content-type', body.type)
}

if (body && typeof body.read === 'function') {
// Try to read EOF in order to get length.
body.read(0)
}

Comment on lines -1091 to -1095
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is problematic in some cases...

const bodyLength = util.bodyLength(body)

contentLength = bodyLength ?? contentLength
Expand Down
106 changes: 43 additions & 63 deletions test/node-test/client-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,71 +122,33 @@ test('GET errors and reconnect with pipelining 3', async (t) => {
await p.completed
})

function installErrorAndReconnectServer (server, p, { contentLength, trackPostWithPlan }) {
let sawPost = false
let sawGet = false

server.on('request', (req, res) => {
if (req.method === 'GET') {
if (sawGet) {
req.socket?.destroy()
return
}

sawGet = true
p.strictEqual('/', req.url)
p.strictEqual('GET', req.method)
res.setHeader('content-type', 'text/plain')
res.end('hello')
return
}

if (sawPost) {
// Node.js 26 can surface additional POST attempts around the queued GET.
// Tear them down and keep the test focused on the reconnect behavior.
req.resume()
req.socket?.destroy()
return
}

sawPost = true
function errorAndPipelining (type) {
test(`POST with a ${type} that errors and pipelining 1 should reconnect`, async (t) => {
const p = tspl(t, { plan: 12 })

if (trackPostWithPlan) {
const server = createServer({ joinDuplicateHeaders: true })
server.once('request', (req, res) => {
p.strictEqual('/', req.url)
p.strictEqual('POST', req.method)
p.strictEqual(req.headers['content-length'], contentLength)
} else {
assert.strictEqual('/', req.url)
assert.strictEqual('POST', req.method)
assert.strictEqual(req.headers['content-length'], contentLength)
}
p.strictEqual('42', req.headers['content-length'])

const bufs = []
req.on('data', (buf) => {
bufs.push(buf)
})
const bufs = []
req.on('data', (buf) => {
bufs.push(buf)
})

req.on('aborted', () => {
// we will abruptly close the connection here
// but this will still end
if (trackPostWithPlan) {
req.on('aborted', () => {
// we will abruptly close the connection here
// but this will still end
p.strictEqual('a string', Buffer.concat(bufs).toString('utf8'))
} else {
assert.strictEqual('a string', Buffer.concat(bufs).toString('utf8'))
}
})
})
}

function errorAndPipelining (type) {
test(`POST with a ${type} that errors and pipelining 1 should reconnect`, async (t) => {
const trackPostWithPlan = type !== consts.STREAM
const p = tspl(t, { plan: trackPostWithPlan ? 12 : 8 })
})

const server = createServer({ joinDuplicateHeaders: true })
installErrorAndReconnectServer(server, p, {
contentLength: '42',
trackPostWithPlan
server.once('request', (req, res) => {
p.strictEqual('/', req.url)
p.strictEqual('GET', req.method)
res.setHeader('content-type', 'text/plain')
res.end('hello')
})
})
t.after(closeServerAsPromise(server))

Expand Down Expand Up @@ -237,13 +199,31 @@ errorAndPipelining(consts.ASYNC_ITERATOR)

function errorAndChunkedEncodingPipelining (type) {
test(`POST with chunked encoding, ${type} body that errors and pipelining 1 should reconnect`, async (t) => {
const trackPostWithPlan = type !== consts.STREAM
const p = tspl(t, { plan: trackPostWithPlan ? 12 : 8 })
const p = tspl(t, { plan: 12 })

const server = createServer({ joinDuplicateHeaders: true })
installErrorAndReconnectServer(server, p, {
contentLength: undefined,
trackPostWithPlan
server.once('request', (req, res) => {
p.strictEqual('/', req.url)
p.strictEqual('POST', req.method)
p.strictEqual(req.headers['content-length'], undefined)

const bufs = []
req.on('data', (buf) => {
bufs.push(buf)
})

req.on('aborted', () => {
// we will abruptly close the connection here
// but this will still end
p.strictEqual('a string', Buffer.concat(bufs).toString('utf8'))
})

server.once('request', (req, res) => {
p.strictEqual('/', req.url)
p.strictEqual('GET', req.method)
res.setHeader('content-type', 'text/plain')
res.end('hello')
})
})
t.after(closeServerAsPromise(server))

Expand Down
Loading