mirror of
https://github.com/nodejs/node.git
synced 2025-05-21 10:42:18 +00:00

PR-URL: https://github.com/nodejs/node/pull/17406 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> This is a significant cleanup and refactoring of the cleanup/close/destroy logic for Http2Stream and Http2Session. There are significant changes here in the timing and ordering of cleanup logic, JS apis. and various related necessary edits.
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
const assert = require('assert');
|
|
const h2 = require('http2');
|
|
|
|
// Http2ServerRequest should always end readable stream
|
|
// even on GET requests with no body
|
|
|
|
const server = h2.createServer();
|
|
server.listen(0, common.mustCall(function() {
|
|
const port = server.address().port;
|
|
server.once('request', common.mustCall(function(request, response) {
|
|
assert.strictEqual(request.complete, false);
|
|
request.on('data', () => {});
|
|
request.on('end', common.mustCall(() => {
|
|
assert.strictEqual(request.complete, true);
|
|
response.on('finish', common.mustCall(function() {
|
|
// the following tests edge cases on request socket
|
|
// right after finished fires but before backing
|
|
// Http2Stream is destroyed
|
|
assert.strictEqual(request.socket.readable, request.stream.readable);
|
|
assert.strictEqual(request.socket.readable, false);
|
|
|
|
server.close();
|
|
}));
|
|
response.end();
|
|
}));
|
|
}));
|
|
|
|
const url = `http://localhost:${port}`;
|
|
const client = h2.connect(url, common.mustCall(() => {
|
|
const request = client.request();
|
|
request.resume();
|
|
request.on('end', common.mustCall(() => {
|
|
client.close();
|
|
}));
|
|
}));
|
|
}));
|