Compare commits

..

4 Commits

Author SHA1 Message Date
9c5394ecdb Bumped v7.0.1 2019-05-14 17:49:52 -04:00
96a103b305 Added toJSON method to Connection class (#849)
* Added toJSON method to Connection class

* Updated test

* Updated typings
2019-05-14 12:01:21 -04:00
3e9ae8b29c Fix #803 (#846) 2019-05-14 12:01:21 -04:00
064807c5a9 Fix 843 (#845)
* Fix #843

* Updated test
2019-05-10 10:56:06 +02:00
4 changed files with 62 additions and 2 deletions

2
lib/Connection.d.ts vendored
View File

@ -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 {};

View File

@ -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 = {

View File

@ -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",

View File

@ -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()
})