1'use strict'; 2 3const common = require('../common'); 4const assert = require('assert'); 5const { get, createServer } = require('http'); 6 7// res.writable should not be set to false after it has finished sending 8// Ref: https://github.com/nodejs/node/issues/15029 9 10let internal; 11let external; 12 13// Proxy server 14const server = createServer(common.mustCall((req, res) => { 15 const listener = common.mustCall(() => { 16 assert.strictEqual(res.writable, true); 17 }); 18 19 // on CentOS 5, 'finish' is emitted 20 res.on('finish', listener); 21 // Everywhere else, 'close' is emitted 22 res.on('close', listener); 23 24 get(`http://127.0.0.1:${internal.address().port}`, common.mustCall((inner) => { 25 inner.pipe(res); 26 })); 27})).listen(0, () => { 28 // Http server 29 internal = createServer((req, res) => { 30 res.writeHead(200); 31 setImmediate(common.mustCall(() => { 32 external.abort(); 33 res.end('Hello World\n'); 34 })); 35 }).listen(0, () => { 36 external = get(`http://127.0.0.1:${server.address().port}`); 37 external.on('error', common.mustCall(() => { 38 server.close(); 39 internal.close(); 40 })); 41 }); 42}); 43