Search code examples
javascriptnode.jskoa

Forever-agent in request.js - how to check if it's working


recently, external server(REST API) told me to use Keep-alive for my request. That's great, since I use request.js(node 8) I found "forever" option:

forever - set to true to use the forever-agent Note: Defaults to http(s).Agent({keepAlive:true}) in node 0.12+

To test if it's working I created my own server in Node8 using Koa.js and Node script where I create array of 100 GET request to my server and after that, I Promise.all them.

However, I don't how can I check if it's using the same agent, if it's working correctly.

Do you have any ideas, how from client(or server) point of view I can check that?

Is keep-alive enough proof that all request for certain domain are using the same agent in 1 Node.js process?


Solution

  • On the client, you can try to capture the socket which is used to send the request using the socket event. You can verify that they are using the same sockets on the client.

    req.on("socket", function (socket) {
    //if saved  socket is empty save it 
    //else check if its using  the saved socket
    
    }