简体   繁体   English

使用node.js ForeverAgent

[英]Using node.js ForeverAgent

To reuse connections when making http.requests I'd like to use the ForeverAgent without having to use the whole request module. 为了在进行http.requests时重用连接,我想使用ForeverAgent而不必使用整个请求模块。

I'm using node v0.8.15 我正在使用节点v0.8.15

Is that possible? 那可能吗? Can someone tell me how? 有人可以告诉我如何吗?

With the layout/structure of the current version of Mikeal's request module, you should be able to do something like the following: 使用Mikeal请求模块当前版本的布局/结构,您应该能够执行以下操作:

var ForeverAgent = require('request/forever');

var myAgent = new ForeverAgent();
var myRequest = http.request({/* … */, agent:myAgent});
/* … */

See the node.js http documentation for a bit more details on the agent option although it is sparse; 请参阅node.js http文档 ,以获取关于代理选项的更多详细信息,尽管它很少。 I don't see any documentation whatsoever (beyond the source code) for this module's "forever" agent itself. 我没有看到任何有关此模块“永久”代理本身的文档(源代码之外)。

ForeverAgent最近被拆分成自己的模块 ,因此您应该使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM