2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-07-15 15:43:24 -04:00
|
|
|
const common = require('../common');
|
2011-10-04 18:08:18 -04:00
|
|
|
var http = require('http');
|
2011-02-24 17:16:11 -08:00
|
|
|
|
2011-10-04 18:08:18 -04:00
|
|
|
var server = http.Server(function(req, res) {
|
|
|
|
console.log('Server accepted request.');
|
2011-02-24 17:16:11 -08:00
|
|
|
res.writeHead(200);
|
2011-10-04 18:08:18 -04:00
|
|
|
res.write('Part of my res.');
|
2011-02-24 17:16:11 -08:00
|
|
|
|
|
|
|
res.destroy();
|
|
|
|
});
|
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
server.listen(0, common.mustCall(function() {
|
2015-12-25 15:32:13 -08:00
|
|
|
http.get({
|
2016-05-29 03:06:56 -04:00
|
|
|
port: this.address().port,
|
2011-10-04 18:08:18 -04:00
|
|
|
headers: { connection: 'keep-alive' }
|
2016-07-15 15:43:24 -04:00
|
|
|
}, common.mustCall(function(res) {
|
2011-02-24 17:16:11 -08:00
|
|
|
server.close();
|
|
|
|
|
2011-10-04 18:08:18 -04:00
|
|
|
console.log('Got res: ' + res.statusCode);
|
2011-02-24 17:16:11 -08:00
|
|
|
console.dir(res.headers);
|
|
|
|
|
2011-10-04 18:08:18 -04:00
|
|
|
res.on('data', function(chunk) {
|
|
|
|
console.log('Read ' + chunk.length + ' bytes');
|
2012-12-13 09:52:08 -08:00
|
|
|
console.log(' chunk=%j', chunk.toString());
|
2011-02-24 17:16:11 -08:00
|
|
|
});
|
|
|
|
|
2011-10-04 18:08:18 -04:00
|
|
|
res.on('end', function() {
|
|
|
|
console.log('Response ended.');
|
2011-02-24 17:16:11 -08:00
|
|
|
});
|
|
|
|
|
2012-12-13 09:52:08 -08:00
|
|
|
res.on('aborted', function() {
|
|
|
|
console.log('Response aborted.');
|
|
|
|
});
|
|
|
|
|
|
|
|
res.socket.on('close', function() {
|
|
|
|
console.log('socket closed, but not res');
|
2015-05-19 13:00:06 +02:00
|
|
|
});
|
2012-12-13 09:52:08 -08:00
|
|
|
|
2011-02-24 17:16:11 -08:00
|
|
|
// it would be nice if this worked:
|
2016-07-15 15:43:24 -04:00
|
|
|
res.on('close', common.mustCall(function() {}));
|
|
|
|
}));
|
|
|
|
}));
|