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]), )}&` }