mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
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>
34 lines
765 B
JavaScript
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');
|