mirror of
https://github.com/nodejs/node.git
synced 2025-05-05 05:53:11 +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.
56 lines
1.4 KiB
JavaScript
56 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
// Verifies that uploading data from a client works
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
const assert = require('assert');
|
|
const http2 = require('http2');
|
|
const fs = require('fs');
|
|
const fixtures = require('../common/fixtures');
|
|
const Countdown = require('../common/countdown');
|
|
|
|
const loc = fixtures.path('person.jpg');
|
|
let fileData;
|
|
|
|
assert(fs.existsSync(loc));
|
|
|
|
fs.readFile(loc, common.mustCall((err, data) => {
|
|
assert.ifError(err);
|
|
fileData = data;
|
|
|
|
const server = http2.createServer();
|
|
|
|
server.on('stream', common.mustCall((stream) => {
|
|
let data = Buffer.alloc(0);
|
|
stream.on('data', (chunk) => data = Buffer.concat([data, chunk]));
|
|
stream.on('end', common.mustCall(() => {
|
|
assert.deepStrictEqual(data, fileData);
|
|
}));
|
|
stream.respond();
|
|
stream.end();
|
|
}));
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const client = http2.connect(`http://localhost:${server.address().port}`);
|
|
|
|
const countdown = new Countdown(2, () => {
|
|
server.close();
|
|
client.close();
|
|
});
|
|
|
|
const req = client.request({ ':method': 'POST' });
|
|
req.on('response', common.mustCall());
|
|
|
|
req.resume();
|
|
req.on('end', common.mustCall());
|
|
|
|
req.on('finish', () => countdown.dec());
|
|
const str = fs.createReadStream(loc);
|
|
str.on('end', common.mustCall());
|
|
str.on('close', () => countdown.dec());
|
|
str.pipe(req);
|
|
}));
|
|
}));
|