Comparing version 0.0.7 to 1.0.0
@@ -10,3 +10,4 @@ /* | ||
var globalOutgoing = 0, | ||
globalIncoming = 0; | ||
globalIncoming = 0, | ||
globalNoDelayFlag = false; | ||
@@ -16,2 +17,4 @@ //overwrite the global functions to control the timeout behavior. | ||
var nodeVersion = Number(process.versions.node.match(/^(\d+\.\d+)/)[1]); | ||
function mergeConfig(global, local) { | ||
@@ -53,3 +56,3 @@ var result = {}, i; | ||
_onTimeout : function () { | ||
_onTimeout : function node_limits_timeout() { | ||
if (this.message instanceof http.ClientRequest) { | ||
@@ -79,3 +82,3 @@ var abortError; | ||
*/ | ||
remove : function () { | ||
remove : function node_limits_remove() { | ||
timers.unenroll(this); | ||
@@ -88,3 +91,3 @@ if (this.message && this.message.__closer) { | ||
http.ClientRequest.prototype.onSocket = function (socket) { | ||
http.ClientRequest.prototype.onSocket = function node_limits_onsocket(socket) { | ||
// Attach socket | ||
@@ -95,14 +98,32 @@ var s = hassign.apply(this, arguments), | ||
if (globalOutgoing > 0 && this instanceof http.ClientRequest) { | ||
closer = new Closer(this, globalOutgoing); | ||
if (globalNoDelayFlag) { | ||
socket.setNoDelay(true); | ||
} | ||
var freeFn = function node_limits_free() { | ||
if (socket._httpMessage === self) { | ||
// Detach socket | ||
if (self.__closer) { | ||
timers.unenroll(self.__closer); | ||
delete self.__closer; | ||
} | ||
} | ||
}; | ||
if (globalOutgoing > 0 && self instanceof http.ClientRequest) { | ||
if (socket) { | ||
socket.once('free', function () { | ||
if (socket._httpMessage === self) { | ||
//Detach Socket | ||
if (self.__closer) { | ||
timers.unenroll(self.__closer); | ||
delete self.__closer; | ||
} | ||
if (nodeVersion >= 6.0) { | ||
closer = new Closer(self, globalOutgoing); | ||
socket.prependOnceListener('free', freeFn); | ||
} | ||
else { | ||
// for Node < 6, prependListener does not exist | ||
// and we need it for keepAlive connections with agents to work | ||
// | ||
// Thus, we'll only add a timer to those requests which are *not* keepalive | ||
if (!self.shouldKeepAlive) { | ||
closer = new Closer(self, globalOutgoing); | ||
socket.once('free', freeFn); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -176,2 +197,8 @@ } | ||
closer = new Closer(resp, timeout); | ||
resp.on('finish', function() { | ||
closer.remove(); | ||
}); | ||
resp.on('close', function() { | ||
closer.remove(); | ||
}); | ||
} | ||
@@ -181,3 +208,3 @@ } | ||
/* | ||
* Set Socket NoDelay to true | ||
* Set Socket NoDelay to true (only for incoming requests!) | ||
*/ | ||
@@ -193,2 +220,10 @@ function setNoDelay(conf, req) { | ||
/* | ||
* Sets whether socketNoDelay should be set on all outgoing ClientRequests | ||
*/ | ||
function setClientRequestNoDelay(conf) { | ||
globalNoDelayFlag = !!conf.socket_no_delay; | ||
} | ||
/* | ||
* Sets the maxSockects | ||
@@ -203,10 +238,14 @@ */ | ||
module.exports = function (config) { | ||
module.exports = function node_limits_init(config) { | ||
if (config && (config.enable === "true" || config.enable === true)) { | ||
globalOutgoing = 0; | ||
globalIncoming = 0; | ||
exposeGlobalTimers(config); | ||
//set MaxSocket at module load time coz its used for http client request | ||
setDefaultMaxSockets(config); | ||
setClientRequestNoDelay(config); | ||
} | ||
return function (req, resp, next) { | ||
return function node_limits(req, resp, next) { | ||
var count = null, | ||
@@ -237,9 +276,10 @@ conf = (req.mod_config) ? mergeConfig(config, req.mod_config) : config, | ||
setDefaultMaxSockets(conf); | ||
setClientRequestNoDelay(conf); | ||
setNoDelay(conf, req); | ||
instrumentReq(conf, req, resp); | ||
setNoDelay(conf, req); | ||
// Wrapping req.emit. Will be called when | ||
// client calls req.on('data' | ||
req.emit = function (eventName, data) { | ||
req.emit = function node_limits_emit(eventName, data) { | ||
@@ -257,3 +297,3 @@ if (eventName === 'data') { | ||
if (!resp._header) { | ||
if (!resp.headersSent) { // since node-v0.9.3 | ||
if (req.socket) { | ||
@@ -269,3 +309,4 @@ req.socket.setNoDelay(true); | ||
} | ||
req.emit('error', 'Request Entity Too Large'); | ||
// Forward all events to original emitter | ||
reqEmit.call(req, 'error', 'Request Entity Too Large'); | ||
req._hadError = true; | ||
@@ -272,0 +313,0 @@ |
@@ -5,32 +5,41 @@ { | ||
"author": "Vinit Sacheti<vsacheti@yahoo-inc.com>", | ||
"version": "0.0.7", | ||
"version": "1.0.0", | ||
"devDependencies": { | ||
"ytestrunner": "*", | ||
"yuitest": "*", | ||
"jshint": "~0.9.0", | ||
"istanbul": "~0.1.27" | ||
"jshint": "~2.9.5", | ||
"mocha": "~5.1", | ||
"nyc": "^11.7", | ||
"sinon": "^5.0", | ||
"async": "^1.5.2" | ||
}, | ||
"contributors": [{ | ||
"name": "Evan Torrie", | ||
"email": "evan.torrie@yahoo.com" | ||
}], | ||
"contributors": [ | ||
{ | ||
"name": "Evan Torrie", | ||
"email": "evan.torrie@yahoo.com" | ||
} | ||
], | ||
"main": "./lib/index.js", | ||
"scripts": { | ||
"pretest": "jshint --config ./node_modules/yui-lint/jshint.json ./lib/", | ||
"test": "istanbul cover --print=both --yui ytestrunner -- --include ./tests/options.js --include ./tests/builder.js --include ./tests/parser.js --include ./tests/parser_coffee.js --include ./tests/test-limits.js" | ||
"pretest": "jshint ./lib/", | ||
"test": "nyc mocha test/unit.js test/functional.js" | ||
}, | ||
"bugs": { "url" : "http://github.com/yahoo/node-limits/issues" }, | ||
"licenses":[ | ||
"bugs": { | ||
"url": "http://github.com/yahoo/node-limits/issues" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type" : "BSD", | ||
"url" : "https://github.com/yahoo/node-limits/blob/master/LICENSE" | ||
"type": "BSD", | ||
"url": "https://github.com/yahoo/node-limits/blob/master/LICENSE" | ||
} | ||
], | ||
"repository": { | ||
"type":"git", | ||
"url":"http://github.com/yahoo/node-limits.git" | ||
"type": "git", | ||
"url": "http://github.com/yahoo/node-limits.git" | ||
}, | ||
"engines": { | ||
"node": ">0.8.x" | ||
} | ||
"node": ">4.x" | ||
}, | ||
"files": [ | ||
"lib/" | ||
], | ||
"dependencies": {} | ||
} |
@@ -8,32 +8,52 @@ limits | ||
* Preventing upload completely. | ||
In config, use: { file_uploads: false } | ||
### Enforcing HTTP timeouts | ||
* Limiting the total size of upload | ||
In config, use: { post_max_size: [bytes] }, if 0, this functionality is disabled | ||
* Limiting the length of uri | ||
In config, use: { uri_max_length: [number] }, if 0 this functionality is disabled | ||
* Setting a global absolute timeout for both incoming and outgoing connections | ||
In config, use: { global_timeout: [millis] }, if 0 - no timeout is set | ||
In config, use: `{ global_timeout: [millis] }`, if 0 - no timeout is set | ||
* Setting a global absolute timeout for incoming connections only | ||
In config, use: { inc_req_timeout: [millis] }, if 0 - no timeout is set | ||
In config, use: `{ inc_req_timeout: [millis] }`, if 0 - no timeout is set | ||
* Setting a global absolute timeout for outgoing connections only | ||
In config, use: { out_req_timeout: [millis] }, if 0 - no timeout is set | ||
In config, use: `{ out_req_timeout: [millis] }`, if 0 - no timeout is set | ||
* Setting idle timeout for incoming connections | ||
In config, use: { idle_timeout: [millis] }, if 0 - no timeout is set | ||
In config, use: `{ idle_timeout: [millis] }`, if 0 - no timeout is set | ||
* Setting the http.Agent.defaultMaxSockets for the entire app | ||
In config, use: { max_sockets: [number] }, if 0 - nothing will be set. | ||
_Note_: Apart from `idle_timeout`, each of these settings applies to | ||
the complete roundtrip request/response cycle. For example, `inc_req_timeout` | ||
applies to the interval from when the server receives an incoming request to | ||
the time that the corresponding response is sent. `out_req_timeout` | ||
applies to the interval from when a client request is sent to the time the | ||
response is received (and the socket freed). | ||
_Warning for Node v4.x_: The outgoing request timeout mechanism does | ||
not work for keepAlive connections in Node v4.x and earlier. Instead, | ||
in Node v4.x, this timeout is applied only if the outgoing | ||
ClientRequest is marked as *not* keepAlive at the time the socket is | ||
attached to the request. | ||
### Ancillary HTTP limits | ||
* Preventing upload completely. In config, use: `{ file_uploads: | ||
false }` | ||
* Limiting the total size of upload | ||
In config, use: `{ post_max_size: [bytes] }`, if 0, this functionality is disabled | ||
* Setting the socket noDelay | ||
In config, use: { socket_no_delay: [boolean] }, if false - nothing will be set. | ||
* Limiting the length of uri | ||
In config, use: `{ uri_max_length: [number] }`, if 0 this functionality is disabled | ||
To completely disable module use config, { enable: false }. | ||
Each of the above functionality is disabled if corresponding config attribute is not set. | ||
* Setting the http.Agent.defaultMaxSockets for the entire app. | ||
In config, use: `{ max_sockets: [number] }`, if 0 - nothing will be set. | ||
Note: this applies only to the *http* global agent. | ||
* Setting incoming/outgoing socket noDelay (i.e. disable Nagle's algorithm) | ||
In config, use: `{ socket_no_delay: [boolean] }`, if false - nothing will be set. | ||
To completely disable module use config, `{ enable: false }`. | ||
Functionality for a specific feature will be disabled if the | ||
corresponding config attribute is not set. | ||
install | ||
@@ -40,0 +60,0 @@ ------- |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
92
16070
5
4
282