• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const { OutgoingMessage } = require('http');
5const { Writable } = require('stream');
6const assert = require('assert');
7
8// Check that OutgoingMessage can be used without a proper Socket
9// Refs: https://github.com/nodejs/node/issues/14386
10// Refs: https://github.com/nodejs/node/issues/14381
11
12class Response extends OutgoingMessage {
13  _implicitHeader() {}
14}
15
16const res = new Response();
17
18let firstChunk = true;
19
20const ws = new Writable({
21  write: common.mustCall((chunk, encoding, callback) => {
22    if (firstChunk) {
23      assert(chunk.toString().endsWith('hello world'));
24      firstChunk = false;
25    } else {
26      assert.strictEqual(chunk.length, 0);
27    }
28    setImmediate(callback);
29  }, 2)
30});
31
32res.socket = ws;
33ws._httpMessage = res;
34res.connection = ws;
35
36res.end('hello world');
37