feat: pass headers to the ran request
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { AxiosRequestConfig } from "axios"
|
||||||
import { BehaviorSubject, Observable } from "rxjs"
|
import { BehaviorSubject, Observable } from "rxjs"
|
||||||
import AxiosStrategy, {
|
import AxiosStrategy, {
|
||||||
cancelRunningAxiosRequest,
|
cancelRunningAxiosRequest,
|
||||||
@@ -20,7 +21,7 @@ export const cancelRunningRequest = () => {
|
|||||||
|
|
||||||
const isExtensionsAllowed = () => settingsStore.value.EXTENSIONS_ENABLED
|
const isExtensionsAllowed = () => settingsStore.value.EXTENSIONS_ENABLED
|
||||||
|
|
||||||
const runAppropriateStrategy = (req: any) => {
|
const runAppropriateStrategy = (req: AxiosRequestConfig) => {
|
||||||
if (isExtensionsAllowed() && hasExtensionInstalled()) {
|
if (isExtensionsAllowed() && hasExtensionInstalled()) {
|
||||||
return ExtensionStrategy(req)
|
return ExtensionStrategy(req)
|
||||||
}
|
}
|
||||||
@@ -52,10 +53,15 @@ export function createRESTNetworkRequestStream(
|
|||||||
): Observable<HoppRESTResponse> {
|
): Observable<HoppRESTResponse> {
|
||||||
const response = new BehaviorSubject<HoppRESTResponse>({ type: "loading" })
|
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()
|
const timeStart = Date.now()
|
||||||
|
|
||||||
runAppropriateStrategy({
|
runAppropriateStrategy({
|
||||||
url: req.effectiveFinalURL,
|
url: req.effectiveFinalURL,
|
||||||
|
headers,
|
||||||
}).then((res: any) => {
|
}).then((res: any) => {
|
||||||
const timeEnd = Date.now()
|
const timeEnd = Date.now()
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export interface EffectiveHoppRESTRequest extends HoppRESTRequest {
|
|||||||
* This contains path, params and environment variables all applied to it
|
* This contains path, params and environment variables all applied to it
|
||||||
*/
|
*/
|
||||||
effectiveFinalURL: string
|
effectiveFinalURL: string
|
||||||
|
effectiveFinalHeaders: { key: string; value: string }[]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,6 +32,11 @@ export function getEffectiveRESTRequestStream(
|
|||||||
return {
|
return {
|
||||||
...request,
|
...request,
|
||||||
effectiveFinalURL: request.endpoint,
|
effectiveFinalURL: request.endpoint,
|
||||||
|
effectiveFinalHeaders: request.headers.filter(
|
||||||
|
(x) =>
|
||||||
|
x.key !== "" && // Remove empty keys
|
||||||
|
x.active // Only active
|
||||||
|
),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user