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