mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
https: allow url and options to be passed to https.request
PR-URL: https://github.com/nodejs/node/pull/22003 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
29
lib/https.js
29
lib/https.js
@@ -255,9 +255,11 @@ Agent.prototype._evictSession = function _evictSession(key) {
|
||||
const globalAgent = new Agent();
|
||||
|
||||
let urlWarningEmitted = false;
|
||||
function request(options, cb) {
|
||||
if (typeof options === 'string') {
|
||||
const urlStr = options;
|
||||
function request(...args) {
|
||||
let options = {};
|
||||
|
||||
if (typeof args[0] === 'string') {
|
||||
const urlStr = args.shift();
|
||||
try {
|
||||
options = urlToOptions(new URL(urlStr));
|
||||
} catch (err) {
|
||||
@@ -273,19 +275,24 @@ function request(options, cb) {
|
||||
'DeprecationWarning', 'DEP0109');
|
||||
}
|
||||
}
|
||||
} else if (options && options[searchParamsSymbol] &&
|
||||
options[searchParamsSymbol][searchParamsSymbol]) {
|
||||
} else if (args[0] && args[0][searchParamsSymbol] &&
|
||||
args[0][searchParamsSymbol][searchParamsSymbol]) {
|
||||
// url.URL instance
|
||||
options = urlToOptions(options);
|
||||
} else {
|
||||
options = util._extend({}, options);
|
||||
options = urlToOptions(args.shift());
|
||||
}
|
||||
|
||||
if (args[0] && typeof args[0] !== 'function') {
|
||||
options = util._extend(options, args.shift());
|
||||
}
|
||||
|
||||
options._defaultAgent = globalAgent;
|
||||
return new ClientRequest(options, cb);
|
||||
args.unshift(options);
|
||||
|
||||
return new ClientRequest(...args);
|
||||
}
|
||||
|
||||
function get(options, cb) {
|
||||
const req = request(options, cb);
|
||||
function get(input, options, cb) {
|
||||
const req = request(input, options, cb);
|
||||
req.end();
|
||||
return req;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user