Name: js-handler/node_modules/restify/node_modules/keep-alive-agent/README.md
| 1: | # keep-alive-agent |
| 2: | |
| 3: | keep-alive-agent is an HTTP connection pool agent for node.js that re-uses sockets. It is simpler than some agents that also solve this problem because it does not attempt to replace the Agent provided by node. If you want to re-use connections, use this agent. If you want the default node behavior, use the default global agent. |
| 4: | |
| 5: | ## Usage |
| 6: | |
| 7: | __new KeepAliveAgent(*options-hash*)__ |
| 8: | |
| 9: | Create an instance of the agent, passing the options hash through to the node Agent constructor. These options are in turn passed along to `createConnection()`. The KeepAliveAgent constructor does not use the options itself. The option you are most likely to change is `maxSockets`, which defaults to 5. |
| 10: | |
| 11: | To use the agent instance, set it in the `agent` field of the options passed to `http.request()` or `http.get()`. See the [http.request() documentation](http://nodejs.org/api/http.html#http_http_request_options_callback) for details. |
| 12: | |
| 13: | __new KeepAliveAgent.Secure(*options-hash*)__ |
| 14: | |
| 15: | A keep-alive agent that creates tls sockets. Use it the same way you use the http agent. |
| 16: | |
| 17: | ## Examples |
| 18: | |
| 19: | ```javascript |
| 20: | var http = require('http'), |
| 21: | KeepAliveAgent = require('keep-alive-agent'); |
| 22: | |
| 23: | var getOptions = { |
| 24: | hostname: 'twitter.com', |
| 25: | port: 80, |
| 26: | path: '/dshaw', |
| 27: | agent: new KeepAliveAgent(), |
| 28: | }; |
| 29: | http.get(getOptions, function(response) |
| 30: | { |
| 31: | response.pipe(process.stdout); |
| 32: | }); |
| 33: | ``` |
| 34: | |
| 35: | To re-use secure connections, use the Secure keep-alive agent: |
| 36: | |
| 37: | ```javascript |
| 38: | var https = require('https'), |
| 39: | KeepAliveAgent = require('keep-alive-agent'); |
| 40: | |
| 41: | var getOptions = { |
| 42: | hostname: 'www.duckduckgo.com', |
| 43: | port: 443, |
| 44: | path: '/?q=unicorns', |
| 45: | agent: new KeepAliveAgent.Secure(), |
| 46: | }; |
| 47: | https.get(getOptions, function(response) |
| 48: | { |
| 49: | response.pipe(process.stdout); |
| 50: | }); |
| 51: | ``` |
| 52: | |
| 53: | ## See Also |
| 54: | |
| 55: | For other implementations, see [agentkeepalive](https://github.com/TBEDP/agentkeepalive) and the [request](https://github.com/mikeal/request) module's [ForeverAgent](https://github.com/mikeal/request/blob/master/forever.js). |
| 56: | |
| 57: | ## Licence |
| 58: | |
| 59: | MIT. |
