From dcf34ea92ccc65c705ff9ca2bff6c2202e7c80df Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Wed, 14 Jul 2021 15:36:15 -0400 Subject: [PATCH] feat: pass headers to the ran request --- helpers/network.ts | 8 +++++++- helpers/utils/EffectiveURL.ts | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/helpers/network.ts b/helpers/network.ts index 5d5801f85..2a43d1c0e 100644 --- a/helpers/network.ts +++ b/helpers/network.ts @@ -1,3 +1,4 @@ +import { AxiosRequestConfig } from "axios" import { BehaviorSubject, Observable } from "rxjs" import AxiosStrategy, { cancelRunningAxiosRequest, @@ -20,7 +21,7 @@ export const cancelRunningRequest = () => { const isExtensionsAllowed = () => settingsStore.value.EXTENSIONS_ENABLED -const runAppropriateStrategy = (req: any) => { +const runAppropriateStrategy = (req: AxiosRequestConfig) => { if (isExtensionsAllowed() && hasExtensionInstalled()) { return ExtensionStrategy(req) } @@ -52,10 +53,15 @@ export function createRESTNetworkRequestStream( ): Observable { const response = new BehaviorSubject({ type: "loading" }) + const headers = req.effectiveFinalHeaders.reduce((acc, { key, value }) => { + return Object.assign(acc, { [key]: value }) + }, {}) + const timeStart = Date.now() runAppropriateStrategy({ url: req.effectiveFinalURL, + headers, }).then((res: any) => { const timeEnd = Date.now() diff --git a/helpers/utils/EffectiveURL.ts b/helpers/utils/EffectiveURL.ts index 23089b769..aa1b8ef83 100644 --- a/helpers/utils/EffectiveURL.ts +++ b/helpers/utils/EffectiveURL.ts @@ -10,6 +10,7 @@ export interface EffectiveHoppRESTRequest extends HoppRESTRequest { * This contains path, params and environment variables all applied to it */ effectiveFinalURL: string + effectiveFinalHeaders: { key: string; value: string }[] } /** @@ -31,6 +32,11 @@ export function getEffectiveRESTRequestStream( return { ...request, effectiveFinalURL: request.endpoint, + effectiveFinalHeaders: request.headers.filter( + (x) => + x.key !== "" && // Remove empty keys + x.active // Only active + ), } }) )