From baac04782b27df02572e612641ae7d91e2fc5941 Mon Sep 17 00:00:00 2001 From: delvedor Date: Fri, 10 May 2019 09:44:31 +0200 Subject: [PATCH 1/2] Fix #843 --- lib/Connection.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Connection.js b/lib/Connection.js index e90182453..9560b40cf 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -191,7 +191,8 @@ class Connection { path: '', href: url.href, origin: url.origin, - port: url.port, + // https://github.com/elastic/elasticsearch-js/issues/843 + port: url.port !== '' ? url.port : undefined, headers: this.headers, auth: !!url.username === true || !!url.password === true ? `${url.username}:${url.password}` From ccc61151fe942ffd84c18884e4ce4ae7674ed984 Mon Sep 17 00:00:00 2001 From: delvedor Date: Fri, 10 May 2019 09:44:35 +0200 Subject: [PATCH 2/2] Updated test --- test/unit/connection.test.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/unit/connection.test.js b/test/unit/connection.test.js index 84068cad5..4d1040280 100644 --- a/test/unit/connection.test.js +++ b/test/unit/connection.test.js @@ -763,3 +763,34 @@ test('Util.inspect Connection class should hide agent and ssl', t => { roles: { master: true, data: true, ingest: true, ml: false } }`) ) }) + +// https://github.com/elastic/elasticsearch-js/issues/843 +test('Port handling', t => { + t.test('http 80', t => { + const connection = new Connection({ + url: new URL('http://localhost:80') + }) + + t.strictEqual( + connection.buildRequestObject({}).port, + undefined + ) + + t.end() + }) + + t.test('https 443', t => { + const connection = new Connection({ + url: new URL('https://localhost:443') + }) + + t.strictEqual( + connection.buildRequestObject({}).port, + undefined + ) + + t.end() + }) + + t.end() +})