0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-http-nodelay.js
Paolo Insogna eacd45656a
http: make TCP noDelay enabled by default
PR-URL: https://github.com/nodejs/node/pull/42163
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
2022-03-09 14:37:49 +00:00

38 lines
808 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
const net = require('net');
const originalConnect = net.Socket.prototype.connect;
net.Socket.prototype.connect = common.mustCall(function(args) {
assert.strictEqual(args[0].noDelay, true);
return originalConnect.call(this, args);
});
const server = http.createServer(common.mustCall((req, res) => {
res.writeHead(200);
res.end();
server.close();
}));
server.listen(0, common.mustCall(() => {
assert.strictEqual(server.noDelay, true);
const req = http.request({
method: 'GET',
port: server.address().port
}, common.mustCall((res) => {
res.on('end', () => {
server.close();
res.req.socket.end();
});
res.resume();
}));
req.end();
}));