http: coalesce chunked writes during auto-corking · nodejs/node@742b4bf · GitHub
Skip to content

Commit 742b4bf

Browse files
GetThatCookieaduh95
authored andcommitted
http: coalesce chunked writes during auto-corking
Signed-off-by: GetThatCookie <NimmenKeks@gmx.de> PR-URL: #64987 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Tim Perry <pimterry@gmail.com>
1 parent f6b4793 commit 742b4bf

6 files changed

Lines changed: 89 additions & 46 deletions

File tree

‎lib/_http_outgoing.js‎

Lines changed: 70 additions & 33 deletions

‎test/parallel/test-http-1.0.js‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,12 @@ function test(handler, request_generator, response_validator) {
127127
assert.strictEqual(req.httpVersionMinor, 1);
128128
res.sendDate = false;
129129
res.writeHead(200, { 'Content-Type': 'text/plain' });
130-
res.write('Hello, '); res._send('');
130+
assert.throws(() => res.write('ignored', 'invalid'), {
131+
code: 'ERR_UNKNOWN_ENCODING',
132+
});
133+
res.write('Hello, ', common.mustCall()); res._send('');
131134
res.write('world!'); res._send('');
132-
res.end();
135+
process.nextTick(() => res.end('X'));
133136
}
134137

135138
function request_generator() {
@@ -148,10 +151,10 @@ function test(handler, request_generator, response_validator) {
148151
'Connection: close\r\n' +
149152
'Transfer-Encoding: chunked\r\n' +
150153
'\r\n' +
151-
'7\r\n' +
152-
'Hello, \r\n' +
153-
'6\r\n' +
154-
'world!\r\n' +
154+
'd\r\n' +
155+
'Hello, world!\r\n' +
156+
'1\r\n' +
157+
'X\r\n' +
155158
'0\r\n' +
156159
'\r\n';
157160

‎test/parallel/test-http-byteswritten.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ const httpServer = http.createServer(common.mustCall(function(req, res) {
4444
res.write(bchunk);
4545
res.write(chunk, 'hex');
4646
}
47-
// Get .bytesWritten while buffer is not empty
48-
assert(res.connection.bytesWritten > 0);
49-
5047
res.end(body);
48+
49+
// Get .bytesWritten while the socket buffer is not empty.
50+
assert(res.connection.bytesWritten > 0);
5151
}));
5252

5353
httpServer.listen(0, function() {

‎test/parallel/test-http-outgoing-destroyed.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ const { OutgoingMessage } = require('http');
6666
});
6767
}));
6868
const err = new Error('Destroy test');
69+
res.write('x', common.mustCall((writeErr) => {
70+
assert.strictEqual(writeErr, err);
71+
}));
6972
res.destroy(err);
7073
assert.strictEqual(res.errored, err);
7174
})).listen(0, common.mustCall(() => {

‎test/parallel/test-stream-pipeline.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,12 @@ tmpdir.refresh();
243243
pipeline(rs, res, () => {});
244244
}));
245245

246-
let cnt = 10;
246+
let received = 0;
247247

248248
const badSink = new Writable({
249249
write(data, enc, cb) {
250-
cnt--;
251-
if (cnt === 0) cb(new Error('kaboom'));
250+
received += data.length;
251+
if (received >= 50) cb(new Error('kaboom'));
252252
else cb();
253253
}
254254
});

‎test/parallel/test-webstreams-pipeline.js‎

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)