Skip to content

Commit c2757d1

Browse files
cjihrigMylesBorins
authored andcommitted
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 <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent ba5683c commit c2757d1

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

doc/api/http.md

+4
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,10 @@ the request body should be sent.
16591659
## Class: `http.IncomingMessage`
16601660
<!-- YAML
16611661
added: v0.1.17
1662+
changes:
1663+
- version: REPLACEME
1664+
pr-url: https://github.com/nodejs/node/pull/30135
1665+
description: The `readableHighWaterMark` value mirrors that of the socket.
16621666
-->
16631667

16641668
* Extends: {stream.Readable}

lib/_http_incoming.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ function readStop(socket) {
3737

3838
/* Abstract base class for ServerRequest and ClientResponse. */
3939
function IncomingMessage(socket) {
40-
Stream.Readable.call(this);
40+
let streamOptions;
41+
42+
if (socket) {
43+
streamOptions = {
44+
highWaterMark: socket.readableHighWaterMark
45+
};
46+
}
47+
48+
Stream.Readable.call(this, streamOptions);
4149

4250
this._readableState.readingMore = true;
4351

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const http = require('http');
5+
const net = require('net');
6+
const readableHighWaterMark = 1024;
7+
const server = http.createServer((req, res) => { res.end(); });
8+
9+
server.listen(0, common.mustCall(() => {
10+
const req = http.request({
11+
port: server.address().port,
12+
createConnection(options) {
13+
options.readableHighWaterMark = readableHighWaterMark;
14+
return net.createConnection(options);
15+
}
16+
}, common.mustCall((res) => {
17+
assert.strictEqual(res.socket, req.socket);
18+
assert.strictEqual(res.socket.readableHighWaterMark, readableHighWaterMark);
19+
assert.strictEqual(res.readableHighWaterMark, readableHighWaterMark);
20+
server.close();
21+
}));
22+
23+
req.end();
24+
}));

0 commit comments

Comments
 (0)