Skip to content

Commit 69f3db4

Browse files
mscdexjasnell
authored andcommitted
http,https: avoid instanceof for WHATWG URL
PR-URL: #12983 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent 85e2d56 commit 69f3db4

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/_http_client.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const debug = common.debug;
3434
const OutgoingMessage = require('_http_outgoing').OutgoingMessage;
3535
const Agent = require('_http_agent');
3636
const Buffer = require('buffer').Buffer;
37-
const urlToOptions = require('internal/url').urlToOptions;
37+
const { urlToOptions, searchParamsSymbol } = require('internal/url');
3838
const outHeadersKey = require('internal/http').outHeadersKey;
3939
const nextTick = require('internal/process/next_tick').nextTick;
4040

@@ -82,7 +82,9 @@ function ClientRequest(options, cb) {
8282
if (!options.hostname) {
8383
throw new Error('Unable to determine the domain name');
8484
}
85-
} else if (options instanceof url.URL) {
85+
} else if (options && options[searchParamsSymbol] &&
86+
options[searchParamsSymbol][searchParamsSymbol]) {
87+
// url.URL instance
8688
options = urlToOptions(options);
8789
} else {
8890
options = util._extend({}, options);

lib/https.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const http = require('http');
2929
const util = require('util');
3030
const inherits = util.inherits;
3131
const debug = util.debuglog('https');
32-
const urlToOptions = require('internal/url').urlToOptions;
32+
const { urlToOptions, searchParamsSymbol } = require('internal/url');
3333

3434
function Server(opts, requestListener) {
3535
if (!(this instanceof Server)) return new Server(opts, requestListener);
@@ -221,7 +221,9 @@ exports.request = function request(options, cb) {
221221
if (!options.hostname) {
222222
throw new Error('Unable to determine the domain name');
223223
}
224-
} else if (options instanceof url.URL) {
224+
} else if (options && options[searchParamsSymbol] &&
225+
options[searchParamsSymbol][searchParamsSymbol]) {
226+
// url.URL instance
225227
options = urlToOptions(options);
226228
} else {
227229
options = util._extend({}, options);

0 commit comments

Comments
 (0)