diff --git a/lib/Connection.d.ts b/lib/Connection.d.ts index c31ff5925..0c49207af 100644 --- a/lib/Connection.d.ts +++ b/lib/Connection.d.ts @@ -78,6 +78,7 @@ export default class Connection { buildRequestObject(params: any): http.ClientRequestArgs; // @ts-ignore [inspect.custom](object: any, options: InspectOptions): string; + toJSON(): any; } export {}; diff --git a/lib/Connection.js b/lib/Connection.js index 9560b40cf..9e8f065ae 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -239,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 = { diff --git a/test/unit/connection.test.js b/test/unit/connection.test.js index 4d1040280..cb7fa9a54 100644 --- a/test/unit/connection.test.js +++ b/test/unit/connection.test.js @@ -794,3 +794,16 @@ test('Port handling', t => { 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() +})