From acaa4a2a2bb6bbc18eb92c9e29175f4f556c4985 Mon Sep 17 00:00:00 2001 From: Brian White Date: Thu, 11 May 2017 17:57:53 -0400 Subject: [PATCH] http,https: avoid instanceof for WHATWG URL PR-URL: https://github.com/nodejs/node/pull/12983 Reviewed-By: Colin Ihrig Reviewed-By: Timothy Gu Reviewed-By: Daijiro Wachi Reviewed-By: Joyee Cheung --- lib/_http_client.js | 6 ++++-- lib/https.js | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/_http_client.js b/lib/_http_client.js index a238a4f14c35e6..3e1ed888279df3 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -34,7 +34,7 @@ const debug = common.debug; const OutgoingMessage = require('_http_outgoing').OutgoingMessage; const Agent = require('_http_agent'); const Buffer = require('buffer').Buffer; -const urlToOptions = require('internal/url').urlToOptions; +const { urlToOptions, searchParamsSymbol } = require('internal/url'); const outHeadersKey = require('internal/http').outHeadersKey; const nextTick = require('internal/process/next_tick').nextTick; @@ -82,7 +82,9 @@ function ClientRequest(options, cb) { if (!options.hostname) { throw new Error('Unable to determine the domain name'); } - } else if (options instanceof url.URL) { + } else if (options && options[searchParamsSymbol] && + options[searchParamsSymbol][searchParamsSymbol]) { + // url.URL instance options = urlToOptions(options); } else { options = util._extend({}, options); diff --git a/lib/https.js b/lib/https.js index 1ca546ac106248..f0ecbd90a6700f 100644 --- a/lib/https.js +++ b/lib/https.js @@ -29,7 +29,7 @@ const http = require('http'); const util = require('util'); const inherits = util.inherits; const debug = util.debuglog('https'); -const urlToOptions = require('internal/url').urlToOptions; +const { urlToOptions, searchParamsSymbol } = require('internal/url'); function Server(opts, requestListener) { if (!(this instanceof Server)) return new Server(opts, requestListener); @@ -221,7 +221,9 @@ exports.request = function request(options, cb) { if (!options.hostname) { throw new Error('Unable to determine the domain name'); } - } else if (options instanceof url.URL) { + } else if (options && options[searchParamsSymbol] && + options[searchParamsSymbol][searchParamsSymbol]) { + // url.URL instance options = urlToOptions(options); } else { options = util._extend({}, options);