PageRenderTime 62ms CodeModel.GetById 23ms app.highlight 21ms RepoModel.GetById 17ms app.codeStats 0ms

/node_modules/restify/node_modules/keep-alive-agent/README.md

https://github.com/jloiola/shack-api
Markdown | 59 lines | 42 code | 17 blank | 0 comment | 0 complexity | 3df4ef2d0faedd8f821a3d79d688077a MD5 | raw file
 1# keep-alive-agent
 2
 3keep-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
 9Create 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
11To 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
15A keep-alive agent that creates tls sockets. Use it the same way you use the http agent.
16
17## Examples
18
19```javascript
20var http = require('http'),
21    KeepAliveAgent = require('keep-alive-agent');
22
23var getOptions = {
24    hostname: 'twitter.com',
25    port: 80,
26    path: '/dshaw',
27    agent: new KeepAliveAgent(),
28};
29http.get(getOptions, function(response)
30{
31	response.pipe(process.stdout);
32});
33```
34
35To re-use secure connections, use the Secure keep-alive agent:
36
37```javascript
38var https = require('https'),
39    KeepAliveAgent = require('keep-alive-agent');
40
41var getOptions = {
42    hostname: 'www.duckduckgo.com',
43    port: 443,
44    path: '/?q=unicorns',
45    agent: new KeepAliveAgent.Secure(),
46};
47https.get(getOptions, function(response)
48{
49	response.pipe(process.stdout);
50});
51```
52
53## See Also
54
55For 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
59MIT.