我可以在node.js请求模块中设置套接字超时和读取超时吗?

时间:2016-06-02 15:52:10

标签: javascript node.js sockets request restify

我使用node.js(restify)和请求模块(https://www.npmjs.com/package/request)。 我的节点服务器是代理并请求其他服务器。 我想设置套接字超时和读取超时。 像java中的clientSocket.connect / clientSocket.setSoTimeOut。 但是请求模块文档只给出“超时”。

我可以设置套接字超时并读取超时的其他值吗?

1 个答案:

答案 0 :(得分:0)

似乎没有。来自文档:

timeout - Integer containing the number of milliseconds to wait for a server
to send response headers (and start the response body) before aborting the
request. Note that if the underlying TCP connection cannot be established, the
OS-wide TCP connection timeout will overrule the timeout option (the default
in Linux can be anywhere from 20-120 seconds).

因此,对于实际的连接超时,您依赖于操作系统。如果你有这个权利,你可以根据需要改变它。

如果您想要您正在寻找的控件,您可以随时使用带有解决方案的客户端。例如,JSON客户端的文档显示了以下选项:

connectTimeout  Number  Amount of time to wait for a socket
requestTimeout  Number  Amount of time to wait for the request to finish