How to set the HTTP Keep-Alive timeout in a nodejs server

后端 未结 2 2011
傲寒
傲寒 2020-12-02 07:54

I\'m actually doing some load testing against an ExpressJS server, and I noticed that the response send by the server includes a \"Connection: Keep-Alive\" header. As far as

相关标签:
2条回答
  • 2020-12-02 08:02

    For Express 3:

    var express = require('express');
    var app = express();
    var server = app.listen(5001);
    
    server.on('connection', function(socket) {
      console.log("A new connection was made by a client.");
      socket.setTimeout(30 * 1000); 
      // 30 second timeout. Change this as you see fit.
    });
    
    0 讨论(0)
  • 2020-12-02 08:21

    To set keepAliveTimeout on the express server do:

    var express = require('express');
    var app = express();
    var server = app.listen(5001);
    
    server.keepAliveTimeout = 30000;
    
    
    
    0 讨论(0)
提交回复
热议问题