fix(#148) : fixed issue where form url encoded params were not being interpolated

This commit is contained in:
Anoop M D 2023-04-27 19:25:52 +05:30
parent 45ca5ded96
commit 49b0f3a322
6 changed files with 32 additions and 4 deletions

View File

@ -42,6 +42,15 @@ const interpolateVars = (request, envVars = {}, collectionVariables ={}) => {
request.data = interpolate(request.data);
}
}
} else if(request.headers["content-type"] === "application/x-www-form-urlencoded") {
if(typeof request.data === "object") {
try {
let parsed = JSON.stringify(request.data);
parsed = interpolate(parsed);
request.data = JSON.parse(parsed);
} catch (err) {
}
}
} else {
request.data = interpolate(request.data);
}

View File

@ -1,5 +1,4 @@
const { get, each, filter } = require('lodash');
const qs = require('qs');
const prepareRequest = (request) => {
const headers = {};
@ -41,7 +40,7 @@ const prepareRequest = (request) => {
const params = {};
const enabledParams = filter(request.body.formUrlEncoded, (p) => p.enabled);
each(enabledParams, (p) => (params[p.name] = p.value));
axiosRequest.data = qs.stringify(params);
axiosRequest.data = params;
}
if (request.body.mode === 'multipartForm') {

View File

@ -1,3 +1,4 @@
const qs = require('qs');
const chalk = require('chalk');
const { forOwn, each, extend, get } = require('lodash');
const FormData = require('form-data');
@ -39,6 +40,11 @@ const runSingleRequest = async function (filename, bruJson, collectionPath, coll
// interpolate variables inside request
interpolateVars(request, envVariables, collectionVariables);
// stringify the request url encoded params
if(request.headers['content-type'] = 'application/x-www-form-urlencoded') {
request.data = qs.stringify(request.data);
}
// run request
const response = await axios(request);

View File

@ -1,3 +1,4 @@
const qs = require('qs');
const axios = require('axios');
const Mustache = require('mustache');
const FormData = require('form-data');
@ -124,6 +125,11 @@ const registerNetworkIpc = (mainWindow, watcher, lastOpenedCollections) => {
interpolateVars(request, envVars, collectionVariables);
// stringify the request url encoded params
if(request.headers['content-type'] = 'application/x-www-form-urlencoded') {
request.data = qs.stringify(request.data);
}
// todo:
// i have no clue why electron can't send the request object
// without safeParseJSON(safeStringifyJSON(request.data))

View File

@ -42,6 +42,15 @@ const interpolateVars = (request, envVars = {}, collectionVariables ={}) => {
request.data = interpolate(request.data);
}
}
} else if(request.headers["content-type"] === "application/x-www-form-urlencoded") {
if(typeof request.data === "object") {
try {
let parsed = JSON.stringify(request.data);
parsed = interpolate(parsed);
request.data = JSON.parse(parsed);
} catch (err) {
}
}
} else {
request.data = interpolate(request.data);
}

View File

@ -1,5 +1,4 @@
const { get, each, filter } = require('lodash');
const qs = require('qs');
const prepareRequest = (request) => {
const headers = {};
@ -39,7 +38,7 @@ const prepareRequest = (request) => {
const params = {};
const enabledParams = filter(request.body.formUrlEncoded, (p) => p.enabled);
each(enabledParams, (p) => (params[p.name] = p.value));
axiosRequest.data = qs.stringify(params);
axiosRequest.data = params;
}
if (request.body.mode === 'multipartForm') {