Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: support readable hwm in IncomingMessage #30135

Merged
merged 1 commit into from
Oct 30, 2019
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
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();
}));