-
Notifications
You must be signed in to change notification settings - Fork 236
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
Connection keep alive behavior. #271
Comments
@Borewit That's odd. I'll take a look. |
Hmm, looks like you're right. I was looking at the test suite regarding the 'Connection' header and found this. It's been a while since I looked at the keep-alive behaviour, but the behaviour in general seems a bit confusing. Check out this thread. I guess we'll have to update the docs. Do you have any suggestions regarding our implementation? |
Not directly Tomás, But I keep it in mind, if I have time... |
Unfortunately, needle still doesn't support keep-alive connections under the hood. |
I'm in the middle of something now, but hope to take a look later today.
|
Has this been resolved? |
I can confirm that keep-alive is working in https (not tested with plain http). You must create agent with keepAlive set to true, see https://nodejs.org/api/http.html#http_new_agent_options and then use it as 'agent' option in all requests. Example: const agent = new require('https').Agent({ keepAlive: true });
...
needle('get',req,{ agent: agent }) . then... @tomas probably it will be nice to clarify this in documentation. |
Good point. Would you submit a PR? :) |
Hi all, It would be nice if needle behaviour could be the same as the Node's default behaviour. |
Been using needle for 2 years and thought connection is kept alive by default. Until today when my colleague found that connection closes. I was referencing "Regarding the 'Connection' header" part in docs, but was confused. Found this issue and created PR to clarify this behaviour. #378 |
Thanks for the PR @Al-Kostryukov. I'll see if I can simplify the use of keep-alive without having to initialize a http agent. |
Ok so after diving a bit deeper I think I found out what is going on. Turns out that if you pass one or more of the TLS options (e.g. Using a one-time Agent means no connection pooling is done, which is the default behaviour of Node and Needle when using keep-alive (which is the default unless you set the connection header to I just pushed a new branch that removes the |
Tomas, I don't think that information is accurate.
To me it looks like the default behavior of Node (tested with v10.13.0, seen it with older versions as well) is not to enable keep-alive (sending
Connection: close
):Tested both with & without HTTP-proxy assigned, consistent behavior.
The only way I found to keep the connection alive is by assigning an Http(s)Agent:
This doesn't seem to work in combination with an http-proxy.
Axios suffers from the same limitation: axios/axios#1981
The text was updated successfully, but these errors were encountered: