11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst { ServerResponse } = require('http');
51cb0ef41Sopenharmony_ciconst { Writable } = require('stream');
61cb0ef41Sopenharmony_ciconst assert = require('assert');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci// Check that ServerResponse 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_ciconst res = new ServerResponse({
131cb0ef41Sopenharmony_ci  method: 'GET',
141cb0ef41Sopenharmony_ci  httpVersionMajor: 1,
151cb0ef41Sopenharmony_ci  httpVersionMinor: 1
161cb0ef41Sopenharmony_ci});
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.assignSocket(ws);
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ciassert.throws(function() {
351cb0ef41Sopenharmony_ci  res.assignSocket(ws);
361cb0ef41Sopenharmony_ci}, {
371cb0ef41Sopenharmony_ci  code: 'ERR_HTTP_SOCKET_ASSIGNED'
381cb0ef41Sopenharmony_ci});
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_cires.end('hello world');
41