Skip to content

Commit

Permalink
fix: keep-alive postfix optional (#477)
Browse files Browse the repository at this point in the history
Fixes: #476
  • Loading branch information
ronag authored Nov 12, 2020
1 parent fb7fe1d commit 6978a61
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function destroy (stream, err) {
}
}

const KEEPALIVE_TIMEOUT_EXPR = /timeout=(\d+)s/
const KEEPALIVE_TIMEOUT_EXPR = /timeout=(\d+)/
function parseKeepAliveTimeout (val) {
const m = val.match(KEEPALIVE_TIMEOUT_EXPR)
return m ? parseInt(m[1]) * 1000 : null
Expand Down
34 changes: 34 additions & 0 deletions test/client-keep-alive.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,40 @@ test('keep-alive header 1', (t) => {
})
})

test('keep-alive header no postfix', (t) => {
t.plan(2)

const server = createServer((socket) => {
socket.write('HTTP/1.1 200 OK\r\n')
socket.write('Content-Length: 0\r\n')
socket.write('Keep-Alive: timeout=2\r\n')
socket.write('Connection: keep-alive\r\n')
socket.write('\r\n\r\n')
})
t.teardown(server.close.bind(server))

server.listen(0, () => {
const client = new Client(`https://localhost:${server.address().port}`)
t.teardown(client.destroy.bind(client))

client.request({
path: '/',
method: 'GET'
}, (err, { body }) => {
t.error(err)
body.on('end', () => {
const timeout = setTimeout(() => {
t.fail()
}, 2e3)
client.on('disconnect', () => {
t.pass()
clearTimeout(timeout)
})
}).resume()
})
})
})

test('keep-alive not timeout', (t) => {
t.plan(2)

Expand Down

0 comments on commit 6978a61

Please sign in to comment.