2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-07-15 15:43:24 -04:00
|
|
|
const common = require('../common');
|
2016-12-30 18:38:06 -05:00
|
|
|
const assert = require('assert');
|
|
|
|
const http = require('http');
|
|
|
|
const net = require('net');
|
2011-09-08 13:46:57 +02:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const options = {
|
2011-09-08 13:46:57 +02:00
|
|
|
host: '127.0.0.1',
|
2016-05-29 03:06:56 -04:00
|
|
|
port: undefined
|
2011-09-08 13:46:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// start a tcp server that closes incoming connections immediately
|
2017-01-08 13:19:00 +00:00
|
|
|
const server = net.createServer(function(client) {
|
2011-09-08 13:46:57 +02:00
|
|
|
client.destroy();
|
|
|
|
server.close();
|
|
|
|
});
|
2016-07-15 15:43:24 -04:00
|
|
|
server.listen(0, options.host, common.mustCall(onListen));
|
2011-09-08 13:46:57 +02:00
|
|
|
|
|
|
|
// do a GET request, expect it to fail
|
|
|
|
function onListen() {
|
2016-05-29 03:06:56 -04:00
|
|
|
options.port = this.address().port;
|
2017-02-03 14:54:19 -05:00
|
|
|
const req = http.request(options, common.mustNotCall());
|
2016-07-15 15:43:24 -04:00
|
|
|
req.on('error', common.mustCall(function(err) {
|
2017-01-08 15:36:25 +00:00
|
|
|
assert.strictEqual(err.code, 'ECONNRESET');
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|
2011-09-08 13:46:57 +02:00
|
|
|
req.end();
|
|
|
|
}
|