lib: remove usage of url.parse

Since url.parse() is deprecated, it must not be used inside Node.js.

PR-URL: https://github.com/nodejs/node/pull/36853
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Beth Griggs <bgriggs@redhat.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
This commit is contained in:
raisinten
2021-01-09 18:17:43 +05:30
committed by Darshan Sen
parent ad38be4f6a
commit 295e766c27
6 changed files with 7 additions and 99 deletions

View File

@@ -37,7 +37,6 @@ const {
require('internal/util').assertCrypto();
const tls = require('tls');
const url = require('url');
const { Agent: HttpAgent } = require('_http_agent');
const {
Server: HttpServer,
@@ -296,27 +295,12 @@ Agent.prototype._evictSession = function _evictSession(key) {
const globalAgent = new Agent();
let urlWarningEmitted = false;
function request(...args) {
let options = {};
if (typeof args[0] === 'string') {
const urlStr = ArrayPrototypeShift(args);
try {
options = urlToHttpOptions(new URL(urlStr));
} catch (err) {
options = url.parse(urlStr);
if (!options.hostname) {
throw err;
}
if (!urlWarningEmitted && !process.noDeprecation) {
urlWarningEmitted = true;
process.emitWarning(
`The provided URL ${urlStr} is not a valid URL, and is supported ` +
'in the https module solely for compatibility.',
'DeprecationWarning', 'DEP0109');
}
}
options = urlToHttpOptions(new URL(urlStr));
} else if (args[0] && args[0][searchParamsSymbol] &&
args[0][searchParamsSymbol][searchParamsSymbol]) {
// url.URL instance