Skip to content

Commit

Permalink
Merge pull request #61 from elastic/trentm/node-v19-keep-alive
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshMock authored Mar 30, 2023
2 parents 64d6fa2 + ac4d007 commit dcf57ba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [14.x, 16.x, 18.x, 19.x]
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
Expand Down
1 change: 1 addition & 0 deletions src/connection/UndiciConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export default class Connection extends BaseConnection {
}
}

// @ts-expect-error Assume header is not string[] for now.
const contentEncoding = (response.headers['content-encoding'] ?? '').toLowerCase()
const isCompressed = contentEncoding.includes('gzip') || contentEncoding.includes('deflate') // eslint-disable-line
const isVectorTile = (response.headers['content-type'] ?? '').includes('application/vnd.mapbox-vector-tile')
Expand Down
10 changes: 9 additions & 1 deletion test/unit/http-connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const options = {
context: null
}

const nodeKeepAliveByDefault = Number(process.versions.node.split('.')[0]) >= 19

test('Basic (http)', async t => {
t.plan(3)

Expand Down Expand Up @@ -176,9 +178,12 @@ test('Disable keep alive', async t => {
}

const [{ port }, server] = await buildServer(handler)
const agent = nodeKeepAliveByDefault
? new http.Agent({ keepAlive: false })
: false
const connection = new HttpConnection({
url: new URL(`http://localhost:${port}`),
agent: false
agent
})
const res = await connection.request({
path: '/hello',
Expand All @@ -188,6 +193,9 @@ test('Disable keep alive', async t => {
}
}, options)
t.match(res.headers, { connection: /close/ })
if (agent) {
agent.destroy()
}
server.stop()
})

Expand Down

0 comments on commit dcf57ba

Please # to comment.