1'use strict'; 2 3const common = require('../common'); 4const { ServerResponse } = require('http'); 5const { Writable } = require('stream'); 6const assert = require('assert'); 7 8// Check that ServerResponse 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 12const res = new ServerResponse({ 13 method: 'GET', 14 httpVersionMajor: 1, 15 httpVersionMinor: 1 16}); 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.assignSocket(ws); 33 34assert.throws(function() { 35 res.assignSocket(ws); 36}, { 37 code: 'ERR_HTTP_SOCKET_ASSIGNED' 38}); 39 40res.end('hello world'); 41