Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

feat: pass headers to the ran request

Andrew Bastindcf34ea92ccc
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<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()
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
+ ),
}
})
)