From 8d12bfeb7ddd1a1b76e7b1249311a928ee300653 Mon Sep 17 00:00:00 2001 From: Malte-Thorben Bruns Date: Thu, 23 Apr 2015 00:06:40 +0200 Subject: [PATCH] call: add support for keepAlive & keepAliveMsecs options --- README.markdown | 8 ++++---- doc/api.markdown | 2 +- doc/plugin-api.markdown | 2 +- doc/plugins.markdown | 2 +- lib/call.js | 4 +++- lib/plugins/validate.js | 3 --- lib/rail.js | 4 ++++ 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/README.markdown b/README.markdown index 3e46162..6f65954 100644 --- a/README.markdown +++ b/README.markdown @@ -9,13 +9,13 @@ _rail_ is a io.js/node.js HTTP client supporting https, http and [http2](https://www.npmjs.com/package/http2). -The concept of _a single request_ is extended to _a possible series of requests_ further referenced as a _call_. -This allows a seamless integration of redirect and authentication mechanisms that require multiple requests to satisfy the original one. - A set of built-in plugins, currently featuring [`buffer`](./doc/plugins.markdown#buffer), [`cookies`](./doc/plugins.markdown#cookies), [`redirect`](./doc/plugins.markdown#redirect), [`json`](./doc/plugins.markdown#json) & [`validate`](./doc/plugins.markdown#validate), make simple requests even simpler, and a powerful event-driven plugin interface aids in the implementation of complex RESTful API calls. -The API is _mostly_ compatible with `http.request()` & `https.request()` and allows _rail_ to be used as a _drop-in replacement_. +The concept of _a single request_ is extended to _a possible series of requests_ further referenced as a _call_. +This allows a seamless integration of redirect and authentication mechanisms that require multiple requests to satisfy the original one. + +The API is mostly compatible with `http.request()` & `https.request()` and allows _rail_ to be used as a _drop-in replacement_. _rail_ works with [io.js](https://iojs.org/) 1.x and [node.js](https://nodejs.org/) 0.10.x/0.12.x. diff --git a/doc/api.markdown b/doc/api.markdown index b0872ca..19b3587 100644 --- a/doc/api.markdown +++ b/doc/api.markdown @@ -1,4 +1,4 @@ -# [RAIL](../README.markdown) API +# [rail](../README.markdown) API ### RAIL.plugins An object holding all built-in [plugins](./doc/plugins.markdown). diff --git a/doc/plugin-api.markdown b/doc/plugin-api.markdown index a8a1d41..9e66c45 100644 --- a/doc/plugin-api.markdown +++ b/doc/plugin-api.markdown @@ -1,4 +1,4 @@ -# [RAIL](../README.markdown) Plugin API +# [rail](../README.markdown) Plugin API ## Table of Contents diff --git a/doc/plugins.markdown b/doc/plugins.markdown index 6a22cdc..5e7b220 100644 --- a/doc/plugins.markdown +++ b/doc/plugins.markdown @@ -1,4 +1,4 @@ -# [RAIL](../README.markdown) Plugins +# [rail](../README.markdown) Plugins ## Table of Contents diff --git a/lib/call.js b/lib/call.js index cb2cc83..492bf3b 100644 --- a/lib/call.js +++ b/lib/call.js @@ -88,7 +88,9 @@ Call.prototype.__configure = function(options) { port: req.port || defaults.port, headers: {}, auth: req.auth || defaults.auth, - agent: req.agent !== undefined ? req.agent : defaults.agent + agent: req.agent !== undefined ? req.agent : defaults.agent, + keepAlive: req.keepAlive || false, + keepAliveMsecs: req.keepAliveMsecs || 1000 }; if (defaults.headers) { diff --git a/lib/plugins/validate.js b/lib/plugins/validate.js index 483698b..aabf4ac 100644 --- a/lib/plugins/validate.js +++ b/lib/plugins/validate.js @@ -38,7 +38,6 @@ ValidatePlugin.prototype._setup = function() { var self = this; var rail = this._rail; - rail.on('plugin-configure', function(call, options) { options.validate = options.validate || {}; @@ -47,7 +46,6 @@ ValidatePlugin.prototype._setup = function() { } }); - rail.on('plugin-response', function(call, options, response) { var err; response.validate = true; @@ -66,7 +64,6 @@ ValidatePlugin.prototype._setup = function() { } }); - this._intercept = function(call, options, response) { self._interceptResponse(call, options, response); }; diff --git a/lib/rail.js b/lib/rail.js index bea83be..029d554 100644 --- a/lib/rail.js +++ b/lib/rail.js @@ -33,6 +33,10 @@ function RAIL(opt_options) { headers: req.headers, auth: req.auth, agent: req.agent, + keepAlive: req.keepAlive, + keepAliveMsecs: req.keepAliveMsecs, + + // tls options ca: req.ca, pfx: req.pfx, key: req.key,