forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http2: close idle connections when allowHTTP1 is true
Fixes: nodejs#51493
- Loading branch information
Showing
2 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fixtures = require('../common/fixtures'); | ||
if (!common.hasCrypto) common.skip('missing crypto'); | ||
|
||
const assert = require('assert'); | ||
const https = require('https'); | ||
const http2 = require('http2'); | ||
|
||
(async function main() { | ||
const server = http2.createSecureServer({ | ||
key: fixtures.readKey('agent1-key.pem'), | ||
cert: fixtures.readKey('agent1-cert.pem'), | ||
allowHTTP1: true, | ||
}); | ||
|
||
server.on( | ||
'request', | ||
common.mustCall((req, res) => { | ||
res.writeHead(200); | ||
res.end(); | ||
}) | ||
); | ||
|
||
server.on( | ||
'close', | ||
common.mustCall() | ||
); | ||
|
||
await new Promise((resolve) => server.listen(0, resolve)); | ||
|
||
await new Promise((resolve) => | ||
https.get( | ||
`https://localhost:${server.address().port}`, | ||
{ | ||
rejectUnauthorized: false, | ||
headers: { connection: 'keep-alive' }, | ||
}, | ||
resolve | ||
) | ||
); | ||
|
||
let serverClosed = false; | ||
setImmediate( | ||
common.mustCall(() => { | ||
assert.ok(serverClosed, 'server should been closed immediately'); | ||
}) | ||
); | ||
server.close( | ||
common.mustSucceed(() => { | ||
serverClosed = true; | ||
}) | ||
); | ||
})().then(common.mustCall()); |