feat: pass headers to the ran request

This commit is contained in:
Andrew Bastin
2021-07-14 15:36:15 -04:00
parent 9ece8adda8
commit dcf34ea92c
2 changed files with 13 additions and 1 deletions

View File

@@ -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<HoppRESTResponse> {
const response = new BehaviorSubject<HoppRESTResponse>({ 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()

View File

@@ -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
),
}
})
)