Files
node/test/parallel/test-http-server-response-standalone.js
Tim Perry 214cf0693b http: improve performance with known-length calls to end()
This boosts RPS performance for the common API case where you call
`res.end(data)` with the entire response by up to 9%.

Signed-off-by: Tim Perry <pimterry@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65466
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-08-24 09:54:15 +00:00

34 lines
765 B
JavaScript

'use strict';
const common = require('../common');
const { ServerResponse } = require('http');
const { Writable } = require('stream');
const assert = require('assert');
// Check that ServerResponse can be used without a proper Socket
// Refs: https://github.com/nodejs/node/issues/14386
// Refs: https://github.com/nodejs/node/issues/14381
const res = new ServerResponse({
method: 'GET',
httpVersionMajor: 1,
httpVersionMinor: 1
});
const ws = new Writable({
write: common.mustCall((chunk, encoding, callback) => {
assert(chunk.toString().endsWith('hello world'));
setImmediate(callback);
}, 1)
});
res.assignSocket(ws);
assert.throws(function() {
res.assignSocket(ws);
}, {
code: 'ERR_HTTP_SOCKET_ASSIGNED'
});
res.end('hello world');