Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f3ff692b76 | |||
| 1e8e09f47a | |||
| 152e5c85b6 | |||
| e7443e0a33 |
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;
|
setRole(role: string, enabled: boolean): Connection;
|
||||||
status: string;
|
status: string;
|
||||||
buildRequestObject(params: any): http.ClientRequestArgs;
|
buildRequestObject(params: any): http.ClientRequestArgs;
|
||||||
|
// @ts-ignore
|
||||||
[inspect.custom](object: any, options: InspectOptions): string;
|
[inspect.custom](object: any, options: InspectOptions): string;
|
||||||
|
toJSON(): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export {};
|
export {};
|
||||||
|
|||||||
@ -191,7 +191,8 @@ class Connection {
|
|||||||
path: '',
|
path: '',
|
||||||
href: url.href,
|
href: url.href,
|
||||||
origin: url.origin,
|
origin: url.origin,
|
||||||
port: url.port,
|
// https://github.com/elastic/elasticsearch-js/issues/843
|
||||||
|
port: url.port !== '' ? url.port : undefined,
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
auth: !!url.username === true || !!url.password === true
|
auth: !!url.username === true || !!url.password === true
|
||||||
? `${url.username}:${url.password}`
|
? `${url.username}:${url.password}`
|
||||||
@ -238,6 +239,19 @@ class Connection {
|
|||||||
roles: this.roles
|
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 = {
|
Connection.statuses = {
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"types": "index.d.ts",
|
"types": "index.d.ts",
|
||||||
"homepage": "http://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html",
|
"homepage": "http://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html",
|
||||||
"version": "5.6.16",
|
"version": "5.6.17",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"elasticsearch",
|
"elasticsearch",
|
||||||
"elastic",
|
"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 } }`)
|
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