11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst { OutgoingMessage } = require('http'); 51cb0ef41Sopenharmony_ciconst { Writable } = require('stream'); 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci// Check that OutgoingMessage can be used without a proper Socket 91cb0ef41Sopenharmony_ci// Refs: https://github.com/nodejs/node/issues/14386 101cb0ef41Sopenharmony_ci// Refs: https://github.com/nodejs/node/issues/14381 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciclass Response extends OutgoingMessage { 131cb0ef41Sopenharmony_ci _implicitHeader() {} 141cb0ef41Sopenharmony_ci} 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciconst res = new Response(); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_cilet firstChunk = true; 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ciconst ws = new Writable({ 211cb0ef41Sopenharmony_ci write: common.mustCall((chunk, encoding, callback) => { 221cb0ef41Sopenharmony_ci if (firstChunk) { 231cb0ef41Sopenharmony_ci assert(chunk.toString().endsWith('hello world')); 241cb0ef41Sopenharmony_ci firstChunk = false; 251cb0ef41Sopenharmony_ci } else { 261cb0ef41Sopenharmony_ci assert.strictEqual(chunk.length, 0); 271cb0ef41Sopenharmony_ci } 281cb0ef41Sopenharmony_ci setImmediate(callback); 291cb0ef41Sopenharmony_ci }, 2) 301cb0ef41Sopenharmony_ci}); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_cires.socket = ws; 331cb0ef41Sopenharmony_ciws._httpMessage = res; 341cb0ef41Sopenharmony_cires.connection = ws; 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_cires.end('hello world'); 37