2017-07-20 10:08:35 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const { ServerResponse } = require('http');
|
|
|
|
const { Writable } = require('stream');
|
|
|
|
const assert = require('assert');
|
|
|
|
|
2018-12-10 12:27:32 +00:00
|
|
|
// Check that ServerResponse can be used without a proper Socket
|
2020-07-30 17:46:22 +00:00
|
|
|
// Refs: https://github.com/nodejs/node/issues/14386
|
|
|
|
// Refs: https://github.com/nodejs/node/issues/14381
|
2017-07-20 10:08:35 +00:00
|
|
|
|
|
|
|
const res = new ServerResponse({
|
|
|
|
method: 'GET',
|
|
|
|
httpVersionMajor: 1,
|
|
|
|
httpVersionMinor: 1
|
|
|
|
});
|
|
|
|
|
2019-05-15 05:34:12 +00:00
|
|
|
let firstChunk = true;
|
|
|
|
|
2017-07-20 10:08:35 +00:00
|
|
|
const ws = new Writable({
|
|
|
|
write: common.mustCall((chunk, encoding, callback) => {
|
2019-05-15 05:34:12 +00:00
|
|
|
if (firstChunk) {
|
|
|
|
assert(chunk.toString().endsWith('hello world'));
|
|
|
|
firstChunk = false;
|
|
|
|
} else {
|
|
|
|
assert.strictEqual(chunk.length, 0);
|
|
|
|
}
|
2017-07-20 10:08:35 +00:00
|
|
|
setImmediate(callback);
|
2019-05-15 05:34:12 +00:00
|
|
|
}, 2)
|
2017-07-20 10:08:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
res.assignSocket(ws);
|
|
|
|
|
2023-05-02 20:02:17 +00:00
|
|
|
assert.throws(function() {
|
|
|
|
res.assignSocket(ws);
|
|
|
|
}, {
|
|
|
|
code: 'ERR_HTTP_SOCKET_ASSIGNED'
|
|
|
|
});
|
|
|
|
|
2017-07-20 10:08:35 +00:00
|
|
|
res.end('hello world');
|