Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: #30135
Fixes: #30107
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
cjihrig committed Oct 30, 2019
commit 11276af5dd60354af3db1b578804ca3839044420
4 changes: 4 additions & 0 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,10 @@ the request body should be sent.
## Class: http.IncomingMessage
<!-- YAML
added: v0.1.17
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/30135
description: The `readableHighWaterMark` value mirrors that of the socket.
-->

* Extends: {stream.Readable}
Expand Down
10 changes: 9 additions & 1 deletion lib/_http_incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
24 changes: 24 additions & 0 deletions test/parallel/test-http-incoming-message-options.js
Original file line number Diff line number Diff line change
@@ -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();
}));