Connection keep alive behavior.
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.6k
- Forks
- 237
- PR merge metrics
- No merged PRs in 30d
Description
Regarding the 'Connection' header
Unless you're running an old version of Node (< 0.11.4), by default Needle won't set the Connection header on requests, yielding Node's default behaviour of keeping the connection alive with the target server. This speeds up inmensely the process of sending several requests to the same host.
On older versions, however, this has the unwanted behaviour of preventing the runtime from exiting, either because of a bug or 'feature' that was changed on 0.11.4. To overcome this Needle does set the 'Connection' header to 'close' on those versions, however this also means that making new requests to the same host doesn't benefit from Keep-Alive.
So if you're stuck on 0.10 or even lower and want full speed, you can simply set the Connection header to 'Keep-Alive' by using { connection: 'Keep-Alive' }. Please note, though, that an event loop handler will prevent the runtime from exiting so you'll need to manually call process.exit() or the universe will collapse.
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):
GET /ws/2/artist/?query=Stromae&offset=&limit=&fmt=json HTTP/1.1
accept: */*
user-agent: Needle/2.2.4 (Node.js v10.13.0; win32 x64)
host: test.musicbrainz.org
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:
const httpAgent = new http.Agent({keepAlive: true});
needle('get', 'http://something', null, {
user_agent: httpAgent
});
const httpsAgent = new https.Agent({keepAlive: true});
needle('get', 'https://something', null, {
user_agent: httpsAgent
});
This doesn't seem to work in combination with an http-proxy.
Axios suffers from the same limitation: axios/axios#1981
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the request examples in the issue with and without an HTTP proxy, comparing the Connection header and the behavior of the supplied http.Agent and https.Agent. The issue names no files or tests; a complete resolution would establish the intended keep-alive behavior and update the relevant implementation or documentation accordingly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100