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 @@ -644,11 +644,6 @@ class Parser {
assert(!this.upgrade)
assert(this.statusCode < 200)

if (statusCode === 100) {
util.destroy(socket, new SocketError('bad response', util.getSocketInfo(socket)))
return -1
}

/* this can only happen if server is misbehaving */
if (upgrade && !request.upgrade) {
util.destroy(socket, new SocketError('bad upgrade', util.getSocketInfo(socket)))
Expand Down
53 changes: 40 additions & 13 deletions test/http-100.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,39 @@ test('error 103 body', async (t) => {
await t.completed
})

test('error 100 body', async (t) => {
t = tspl(t, { plan: 2 })
test('ignore unsolicited 100 Continue response', async (t) => {
t = tspl(t, { plan: 5 })

let connections = 0
const server = net.createServer({ joinDuplicateHeaders: true }, (socket) => {
socket.write('HTTP/1.1 100 Early Hints\r\n')
socket.write('\r\n')
connections++
let requests = 0
let received = ''
socket.on('data', (chunk) => {
received += chunk
if (!received.includes('\r\n\r\n')) {
return
}

received = ''
requests++
if (requests === 1) {
socket.write(
'HTTP/1.1 100 Continue\r\n\r\n' +
'HTTP/1.1 200 OK\r\n' +
'content-length: 5\r\n' +
'connection: keep-alive\r\n\r\n' +
'hello'
)
} else {
socket.end(
'HTTP/1.1 200 OK\r\n' +
'content-length: 5\r\n' +
'connection: close\r\n\r\n' +
'world'
)
}
})
})
after(() => server.close())
server.listen(0)
Expand All @@ -88,15 +115,15 @@ test('error 100 body', async (t) => {
const client = new Client(`http://localhost:${server.address().port}`)
after(() => client.close())

client.request({
path: '/',
method: 'GET'
}, (err) => {
t.strictEqual(err.message, 'bad response')
})
client.on('disconnect', () => {
t.ok(true, 'pass')
})
const first = await client.request({ path: '/', method: 'GET' })
t.strictEqual(first.statusCode, 200)
t.strictEqual(await first.body.text(), 'hello')

const second = await client.request({ path: '/', method: 'GET' })
t.strictEqual(second.statusCode, 200)
t.strictEqual(await second.body.text(), 'world')
t.strictEqual(connections, 1)

await t.completed
})

Expand Down
Loading