https_agent.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * Https Agent base on custom http agent
  3. *
  4. * Copyright(c) node-modules and other contributors.
  5. * MIT Licensed
  6. *
  7. * Authors:
  8. * fengmk2 <m@fengmk2.com> (http://fengmk2.com)
  9. */
  10. 'use strict';
  11. /**
  12. * Module dependencies.
  13. */
  14. var https = require('https');
  15. var utils = require('./utils');
  16. var HttpAgent = require('./agent');
  17. var OriginalHttpsAgent = https.Agent;
  18. var HttpsAgent;
  19. if (utils.isNode10) {
  20. // node v0.10
  21. HttpsAgent = function HttpsAgent(options) {
  22. HttpAgent.call(this, options);
  23. this.defaultPort = 443;
  24. this.protocol = 'https:';
  25. };
  26. utils.inherits(HttpsAgent, HttpAgent);
  27. HttpsAgent.prototype.createConnection = https.globalAgent.createConnection;
  28. HttpsAgent.prototype.getName = function(options) {
  29. var name = HttpAgent.prototype.getName.call(this, options);
  30. name += ':';
  31. if (options.ca)
  32. name += options.ca;
  33. name += ':';
  34. if (options.cert)
  35. name += options.cert;
  36. name += ':';
  37. if (options.ciphers)
  38. name += options.ciphers;
  39. name += ':';
  40. if (options.key)
  41. name += options.key;
  42. name += ':';
  43. if (options.pfx)
  44. name += options.pfx;
  45. name += ':';
  46. if (options.rejectUnauthorized !== undefined)
  47. name += options.rejectUnauthorized;
  48. return name;
  49. };
  50. } else {
  51. HttpsAgent = function HttpsAgent(options) {
  52. HttpAgent.call(this, options);
  53. this.defaultPort = 443;
  54. this.protocol = 'https:';
  55. this.maxCachedSessions = this.options.maxCachedSessions;
  56. if (this.maxCachedSessions === undefined)
  57. this.maxCachedSessions = 100;
  58. this._sessionCache = {
  59. map: {},
  60. list: []
  61. };
  62. };
  63. utils.inherits(HttpsAgent, HttpAgent);
  64. [
  65. 'createConnection',
  66. 'getName',
  67. '_getSession',
  68. '_cacheSession',
  69. // https://github.com/nodejs/node/pull/4982
  70. '_evictSession',
  71. ].forEach(function(method) {
  72. if (typeof OriginalHttpsAgent.prototype[method] === 'function') {
  73. HttpsAgent.prototype[method] = OriginalHttpsAgent.prototype[method];
  74. }
  75. });
  76. }
  77. module.exports = HttpsAgent;