1'use strict';
2const common = require('../common');
3const http = require('http');
4
5{
6  let serverRes;
7  const server = http.Server(function(req, res) {
8    res.write('Part of my res.');
9    serverRes = res;
10  });
11
12  server.listen(0, common.mustCall(function() {
13    http.get({
14      port: this.address().port,
15      headers: { connection: 'keep-alive' }
16    }, common.mustCall(function(res) {
17      server.close();
18      serverRes.destroy();
19      res.on('aborted', common.mustCall());
20      res.on('error', common.expectsError({
21        code: 'ECONNRESET'
22      }));
23    }));
24  }));
25}
26
27{
28  // Don't crash of no 'error' handler.
29  let serverRes;
30  const server = http.Server(function(req, res) {
31    res.write('Part of my res.');
32    serverRes = res;
33  });
34
35  server.listen(0, common.mustCall(function() {
36    http.get({
37      port: this.address().port,
38      headers: { connection: 'keep-alive' }
39    }, common.mustCall(function(res) {
40      server.close();
41      serverRes.destroy();
42      res.on('aborted', common.mustCall());
43    }));
44  }));
45}
46