From 974bf0a819c3c5c0a955f66b618f7599f4231465 Mon Sep 17 00:00:00 2001 From: delvedor Date: Wed, 20 Feb 2019 12:43:06 +0100 Subject: [PATCH] Added global headers option --- index.js | 4 +++- lib/Transport.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 051c88b91..783ceeafc 100644 --- a/index.js +++ b/index.js @@ -50,6 +50,7 @@ class Client extends EventEmitter { compression: false, ssl: null, agent: null, + headers: {}, nodeFilter: null, nodeWeighter: null, nodeSelector: 'round-robin' @@ -85,7 +86,8 @@ class Client extends EventEmitter { sniffOnConnectionFault: options.sniffOnConnectionFault, sniffEndpoint: options.sniffEndpoint, suggestCompression: options.suggestCompression, - compression: options.compression + compression: options.compression, + headers: options.headers }) const apis = buildApi({ diff --git a/lib/Transport.js b/lib/Transport.js index 94a1df69f..6dafb3574 100644 --- a/lib/Transport.js +++ b/lib/Transport.js @@ -27,6 +27,7 @@ class Transport { this.requestTimeout = toMs(opts.requestTimeout) this.suggestCompression = opts.suggestCompression === true this.compression = opts.compression || false + this.headers = opts.headers || {} this.sniffInterval = opts.sniffInterval this.sniffOnConnectionFault = opts.sniffOnConnectionFault this.sniffEndpoint = opts.sniffEndpoint @@ -82,7 +83,8 @@ class Transport { return callback(new NoLivingConnectionsError('There are not living connections'), result) } - const headers = options.headers || {} + // TODO: make this assignment FAST + const headers = Object.assign({}, this.headers, options.headers) // handle json body if (params.body != null) {