Skip to content

Commit 673924c

Browse files
committed
http: don't throw in isValidConnectPath
1 parent 82f6499 commit 673924c

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

lib/_http_client.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const {
6060
const Agent = require('_http_agent');
6161
const { Buffer } = require('buffer');
6262
const { defaultTriggerAsyncIdScope } = require('internal/async_hooks');
63-
const { URL, urlToHttpOptions, isURL } = require('internal/url');
63+
const { URL, URLParse, urlToHttpOptions, isURL } = require('internal/url');
6464
const {
6565
kOutHeaders,
6666
kNeedDrain,
@@ -196,23 +196,18 @@ function authoritiesMatch(canonicalHost, hostFromHeader) {
196196

197197
function isValidConnectPath(path) {
198198
const match = CONNECT_PATH_REGEX.exec(path);
199-
if (match === null) {
199+
if (match === null || +match[2] === 0) {
200200
return false;
201201
}
202202

203-
try {
204-
validatePort(match[2], 'options.path', false);
205-
const url = new URL(`http://${path}`);
206-
207-
return url.hostname !== '' &&
208-
url.username === '' &&
209-
url.password === '' &&
210-
url.pathname === '/' &&
211-
url.search === '' &&
212-
url.hash === '';
213-
} catch {
214-
return false;
215-
}
203+
const url = URLParse(`http://${path}`);
204+
return url !== null &&
205+
url.hostname !== '' &&
206+
url.username === '' &&
207+
url.password === '' &&
208+
url.pathname === '/' &&
209+
url.search === '' &&
210+
url.hash === '';
216211
}
217212

218213
// https://datatracker.ietf.org/doc/html/rfc9112#section-3.2

0 commit comments

Comments
 (0)