current commit
260801.17 · http: runtime deprecate instantiating without new
'use strict';
const common = require('../common');
const http = require('http');

{
  let serverRes;
  const server = new http.Server(function(req, res) {
    res.write('Part of my res.');
    serverRes = res;
  });

  server.listen(0, common.mustCall(function() {
    http.get({
      port: this.address().port,
      headers: { connection: 'keep-alive' }
    }, common.mustCall(function(res) {
      server.close();
      serverRes.destroy();
      res.on('aborted', common.mustCall());
      res.on('error', common.expectsError({
        code: 'ECONNRESET'
      }));
    }));
  }));
}

{
  // Don't crash of no 'error' handler.
  let serverRes;
  const server = new http.Server(function(req, res) {
    res.write('Part of my res.');
    serverRes = res;
  });

  server.listen(0, common.mustCall(function() {
    http.get({
      port: this.address().port,
      headers: { connection: 'keep-alive' }
    }, common.mustCall(function(res) {
      server.close();
      serverRes.destroy();
      res.on('aborted', common.mustCall());
    }));
  }));
}