diff --git a/src/node/index.js b/src/node/index.js index 75217c8b..42c8f932 100644 --- a/src/node/index.js +++ b/src/node/index.js @@ -749,7 +749,7 @@ Request.prototype.request = function () { options.method = this.method; options.port = url.port; options.path = path; - options.host = url.hostname; + options.host = utils.normalizeHostname(url.hostname); // ex: [::1] -> ::1 options.ca = this._ca; options.key = this._key; options.pfx = this._pfx; diff --git a/src/utils.js b/src/utils.js index bd8333f9..fac56f1b 100644 --- a/src/utils.js +++ b/src/utils.js @@ -71,6 +71,11 @@ exports.cleanHeader = (header, changesOrigin) => { return header; }; +exports.normalizeHostname = (hostname) => { + const [,normalized] = hostname.match(/^\[([^\]]+)\]$/) || []; + return normalized || hostname; +}; + /** * Check if `obj` is an object. * diff --git a/test/node/basic.js b/test/node/basic.js index a0255322..16dfcb1a 100644 --- a/test/node/basic.js +++ b/test/node/basic.js @@ -134,6 +134,24 @@ describe('[node] request', () => { }); }); + if (doesntWorkInHttp2) { + describe('ipv6 address', () => { + it('should successfully query an ipv6 address', (done) => { + request.get(`http://[::]:${process.env.ZUUL_PORT}/url?a=(b%29`).end((error, res) => { + assert.equal('/url?a=(b%29', res.text); + done(); + }); + }); + + it('should successfully query an ipv6 address', (done) => { + request.get(`http://[::1]:${process.env.ZUUL_PORT}/url?a=(b%29`).end((error, res) => { + assert.equal('/url?a=(b%29', res.text); + done(); + }); + }); + }); + } + describe('.buffer()', () => { it('should enable buffering', (done) => { request