From 2dbd8aad7f22fe014173d63715a3a232fde6d32f Mon Sep 17 00:00:00 2001 From: zhangyongsheng Date: Tue, 10 Nov 2020 22:22:35 +0800 Subject: [PATCH] http2: allow setting the local window size of a session --- doc/api/errors.md | 5 + doc/api/http2.md | 23 ++++ lib/internal/errors.js | 1 + lib/internal/http2/core.js | 29 ++++- src/node_http2.cc | 21 +++ src/node_http2.h | 3 + test/parallel/test-http2-client-destroy.js | 2 + .../test-http2-client-setLocalWindowSize.js | 121 ++++++++++++++++++ .../test-http2-server-setLocalWindowSize.js | 37 ++++++ 9 files changed, 237 insertions(+), 5 deletions(-) create mode 100644 test/parallel/test-http2-client-setLocalWindowSize.js create mode 100644 test/parallel/test-http2-server-setLocalWindowSize.js diff --git a/doc/api/errors.md b/doc/api/errors.md index 192c4ecf5772f2..9433e00897877b 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1226,6 +1226,11 @@ reached. An attempt was made to initiate a new push stream from within a push stream. Nested push streams are not permitted. + +### `ERR_HTTP2_NO_MEM` + +Out of memory when using the `http2session.setLocalWindowSize(windowSize)` API. + ### `ERR_HTTP2_NO_SOCKET_MANIPULATION` diff --git a/doc/api/http2.md b/doc/api/http2.md index b4977397f350c1..d09d093f3a71d6 100644 --- a/doc/api/http2.md +++ b/doc/api/http2.md @@ -519,6 +519,29 @@ added: v8.4.0 A prototype-less object describing the current remote settings of this `Http2Session`. The remote settings are set by the *connected* HTTP/2 peer. +#### `http2session.setLocalWindowSize(windowSize)` + + +* `windowSize` {number} + +Sets the local endpoint's window size. +The `windowSize` is the total window size to set, not +the delta. + +```js +const http2 = require('http2'); + +const server = http2.createServer(); +const expectedWindowSize = 2 ** 20; +server.on('connect', (session) => { + + // Set local window size to be 2 ** 20 + session.setLocalWindowSize(expectedWindowSize); +}); +``` + #### `http2session.setTimeout(msecs, callback)`