Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9c5394ecdb | |||
| 96a103b305 | |||
| 3e9ae8b29c | |||
| 064807c5a9 |
2
lib/Connection.d.ts
vendored
2
lib/Connection.d.ts
vendored
@ -76,7 +76,9 @@ export default class Connection {
|
||||
setRole(role: string, enabled: boolean): Connection;
|
||||
status: string;
|
||||
buildRequestObject(params: any): http.ClientRequestArgs;
|
||||
// @ts-ignore
|
||||
[inspect.custom](object: any, options: InspectOptions): string;
|
||||
toJSON(): any;
|
||||
}
|
||||
|
||||
export {};
|
||||
|
||||
@ -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}`
|
||||
@ -238,6 +239,19 @@ class Connection {
|
||||
roles: this.roles
|
||||
}
|
||||
}
|
||||
|
||||
toJSON () {
|
||||
return {
|
||||
url: this.url,
|
||||
id: this.id,
|
||||
headers: this.headers,
|
||||
deadCount: this.deadCount,
|
||||
resurrectTimeout: this.resurrectTimeout,
|
||||
_openRequests: this._openRequests,
|
||||
status: this.status,
|
||||
roles: this.roles
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connection.statuses = {
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"homepage": "http://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html",
|
||||
"version": "7.0.0",
|
||||
"version": "7.0.1",
|
||||
"keywords": [
|
||||
"elasticsearch",
|
||||
"elastic",
|
||||
|
||||
@ -763,3 +763,47 @@ 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()
|
||||
})
|
||||
|
||||
test('Should not add agent and ssl to the serialized connection', t => {
|
||||
const connection = new Connection({
|
||||
url: new URL('http://localhost:9200')
|
||||
})
|
||||
|
||||
t.strictEqual(
|
||||
JSON.stringify(connection),
|
||||
'{"url":"http://localhost:9200/","id":"http://localhost:9200/","headers":null,"deadCount":0,"resurrectTimeout":0,"_openRequests":0,"status":"alive","roles":{"master":true,"data":true,"ingest":true,"ml":false}}'
|
||||
)
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user