From 1709ba2bf159e393575f10ba18f49cd8868964f3 Mon Sep 17 00:00:00 2001 From: Raoul Gaillard Date: Tue, 3 Nov 2020 20:14:08 +0100 Subject: [PATCH] chore(all): Revert "chore(all): Revert "feat(headers): Process new headers"" This reverts commit b3ae23b7464bcecfe09245f1c6d1c606aa9845dc. --- src/index.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index f0bb314..97373d7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -89,13 +89,13 @@ class SimpleQL { * Not the right solution */ private async processHeaders( - headers: ISimpleQLHeaders + headers: ISimpleQLHeaders, ): Promise { const h: ISimpleQLHeaders = { ...headers } as DynamicHeaders const keys = Object.keys(headers) const dynamicHeaders = headers as DynamicHeaders - if (keys.length > 0 && keys.filter(String).length === keys.length) { + if (keys.length > 0 && keys.filter(String).length === keys.length) { for (let name in headers) { if (typeof dynamicHeaders[name] === 'function') { h[name] = await (dynamicHeaders[name] as DynamicHeaderValue)() @@ -115,10 +115,13 @@ class SimpleQL { private async fetch( ctx: object | IQueryOptions, - options: IRequestInit + options: IRequestInit, ): Promise> { try { - const headers = await this.processHeaders(this.options.headers) + const headers = await this.processHeaders({ + ...this.options.headers, + ...options.headers, + }) const res = await fetch( this.options.method.toLocaleLowerCase() === 'get' @@ -130,7 +133,7 @@ class SimpleQL { ? { body: this.prepareBody(ctx as IQueryOptions) } : {}), headers, - } + }, ) if (res.status >= 400) { const error = await res.text() @@ -173,7 +176,7 @@ class SimpleQL { var key: any for (key in params) { query += `${encodeURIComponent(key)}=${encodeURIComponent( - this.encodeURIType(params[key]) + this.encodeURIType(params[key]), )}&` }