diff --git a/.dist.eslintrc b/.dist.eslintrc index 6fbc43fd..6fa48a70 100644 --- a/.dist.eslintrc +++ b/.dist.eslintrc @@ -17,6 +17,7 @@ "no-undef": "off", "no-unused-vars": "off", "no-useless-escape": "off", + "no-obj-calls": "off", "no-cond-assign": "off", "no-redeclare": "off", "node/no-exports-assign": "off", diff --git a/src/node/http2wrapper.js b/src/node/http2wrapper.js index af315095..0605abd8 100644 --- a/src/node/http2wrapper.js +++ b/src/node/http2wrapper.js @@ -21,6 +21,10 @@ function setProtocol(protocol) { }; } +function normalizeIpv6Host(host) { + return net.isIP(host) === 6 ? `[${host}]` : host; +} + class Request extends Stream { constructor(protocol, options) { super(); @@ -48,11 +52,12 @@ class Request extends Stream { this._headers = {}; + const normalizedHost = normalizeIpv6Host(host); const session = http2.connect( - `${protocol}//${host}:${port}`, + `${protocol}//${normalizedHost}:${port}`, sessionOptions ); - this.setHeader('host', `${host}:${port}`); + this.setHeader('host', `${normalizedHost}:${port}`); session.on('error', (error) => this.emit('error', error)); diff --git a/test/node/basic.js b/test/node/basic.js index 16dfcb1a..d2510362 100644 --- a/test/node/basic.js +++ b/test/node/basic.js @@ -134,23 +134,21 @@ 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(); - }); + 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(); - }); + 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) => {