2017-07-20 10:08:35 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const { OutgoingMessage } = require('http');
|
|
|
|
const { Writable } = require('stream');
|
|
|
|
const assert = require('assert');
|
|
|
|
|
2018-12-03 16:15:45 +00:00
|
|
|
// Check that OutgoingMessage can be used without a proper Socket
|
2020-07-30 17:46:22 +00:00
|
|
|
// Refs: https://github.com/nodejs/node/issues/14386
|
|
|
|
// Refs: https://github.com/nodejs/node/issues/14381
|
2017-07-20 10:08:35 +00:00
|
|
|
|
|
|
|
class Response extends OutgoingMessage {
|
|
|
|
_implicitHeader() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
const res = new Response();
|
2019-05-15 05:34:12 +00:00
|
|
|
|
|
|
|
let firstChunk = true;
|
|
|
|
|
2017-07-20 10:08:35 +00:00
|
|
|
const ws = new Writable({
|
|
|
|
write: common.mustCall((chunk, encoding, callback) => {
|
2019-05-15 05:34:12 +00:00
|
|
|
if (firstChunk) {
|
|
|
|
assert(chunk.toString().endsWith('hello world'));
|
|
|
|
firstChunk = false;
|
|
|
|
} else {
|
|
|
|
assert.strictEqual(chunk.length, 0);
|
|
|
|
}
|
2017-07-20 10:08:35 +00:00
|
|
|
setImmediate(callback);
|
2019-05-15 05:34:12 +00:00
|
|
|
}, 2)
|
2017-07-20 10:08:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
res.socket = ws;
|
|
|
|
ws._httpMessage = res;
|
|
|
|
res.connection = ws;
|
|
|
|
|
|
|
|
res.end('hello world');
|