Skip to content

Instantly share code, notes, and snippets.

@fengmk2
Created October 24, 2016 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fengmk2/14c402a31cd44c1ed3ab772d74d085ec to your computer and use it in GitHub Desktop.
Save fengmk2/14c402a31cd44c1ed3ab772d74d085ec to your computer and use it in GitHub Desktop.
'use strict';
var https = require('https');
var http = require('http');
var urllib = require('urllib');
var httpsAgent = new https.Agent({ keepAlive: true });
var agent = new http.Agent({ keepAlive: true });
// cnodejs.org => 123.59.77.142
var url = 'https://123.59.77.142';
console.log('timing: %s', url);
var count = 10;
function request(index) {
if (index === count) {
return;
}
urllib.request(url, {
headers: {
host: 'cnodejs.org',
},
data: { wd: 'nodejs' },
timing: true,
httpsAgent: httpsAgent,
agent: agent,
}, function (err, data, res) {
console.log('---------------------------');
console.log('No#%d: %s, keepalive: %s, content size: %d',
index, res.statusCode, res.keepAliveSocket, data.length);
console.log(res.timing);
index++;
setImmediate(request.bind(null, index));
});
}
request(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment