1'use strict';
2const common = require('../common');
3const http = require('http');
4const assert = require('assert');
5
6{
7  const server = http.createServer(common.mustCall((req, res) => {
8    assert.strictEqual(res.closed, false);
9    req.pipe(res);
10    res.on('error', common.mustNotCall());
11    res.on('close', common.mustCall(() => {
12      assert.strictEqual(res.closed, true);
13      res.end('asd');
14      process.nextTick(() => {
15        server.close();
16      });
17    }));
18  })).listen(0, () => {
19    http
20      .request({
21        port: server.address().port,
22        method: 'PUT'
23      })
24      .on('response', (res) => {
25        res.destroy();
26      })
27      .write('asd');
28  });
29}
30
31{
32  const server = http.createServer(common.mustCall((req, res) => {
33    assert.strictEqual(res.closed, false);
34    req.pipe(res);
35    res.on('error', common.mustNotCall());
36    res.on('close', common.mustCall(() => {
37      assert.strictEqual(res.closed, true);
38      process.nextTick(() => {
39        server.close();
40      });
41    }));
42    const err = new Error('Destroy test');
43    res.destroy(err);
44    assert.strictEqual(res.errored, err);
45  })).listen(0, () => {
46    http
47      .request({
48        port: server.address().port,
49        method: 'PUT'
50      })
51      .on('error', common.mustCall())
52      .write('asd');
53  });
54
55}
56