Custom agent #44

rauchg opened this Issue Oct 8, 2012 · 3 comments

4 participants


Since agent: false I've lost the ability to track the net sockets that correspond with each request. This is hugely important for testing what happens to polling requests when the underlying sockets close in when running the clients from Node.

A couple things would help me:

  • As I suggested before, the ability to generate a custom XMLHttpRequest:

    var XMLHTTPRequest = require('xmlhttprequest')({ agent: myCustomAgent });
  • The ability to access the Node request object. This requires adding some private property to the XMLHttpRequest instances.


+1. guille's solution is the most flexible, but in addition I think it would be beneficial/convenient to globally set the agent (which would also allow tweaking only maxSockets, another open issue).

require('xmlhttprequest').getHttpAgent().maxSockets = 100;

Because of this issue in Node which changed rejectUnauthorized from default false to true (see nodejs/node-v0.x-archive#3949), the TLS negotiation fails for self-signed certificates. This is very important when testing and before any CA signed certificates are installed in production. Currently there is no way to pass HTTP/HTTPS options into this module. Please consider enhancing the above agent option with a more generic option object (similar to the one used by HTTP/HTTPS requests) which also contains a custom Agent. This way users can set the "rejectUnauthorized" to false.

See examples for options format in

I will open a separate issue for this so it can be tracked. I would however suggest passing the options in the Request function rather than constructor to be more in line with HTTP/HTTPS paradigm.


@guille My proposed pull request (see above) would also address your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment