mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
Refactor the read mechanism to completely avoid copying. Instead of copying individual `DATA` frame contents into buffers, create `ArrayBuffer` instances for all socket reads and emit slices of those `ArrayBuffer`s to JS. Backport-PR-URL: https://github.com/nodejs/node/pull/20456 PR-URL: https://github.com/nodejs/node/pull/18030 Reviewed-By: James M Snell <jasnell@gmail.com>
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
// Verifies that a full HTTP2 pipeline handles backpressure.
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
const assert = require('assert');
|
|
const http2 = require('http2');
|
|
const makeDuplexPair = require('../common/duplexpair');
|
|
|
|
common.crashOnUnhandledRejection();
|
|
|
|
{
|
|
let req;
|
|
const server = http2.createServer();
|
|
server.on('stream', common.mustCallAsync(async (stream, headers) => {
|
|
stream.respond({
|
|
'content-type': 'text/html',
|
|
':status': 200
|
|
});
|
|
req._readableState.highWaterMark = 20;
|
|
stream._writableState.highWaterMark = 20;
|
|
assert.strictEqual(stream.write('A'.repeat(5)), true);
|
|
assert.strictEqual(stream.write('A'.repeat(40)), false);
|
|
assert.strictEqual(await event(req, 'data'), 'A'.repeat(5));
|
|
assert.strictEqual(await event(req, 'data'), 'A'.repeat(40));
|
|
await event(stream, 'drain');
|
|
assert.strictEqual(stream.write('A'.repeat(5)), true);
|
|
assert.strictEqual(stream.write('A'.repeat(40)), false);
|
|
}));
|
|
|
|
const { clientSide, serverSide } = makeDuplexPair();
|
|
server.emit('connection', serverSide);
|
|
|
|
const client = http2.connect('http://localhost:80', {
|
|
createConnection: common.mustCall(() => clientSide)
|
|
});
|
|
|
|
req = client.request({ ':path': '/' });
|
|
req.setEncoding('utf8');
|
|
req.end();
|
|
}
|
|
|
|
function event(ee, eventName) {
|
|
return new Promise((resolve) => {
|
|
ee.once(eventName, common.mustCall(resolve));
|
|
});
|
|
}
|