• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5
6const http = require('http');
7
8for (const method of ['abort', 'destroy']) {
9  const server = http.createServer(common.mustCall((req, res) => {
10    res.end(req.url);
11  }));
12  server.listen(0, common.mustCall(() => {
13    const agent = http.Agent({ keepAlive: true });
14
15    const req = http
16      .request({
17        port: server.address().port,
18        agent
19      })
20      .on('socket', common.mustCall((socket) => {
21        socket.on('free', common.mustCall());
22      }))
23      .on('response', common.mustCall((res) => {
24        assert.strictEqual(req.destroyed, false);
25        res.on('end', () => {
26          assert.strictEqual(req.destroyed, true);
27          req[method]();
28          assert.strictEqual(req.socket.destroyed, false);
29          agent.destroy();
30          server.close();
31        }).resume();
32      }))
33      .end();
34    assert.strictEqual(req.destroyed, false);
35  }));
36}
37