11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst http = require('http'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci{ 61cb0ef41Sopenharmony_ci let serverRes; 71cb0ef41Sopenharmony_ci const server = http.Server(function(req, res) { 81cb0ef41Sopenharmony_ci res.write('Part of my res.'); 91cb0ef41Sopenharmony_ci serverRes = res; 101cb0ef41Sopenharmony_ci }); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci server.listen(0, common.mustCall(function() { 131cb0ef41Sopenharmony_ci http.get({ 141cb0ef41Sopenharmony_ci port: this.address().port, 151cb0ef41Sopenharmony_ci headers: { connection: 'keep-alive' } 161cb0ef41Sopenharmony_ci }, common.mustCall(function(res) { 171cb0ef41Sopenharmony_ci server.close(); 181cb0ef41Sopenharmony_ci serverRes.destroy(); 191cb0ef41Sopenharmony_ci res.on('aborted', common.mustCall()); 201cb0ef41Sopenharmony_ci res.on('error', common.expectsError({ 211cb0ef41Sopenharmony_ci code: 'ECONNRESET' 221cb0ef41Sopenharmony_ci })); 231cb0ef41Sopenharmony_ci })); 241cb0ef41Sopenharmony_ci })); 251cb0ef41Sopenharmony_ci} 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci{ 281cb0ef41Sopenharmony_ci // Don't crash of no 'error' handler. 291cb0ef41Sopenharmony_ci let serverRes; 301cb0ef41Sopenharmony_ci const server = http.Server(function(req, res) { 311cb0ef41Sopenharmony_ci res.write('Part of my res.'); 321cb0ef41Sopenharmony_ci serverRes = res; 331cb0ef41Sopenharmony_ci }); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci server.listen(0, common.mustCall(function() { 361cb0ef41Sopenharmony_ci http.get({ 371cb0ef41Sopenharmony_ci port: this.address().port, 381cb0ef41Sopenharmony_ci headers: { connection: 'keep-alive' } 391cb0ef41Sopenharmony_ci }, common.mustCall(function(res) { 401cb0ef41Sopenharmony_ci server.close(); 411cb0ef41Sopenharmony_ci serverRes.destroy(); 421cb0ef41Sopenharmony_ci res.on('aborted', common.mustCall()); 431cb0ef41Sopenharmony_ci })); 441cb0ef41Sopenharmony_ci })); 451cb0ef41Sopenharmony_ci} 46