test-agentOptions.js 804 B

1234567891011121314151617181920212223
  1. var request = require('../index')
  2. , http = require('http')
  3. , server = require('./server')
  4. , assert = require('assert')
  5. ;
  6. var s = http.createServer(function (req, resp) {
  7. resp.statusCode = 200
  8. resp.end('')
  9. }).listen(6767, function () {
  10. // requests without agentOptions should use global agent
  11. var r = request('http://localhost:6767', function (e, resp, body) {
  12. assert.deepEqual(r.agent, http.globalAgent);
  13. assert.equal(Object.keys(r.pool).length, 0);
  14. // requests with agentOptions should apply agentOptions to new agent in pool
  15. var r2 = request('http://localhost:6767', { agentOptions: { foo: 'bar' } }, function (e, resp, body) {
  16. assert.deepEqual(r2.agent.options, { foo: 'bar' });
  17. assert.equal(Object.keys(r2.pool).length, 1);
  18. s.close()
  19. });
  20. })
  21. })