Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access NodeJS KeepAlive #3556

Closed
markfermor opened this issue Feb 9, 2018 · 3 comments
Closed

How to access NodeJS KeepAlive #3556

markfermor opened this issue Feb 9, 2018 · 3 comments
Labels

Comments

@markfermor
Copy link

I'm not sure how or if it's even possible to use https://nodejs.org/docs/latest-v8.x/api/http.html#http_request_setsocketkeepalive_enable_initialdelay

I'm interested in being able to do something like

    if (req.headers['via'].incudes('random')) {
      req.setSocketKeepAlive(true, 1000)
    }

The point being I'd like to be able to change the HTTP Keep Alive behaviour per request based on the content of the request being sent. Obviously the above doesn't work, is there a way to do it?

I can use https://nodejs.org/docs/latest-v8.x/api/http.html#http_server_keepalivetimeout as a setting for any/all requests, but I'm wondering if I don't have to do that, and could instead do it on a per request basis?

@dougwilson dougwilson reopened this Feb 9, 2018
@dougwilson
Copy link
Contributor

It doesn't looks like this is possible to do in Node.js. Express just uses the Node.js HTTP server so is limited by what it allows you to do. The "req" object is https://nodejs.org/docs/latest-v8.x/api/http.html#http_class_http_incomingmessage and the "res" object is https://nodejs.org/docs/latest-v8.x/api/http.html#http_class_http_serverresponse

@dougwilson
Copy link
Contributor

Actually from the Node.js docs, looks like it is "req.socket.setKeepAlive()"

@markfermor
Copy link
Author

ahh that's beautiful. I've been trying to understand how it works/all links together. That solves it I think.
Many Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants