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
22 changes: 7 additions & 15 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,19 +542,6 @@ class Parser {
}
}

finish () {
try {
try {
currentParser = this
} finally {
currentParser = null
}
} catch (err) {
/* istanbul ignore next: difficult to make a test case for */
util.destroy(this.socket, err)
}
}

destroy () {
assert(this.ptr != null)
assert(currentParser == null)
Expand Down Expand Up @@ -917,7 +904,7 @@ function onSocketError (err) {
// to the user.
if (err.code === 'ECONNRESET' && parser.statusCode && !parser.shouldKeepAlive) {
// We treat all incoming data so for as a valid response.
parser.finish()
parser.onMessageComplete()
return
}

Expand Down Expand Up @@ -951,7 +938,7 @@ function onSocketEnd () {

if (parser.statusCode && !parser.shouldKeepAlive) {
// We treat all incoming data so far as a valid response.
parser.finish()
parser.onMessageComplete()
return
}

Expand All @@ -961,6 +948,11 @@ function onSocketEnd () {
function onSocketClose () {
const { [kClient]: client } = this

if (!this[kError] && this[kParser].statusCode && !this[kParser].shouldKeepAlive) {
// We treat all incoming data so far as a valid response.
this[kParser].onMessageComplete()
}

this[kParser].destroy()
this[kParser] = null

Expand Down
4 changes: 2 additions & 2 deletions test/content-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ test('response invalid content length with close', (t) => {
t.teardown(client.destroy.bind(client))

client.on('disconnect', (origin, client, err) => {
t.equal(err.code, 'UND_ERR_SOCKET')
t.equal(err.code, 'UND_ERR_RES_CONTENT_LENGTH_MISMATCH')
})

client.request({
Expand All @@ -294,7 +294,7 @@ test('response invalid content length with close', (t) => {
t.fail()
})
.on('error', (err) => {
t.equal(err.code, 'UND_ERR_SOCKET')
t.equal(err.code, 'UND_ERR_RES_CONTENT_LENGTH_MISMATCH')
})
.resume()
})
Expand Down
12 changes: 12 additions & 0 deletions test/issue-1670.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict'

const { test } = require('tap')
const { request } = require('..')

test('https://github.com/mcollina/undici/issues/810', async (t) => {
const { body } = await request('https://api.github.com/user/emails')

await body.text()

t.end()
})