PageRenderTime 24ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/Chuks/BookFinder-RESTAPI
Markdown | 59 lines | 42 code | 17 blank | 0 comment | 0 complexity | 3df4ef2d0faedd8f821a3d79d688077a MD5 | raw file
Possible License(s): Apache-2.0, MIT, CC-BY-SA-3.0, 0BSD, BSD-3-Clause
  1. # keep-alive-agent
  2. 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.
  3. ## Usage
  4. __new KeepAliveAgent(*options-hash*)__
  5. 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.
  6. 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.
  7. __new KeepAliveAgent.Secure(*options-hash*)__
  8. A keep-alive agent that creates tls sockets. Use it the same way you use the http agent.
  9. ## Examples
  10. ```javascript
  11. var http = require('http'),
  12. KeepAliveAgent = require('keep-alive-agent');
  13. var getOptions = {
  14. hostname: 'twitter.com',
  15. port: 80,
  16. path: '/dshaw',
  17. agent: new KeepAliveAgent(),
  18. };
  19. http.get(getOptions, function(response)
  20. {
  21. response.pipe(process.stdout);
  22. });
  23. ```
  24. To re-use secure connections, use the Secure keep-alive agent:
  25. ```javascript
  26. var https = require('https'),
  27. KeepAliveAgent = require('keep-alive-agent');
  28. var getOptions = {
  29. hostname: 'www.duckduckgo.com',
  30. port: 443,
  31. path: '/?q=unicorns',
  32. agent: new KeepAliveAgent.Secure(),
  33. };
  34. https.get(getOptions, function(response)
  35. {
  36. response.pipe(process.stdout);
  37. });
  38. ```
  39. ## See Also
  40. 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).
  41. ## Licence
  42. MIT.