Skip to content

Commit

Permalink
remove istanbule ignore and add test for bad upgrade (nodejs#1279)
Browse files Browse the repository at this point in the history
  • Loading branch information
is2ei authored and metcoder95 committed Dec 26, 2022
1 parent 73772f8 commit 8730223
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/client.js
Expand Up @@ -794,7 +794,7 @@ class Parser {
return -1
}

/* istanbul ignore if: this can only happen if server is misbehaving */
/* this can only happen if server is misbehaving */
if (upgrade && !request.upgrade) {
util.destroy(socket, new SocketError('bad upgrade', util.getSocketInfo(socket)))
return -1
Expand Down
24 changes: 24 additions & 0 deletions test/http-100.js
Expand Up @@ -84,6 +84,30 @@ test('error 100 body', (t) => {
})
})

test('error 101 upgrade', (t) => {
t.plan(2)

const server = net.createServer((socket) => {
socket.write('HTTP/1.1 101 Switching Protocols\r\nUpgrade: example/1\r\nConnection: Upgrade\r\n')
socket.write('\r\n')
})
t.teardown(server.close.bind(server))
server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
t.teardown(client.destroy.bind(client))

client.request({
path: '/',
method: 'GET'
}, (err) => {
t.equal(err.message, 'bad upgrade')
})
client.on('disconnect', () => {
t.pass()
})
})
})

test('1xx response without timeouts', { only: true }, t => {
t.plan(2)

Expand Down

0 comments on commit 8730223

Please sign in to comment.