Skip to content

Commit 064807c

Browse files
committed
Fix 843 (#845)
* Fix #843 * Updated test
1 parent 72b67fe commit 064807c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/Connection.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ class Connection {
191191
path: '',
192192
href: url.href,
193193
origin: url.origin,
194-
port: url.port,
194+
// https://github.com/elastic/elasticsearch-js/issues/843
195+
port: url.port !== '' ? url.port : undefined,
195196
headers: this.headers,
196197
auth: !!url.username === true || !!url.password === true
197198
? `${url.username}:${url.password}`

test/unit/connection.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,3 +763,34 @@ test('Util.inspect Connection class should hide agent and ssl', t => {
763763
roles: { master: true, data: true, ingest: true, ml: false } }`)
764764
)
765765
})
766+
767+
// https://github.com/elastic/elasticsearch-js/issues/843
768+
test('Port handling', t => {
769+
t.test('http 80', t => {
770+
const connection = new Connection({
771+
url: new URL('http://localhost:80')
772+
})
773+
774+
t.strictEqual(
775+
connection.buildRequestObject({}).port,
776+
undefined
777+
)
778+
779+
t.end()
780+
})
781+
782+
t.test('https 443', t => {
783+
const connection = new Connection({
784+
url: new URL('https://localhost:443')
785+
})
786+
787+
t.strictEqual(
788+
connection.buildRequestObject({}).port,
789+
undefined
790+
)
791+
792+
t.end()
793+
})
794+
795+
t.end()
796+
})

0 commit comments

Comments
 (0)