From 0f0106fc718d98e9f11382eb9292cf736c933f59 Mon Sep 17 00:00:00 2001 From: Tijn Kersjes Date: Wed, 18 May 2016 12:37:38 +0200 Subject: [PATCH] Pass all http options to fetch --- lib/__tests__/index.js | 20 ++++++++++++++++++++ lib/index.js | 10 +++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/__tests__/index.js b/lib/__tests__/index.js index 405ca92..7d43381 100644 --- a/lib/__tests__/index.js +++ b/lib/__tests__/index.js @@ -64,6 +64,26 @@ describe('LokkaHTTPTransport', () => { credentials: 'include' }); }); + + it('should add custom options', () => { + const headers = { + bb: 'hello' + }; + const transport = new LokkaHTTPTransport('/', {headers, blabla: 42}); + const options = transport._buildOptions({aa: 10}); + + expect(options).to.deep.equal({ + method: 'post', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + bb: 'hello' + }, + body: JSON.stringify({aa: 10}), + credentials: 'include', + blabla: 42 + }); + }); }); describe('send()', () => { diff --git a/lib/index.js b/lib/index.js index c037a56..3cf3816 100644 --- a/lib/index.js +++ b/lib/index.js @@ -18,10 +18,9 @@ export class Transport extends LokkaTransport { } super(); - this._httpOptions = { - auth: options.auth, - headers: options.headers || {} - }; + const { headers, ...rest } = options; + this._httpHeaders = headers || {}; + this._httpOptions = { ...rest }; this.endpoint = endpoint; } @@ -37,7 +36,8 @@ export class Transport extends LokkaTransport { credentials: 'include', }; - Object.assign(options.headers, this._httpOptions.headers); + Object.assign(options.headers, this._httpHeaders); + Object.assign(options, this._httpOptions); return options; }