You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

https_agent.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use strict';
  2. const OriginalHttpsAgent = require('https').Agent;
  3. const HttpAgent = require('./agent');
  4. const {
  5. INIT_SOCKET,
  6. CREATE_HTTPS_CONNECTION,
  7. } = require('./constants');
  8. class HttpsAgent extends HttpAgent {
  9. constructor(options) {
  10. super(options);
  11. this.defaultPort = 443;
  12. this.protocol = 'https:';
  13. this.maxCachedSessions = this.options.maxCachedSessions;
  14. /* istanbul ignore next */
  15. if (this.maxCachedSessions === undefined) {
  16. this.maxCachedSessions = 100;
  17. }
  18. this._sessionCache = {
  19. map: {},
  20. list: [],
  21. };
  22. }
  23. createConnection(options, oncreate) {
  24. const socket = this[CREATE_HTTPS_CONNECTION](options, oncreate);
  25. this[INIT_SOCKET](socket, options);
  26. return socket;
  27. }
  28. }
  29. // https://github.com/nodejs/node/blob/master/lib/https.js#L89
  30. HttpsAgent.prototype[CREATE_HTTPS_CONNECTION] = OriginalHttpsAgent.prototype.createConnection;
  31. [
  32. 'getName',
  33. '_getSession',
  34. '_cacheSession',
  35. // https://github.com/nodejs/node/pull/4982
  36. '_evictSession',
  37. ].forEach(function(method) {
  38. /* istanbul ignore next */
  39. if (typeof OriginalHttpsAgent.prototype[method] === 'function') {
  40. HttpsAgent.prototype[method] = OriginalHttpsAgent.prototype[method];
  41. }
  42. });
  43. module.exports = HttpsAgent;