summaryrefslogtreecommitdiff
path: root/lib/internal/http2
diff options
context:
space:
mode:
authorLuigi Pinca <luigipinca@gmail.com>2019-06-24 18:15:58 +0200
committerLuigi Pinca <luigipinca@gmail.com>2019-07-01 18:26:10 +0200
commit26b048effb23eb479fe0e10087860bb7f9862f2a (patch)
tree4af8383b916eff1e048a0f5d1e2309747d7255ab /lib/internal/http2
parent9b77be4814cfe9cf816c05b325b2fa7bc6a92e55 (diff)
downloadandroid-node-v8-26b048effb23eb479fe0e10087860bb7f9862f2a.tar.gz
android-node-v8-26b048effb23eb479fe0e10087860bb7f9862f2a.tar.bz2
android-node-v8-26b048effb23eb479fe0e10087860bb7f9862f2a.zip
http2: remove square brackets from parsed hostname
Make `http2.connect()` work when using URLs with literal IPv6 addresses. Fixes: https://github.com/nodejs/node/issues/28216 PR-URL: https://github.com/nodejs/node/pull/28406 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Diffstat (limited to 'lib/internal/http2')
-rw-r--r--lib/internal/http2/core.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js
index fefb04d03d..a65dbb92c5 100644
--- a/lib/internal/http2/core.js
+++ b/lib/internal/http2/core.js
@@ -2778,7 +2778,16 @@ function connect(authority, options, listener) {
const protocol = authority.protocol || options.protocol || 'https:';
const port = '' + (authority.port !== '' ?
authority.port : (authority.protocol === 'http:' ? 80 : 443));
- const host = authority.hostname || authority.host || 'localhost';
+ let host = 'localhost';
+
+ if (authority.hostname) {
+ host = authority.hostname;
+
+ if (host[0] === '[')
+ host = host.slice(1, -1);
+ } else if (authority.host) {
+ host = authority.host;
+ }
let socket;
if (typeof options.createConnection === 'function') {