Allow http.Agent
usage
#56
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
by passing in an
http.Agent
instance (eitherhttp.globalAgent
or any custom instance) to theXMLHttpRequest
constructor.This addresses #44 and #48.
This is so that connections can be reused by the standard Http Keep-Alive mechanism, that is based on the
http.Agent.maxSockets
setting. Without agents, every request means a new TCP connections, behavior that differs from browser implementations of XHR.One ramification of the former that made me implement this was that one TCP socket per HTTP request severely limits your ability to do load testing, as all your outbound ports get consumed in the
TIME_WAIT
state in no time. Try e.g.socket-io-client
and thexhr-polling
transport from node.js, which will usenode-XMLHttpRequest
, to verify.Browser implementations of XHR on the other hand recycle their TCP sockets, otherwise socket-io based clients would bail as well in normal, non load-testing scenarios, when more than 16k events in 4 minutes are sent (the numbers highly depend on your OS and TCP settings).
Implementation note: It maintains backwards compatibility, in that if you don't pass in an agent, none will be used.
Ideally however, I'd like
http.globalAgent
to be the default, like it is with node'shttp
requests, and like it was the case fornode-XMLHttpRequest
until changed by 8958631 , which @guile also laments in #44. However, my patch maintains the current status quo.