From 86369e4ac58ffaf272f38b0f372d8092ba15613f Mon Sep 17 00:00:00 2001 From: cjihrig Date: Fri, 25 Oct 2019 21:17:06 -0400 Subject: [PATCH] http: support readable hwm in IncomingMessage This commit causes http.IncomingMessage instances to set their readableHighWaterMark value the same value used in the underlying socket. PR-URL: https://github.com/nodejs/node/pull/30135 Fixes: https://github.com/nodejs/node/issues/30107 Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Yongsheng Zhang Reviewed-By: Trivikram Kamat --- doc/api/http.md | 4 ++++ lib/_http_incoming.js | 10 +++++++- .../test-http-incoming-message-options.js | 24 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-http-incoming-message-options.js diff --git a/doc/api/http.md b/doc/api/http.md index 2f6b27e10c652e..33778d5445ae4b 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -1659,6 +1659,10 @@ the request body should be sent. ## Class: `http.IncomingMessage` * Extends: {stream.Readable} diff --git a/lib/_http_incoming.js b/lib/_http_incoming.js index 56ff31af8b17c1..8f4c05c5fe5919 100644 --- a/lib/_http_incoming.js +++ b/lib/_http_incoming.js @@ -37,7 +37,15 @@ function readStop(socket) { /* Abstract base class for ServerRequest and ClientResponse. */ function IncomingMessage(socket) { - Stream.Readable.call(this); + let streamOptions; + + if (socket) { + streamOptions = { + highWaterMark: socket.readableHighWaterMark + }; + } + + Stream.Readable.call(this, streamOptions); this._readableState.readingMore = true; diff --git a/test/parallel/test-http-incoming-message-options.js b/test/parallel/test-http-incoming-message-options.js new file mode 100644 index 00000000000000..61e178eb47aeda --- /dev/null +++ b/test/parallel/test-http-incoming-message-options.js @@ -0,0 +1,24 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const http = require('http'); +const net = require('net'); +const readableHighWaterMark = 1024; +const server = http.createServer((req, res) => { res.end(); }); + +server.listen(0, common.mustCall(() => { + const req = http.request({ + port: server.address().port, + createConnection(options) { + options.readableHighWaterMark = readableHighWaterMark; + return net.createConnection(options); + } + }, common.mustCall((res) => { + assert.strictEqual(res.socket, req.socket); + assert.strictEqual(res.socket.readableHighWaterMark, readableHighWaterMark); + assert.strictEqual(res.readableHighWaterMark, readableHighWaterMark); + server.close(); + })); + + req.end(); +}));