Created
October 24, 2016 18:11
-
-
Save fengmk2/14c402a31cd44c1ed3ab772d74d085ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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