From a6c6cbb4e6b83d2552e9bc573f75df92eb0870e5 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 PR-URL: https://github.com/nodejs/node/pull/35978 Fixes: https://github.com/nodejs/node/issues/31084 Refs: https://github.com/nodejs/node/pull/26962 Reviewed-By: Matteo Collina Reviewed-By: Ricky Zhou <0x19951125@gmail.com> --- doc/api/errors.md | 5 + doc/api/http2.md | 23 ++++ lib/internal/errors.js | 1 + lib/internal/http2/core.js | 18 +++ 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, 231 insertions(+) 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 3c65555602621a..784c9ac5a226d0 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1137,6 +1137,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 8df14ab04a6ba3..1272531e7147c4 100644 --- a/doc/api/http2.md +++ b/doc/api/http2.md @@ -518,6 +518,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)`