Skip to content

Commit

Permalink
Release 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Nov 6, 2013
1 parent 7e53066 commit 13eb5b7
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 12 deletions.
16 changes: 16 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

0.2.0 / 2013-11-06
==================

* use keepalive agent on node 0.11+ impl

0.1.5 / 2013-06-24
==================

* support coveralls
* add node 0.10 test
* add 0.8.22 original https.js
* add original http.js module to diff
* update jscover
* mv pem to fixtures
* add https agent usage
44 changes: 44 additions & 0 deletions example/agent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
var http = require('http');
var Agent = require('../');

var keepaliveAgent = new Agent({
keepAlive: true
});
// https://www.google.com/search?q=nodejs&sugexp=chrome,mod=12&sourceid=chrome&ie=UTF-8
var options = {
host: 'gitcafe.com',
path: '/',
method: 'GET',
agent: keepaliveAgent
};

var start = Date.now();
var req = http.get(options, function (res) {
console.log('STATUS1: %d, %d ms', res.statusCode, Date.now() - start);
console.log('HEADERS1: %j', res.headers);
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY1: %d', chunk.length);
});
res.on('end', function () {
process.nextTick(function () {
start = Date.now();
http.get(options, function (res) {
console.log('STATUS2: %d, %d ms', res.statusCode, Date.now() - start);
console.log('HEADERS2: %j', res.headers);
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY2: %d', chunk.length);
});
});
});
});
});
req.on('error', function (e) {
console.log('problem with request: ' + e.message);
});

setTimeout(function () {
console.log('keep alive sockets:', keepaliveAgent);
process.exit();
}, 3000);
33 changes: 24 additions & 9 deletions example/https_agent.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
var https = require('https');
var HttpsAgent = require('../').HttpsAgent;

var keepaliveAgent = new HttpsAgent();
var keepaliveAgent = new HttpsAgent({
keepAlive: true
});
// https://www.google.com/search?q=nodejs&sugexp=chrome,mod=12&sourceid=chrome&ie=UTF-8
var options = {
host: 'www.google.com',
host: 'github.com',
port: 443,
path: '/search?q=nodejs&sugexp=chrome,mod=12&sourceid=chrome&ie=UTF-8',
path: '/',
method: 'GET',
agent: keepaliveAgent
};

var start = Date.now();
var req = https.request(options, function (res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
console.log('STATUS1: %d, %d ms', res.statusCode, Date.now() - start);
console.log('HEADERS1: %j', res.headers);
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
console.log('BODY1: %d', chunk.length);
});
res.on('end', function () {
process.nextTick(function () {
start = Date.now();
https.get(options, function (res) {
console.log('STATUS2: %d, %d ms', res.statusCode, Date.now() - start);
console.log('HEADERS2: %j', res.headers);
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY2: %d', chunk.length);
});
});
});
});
});

Expand All @@ -26,7 +42,6 @@ req.on('error', function (e) {
req.end();

setTimeout(function () {
console.log('keep alive sockets:');
console.log(keepaliveAgent.unusedSockets);
console.log('keep alive sockets:', keepaliveAgent);
process.exit();
}, 2000);
}, 5000);
4 changes: 2 additions & 2 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function Agent(options) {
freeSockets = freeSockets || [];
self.freeSockets[name] = freeSockets;
socket.setKeepAlive(true, self.keepAliveMsecs);
socket.unref();
socket.unref && socket.unref();
socket._httpMessage = null;
self.removeSocket(socket, options);
freeSockets.push(socket);
Expand Down Expand Up @@ -170,7 +170,7 @@ Agent.prototype.addRequest = function(req, options) {
if (!this.freeSockets[name].length)
delete this.freeSockets[name];

socket.ref();
socket.ref && socket.ref();
req.onSocket(socket);
this.sockets[name].push(socket);
} else if (sockLen < this.maxSockets) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "agentkeepalive",
"version": "0.1.5",
"version": "0.2.0",
"description": "Missing keepalive http.Agent",
"main": "index.js",
"directories": {
Expand Down Expand Up @@ -32,6 +32,7 @@
"coveralls": "*",
"mocha-lcov-reporter": "*"
},
"engines": { "node": ">= 0.10.0" },
"author": "fengmk2 <[email protected]> (http://fengmk2.github.com)",
"license": "MIT"
}

0 comments on commit 13eb5b7

Please sign in to comment.