From d9da26c21c617d4faf6b7a49e4c466041439abf6 Mon Sep 17 00:00:00 2001 From: Tony <454794+tonyrewin@users.noreply.github.com> Date: Tue, 16 Nov 2021 10:44:33 +0300 Subject: [PATCH 1/4] added http request headers injection support --- src/gFetch.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gFetch.ts b/src/gFetch.ts index e4d40ff..ce32b58 100644 --- a/src/gFetch.ts +++ b/src/gFetch.ts @@ -100,6 +100,7 @@ export type GFetchReturnWithErrors = Spread<[T, GFetchQueryDefault]>; export class GFetch extends Object { public path: string; + public headers?: { [key: string]: string } constructor(options: GClientOptions) { super(); @@ -127,7 +128,7 @@ export class GFetch extends Object { const res = await fetch(this.path, { method: "POST", credentials: "include", - headers: { "Content-Type": "application/json" }, + headers: { "Content-Type": "application/json", ...headers }, body: JSON.stringify(newQueries), }); From 0a101982ac4f30d2edc5f0355e10e7e577d7d880 Mon Sep 17 00:00:00 2001 From: Tony <454794+tonyrewin@users.noreply.github.com> Date: Thu, 18 Nov 2021 07:49:46 +0300 Subject: [PATCH 2/4] fix headers injection --- src/gFetch.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gFetch.ts b/src/gFetch.ts index ce32b58..0a71647 100644 --- a/src/gFetch.ts +++ b/src/gFetch.ts @@ -104,7 +104,8 @@ export class GFetch extends Object { constructor(options: GClientOptions) { super(); - const { path } = options; + const { path, headers } = options; + this.headers = headers; this.path = path; this.fetch = this.fetch.bind(this); } @@ -128,7 +129,7 @@ export class GFetch extends Object { const res = await fetch(this.path, { method: "POST", credentials: "include", - headers: { "Content-Type": "application/json", ...headers }, + headers: { "Content-Type": "application/json", ...this.headers }, body: JSON.stringify(newQueries), }); From 8bbc54b77f4c1b60b731f4ec12140c170ddb19db Mon Sep 17 00:00:00 2001 From: Tony <454794+tonyrewin@users.noreply.github.com> Date: Thu, 18 Nov 2021 08:39:41 +0300 Subject: [PATCH 3/4] Update gFetch.ts --- src/gFetch.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gFetch.ts b/src/gFetch.ts index 0a71647..2923220 100644 --- a/src/gFetch.ts +++ b/src/gFetch.ts @@ -84,6 +84,7 @@ type gFetchProperties = { export type GClientOptions = { path?: string; + headers?: string; }; export type GReturn = { From 2534a8c1d820d099b90ec7e98e62365bf12b7143 Mon Sep 17 00:00:00 2001 From: Tony <454794+tonyrewin@users.noreply.github.com> Date: Thu, 18 Nov 2021 08:40:58 +0300 Subject: [PATCH 4/4] fix GFetchOptions type --- src/gFetch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gFetch.ts b/src/gFetch.ts index 2923220..89f5c50 100644 --- a/src/gFetch.ts +++ b/src/gFetch.ts @@ -84,7 +84,7 @@ type gFetchProperties = { export type GClientOptions = { path?: string; - headers?: string; + headers?: { [key: string]?: string }; }; export type GReturn = {