How to disable timeout in Node.js http servers?

I have a Node.js server that receives web requests from browsers. Now, some connections should remain open for a long time, perhaps forever - even if no data has been sent at this time.

By default, http servers in Node.js have a timeout of 120 seconds, but I can disable this: according to the Node.js documentation, it is possible to call setTimeoutand set a timeout on0 .

So basically it looks like this:

var http = require('http');

http.createServer(function (req, res) {
  req.setTimeout(0);
  // ...
}).listen(3000);

If I run this, it will work, but I wonder if this is really all I need. Are there any settings in browsers, any HTTP headers ... that could affect this behavior?

+4
source share

Source: https://habr.com/ru/post/1569200/


All Articles