mirror of
https://github.com/nodejs/node.git
synced 2025-04-29 14:25:18 +00:00

Ensure that the callback of `OutgoingMessage.prototype.write()` is called when `outgoingMessage._hasBody` is `false` (HEAD method, 204 status code, etc.). Refs: https://github.com/nodejs/node/pull/27709 PR-URL: https://github.com/nodejs/node/pull/27777 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
40 lines
877 B
JavaScript
40 lines
877 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
// This test ensures that the callback of `OutgoingMessage.prototype.write()` is
|
|
// called also when writing empty chunks or when the message has no body.
|
|
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
const stream = require('stream');
|
|
|
|
for (const method of ['GET, HEAD']) {
|
|
const expected = ['a', 'b', '', Buffer.alloc(0), 'c'];
|
|
const results = [];
|
|
|
|
const writable = new stream.Writable({
|
|
write(chunk, encoding, callback) {
|
|
callback();
|
|
}
|
|
});
|
|
|
|
const res = new http.ServerResponse({
|
|
method: method,
|
|
httpVersionMajor: 1,
|
|
httpVersionMinor: 1
|
|
});
|
|
|
|
res.assignSocket(writable);
|
|
|
|
for (const chunk of expected) {
|
|
res.write(chunk, () => {
|
|
results.push(chunk);
|
|
});
|
|
}
|
|
|
|
res.end(common.mustCall(() => {
|
|
assert.deepStrictEqual(results, expected);
|
|
}));
|
|
}
|