1// Copyright Joyent, Inc. and other Node contributors. 2// 3// Permission is hereby granted, free of charge, to any person obtaining a 4// copy of this software and associated documentation files (the 5// "Software"), to deal in the Software without restriction, including 6// without limitation the rights to use, copy, modify, merge, publish, 7// distribute, sublicense, and/or sell copies of the Software, and to permit 8// persons to whom the Software is furnished to do so, subject to the 9// following conditions: 10// 11// The above copyright notice and this permission notice shall be included 12// in all copies or substantial portions of the Software. 13// 14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20// USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22'use strict'; 23const common = require('../common'); 24const http = require('http'); 25const assert = require('assert'); 26 27{ 28 const server = http.createServer( 29 common.mustCall((req, res) => { 30 res.writeHead(200); 31 res.write('a'); 32 }) 33 ); 34 server.listen( 35 0, 36 common.mustCall(() => { 37 http.get( 38 { port: server.address().port }, 39 common.mustCall((res) => { 40 res.on('data', common.mustCall(() => { 41 res.destroy(); 42 })); 43 assert.strictEqual(res.destroyed, false); 44 res.on('close', common.mustCall(() => { 45 assert.strictEqual(res.destroyed, true); 46 server.close(); 47 })); 48 }) 49 ); 50 }) 51 ); 52} 53 54{ 55 const server = http.createServer( 56 common.mustCall((req, res) => { 57 res.writeHead(200); 58 res.end('a'); 59 }) 60 ); 61 server.listen( 62 0, 63 common.mustCall(() => { 64 http.get( 65 { port: server.address().port }, 66 common.mustCall((res) => { 67 assert.strictEqual(res.destroyed, false); 68 res.on('end', common.mustCall(() => { 69 assert.strictEqual(res.destroyed, false); 70 })); 71 res.on('close', common.mustCall(() => { 72 assert.strictEqual(res.destroyed, true); 73 server.close(); 74 })); 75 res.resume(); 76 }) 77 ); 78 }) 79 ); 80} 81 82{ 83 const server = http.createServer( 84 common.mustCall((req, res) => { 85 res.on('close', common.mustCall()); 86 res.destroy(); 87 }) 88 ); 89 90 server.listen( 91 0, 92 common.mustCall(() => { 93 http.get( 94 { port: server.address().port }, 95 common.mustNotCall() 96 ) 97 .on('error', common.mustCall(() => { 98 server.close(); 99 })); 100 }) 101 ); 102} 103