2 const url = require('url');
3 const https = require('https');
6 * This currently needs to be applied to all Node.js versions
7 * in order to determine if the `req` is an HTTP or HTTPS request.
9 * There is currently no PR attempting to move this property upstream.
11 const patchMarker = "__agent_base_https_request_patched__";
12 if (!https.request[patchMarker]) {
13 https.request = (function(request) {
14 return function(_options, cb) {
16 if (typeof _options === 'string') {
17 options = url.parse(_options);
19 options = Object.assign({}, _options);
21 if (null == options.port) {
24 options.secureEndpoint = true;
25 return request.call(https, options, cb);
28 https.request[patchMarker] = true;
32 * This is needed for Node.js >= 9.0.0 to make sure `https.get()` uses the
33 * patched `https.request()`.
35 * Ref: https://github.com/nodejs/node/commit/5118f31
37 https.get = function (_url, _options, cb) {
39 if (typeof _url === 'string' && _options && typeof _options !== 'function') {
40 options = Object.assign({}, url.parse(_url), _options);
41 } else if (!_options && !cb) {
48 const req = https.request(options, cb);