Skip to content

Commit

Permalink
http: support readable hwm in IncomingMessage
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Yongsheng Zhang <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
  • Loading branch information
cjihrig authored and BethGriggs committed Feb 6, 2020
1 parent 785aa86 commit 86369e4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,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();
}));

0 comments on commit 86369e4

Please sign in to comment.