fix: add body env resolution for har generation

This commit is contained in:
Andrew Bastin
2022-01-03 11:17:02 +05:30
parent c3aedac77e
commit 67baf74edc
2 changed files with 42 additions and 6 deletions

View File

@@ -1,6 +1,10 @@
import { combineLatest, Observable } from "rxjs"
import { map } from "rxjs/operators"
import { FormDataKeyValue, HoppRESTRequest } from "@hoppscotch/data"
import {
FormDataKeyValue,
HoppRESTReqBody,
HoppRESTRequest,
} from "@hoppscotch/data"
import { parseTemplateString, parseBodyEnvVariables } from "../templating"
import { Environment, getGlobalVariables } from "~/newstore/environments"
@@ -16,6 +20,36 @@ export interface EffectiveHoppRESTRequest extends HoppRESTRequest {
effectiveFinalBody: FormData | string | null
}
// Resolves environment variables in the body
export const resolvesEnvsInBody = (
body: HoppRESTReqBody,
env: Environment
): HoppRESTReqBody => {
if (!body.contentType) return body
if (body.contentType === "multipart/form-data") {
return {
contentType: "multipart/form-data",
body: body.body.map(
(entry) =>
<FormDataKeyValue>{
active: entry.active,
isFile: entry.isFile,
key: parseTemplateString(entry.key, env.variables),
value: entry.isFile
? entry.value
: parseTemplateString(entry.value, env.variables),
}
),
}
} else {
return {
contentType: body.contentType,
body: parseTemplateString(body.body, env.variables),
}
}
}
function getFinalBodyFromRequest(
request: HoppRESTRequest,
env: Environment