Merge pull request #1102 from nelup20/feature/946-fix_prepend_after_interpolation_and_add_to_cli

feat(#946): Fix PR #1070 - Add feature to CLI & prepend after interpolation
This commit is contained in:
Anoop M D 2023-12-01 14:05:38 +05:30 committed by GitHub
commit d23bd85cc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 21 deletions

2
package-lock.json generated
View File

@ -30182,4 +30182,4 @@
}
}
}
}
}

View File

@ -17,6 +17,8 @@ const { SocksProxyAgent } = require('socks-proxy-agent');
const { makeAxiosInstance } = require('../utils/axios-instance');
const { shouldUseProxy, PatchedHttpsProxyAgent } = require('../utils/proxy-util');
const protocolRegex = /([a-zA-Z]{2,20}:\/\/)(.*)/;
const runSingleRequest = async function (
filename,
bruJson,
@ -81,6 +83,10 @@ const runSingleRequest = async function (
// interpolate variables inside request
interpolateVars(request, envVariables, collectionVariables, processEnvVars);
if (!protocolRegex.test(request.url)) {
request.url = `http://${request.url}`;
}
const options = getOptions();
const insecure = get(options, 'insecure', false);
const httpsAgentRequestFields = {};

View File

@ -72,6 +72,8 @@ const getEnvVars = (environment = {}) => {
};
};
const protocolRegex = /([a-zA-Z]{2,20}:\/\/)(.*)/;
const configureRequest = async (
collectionUid,
request,
@ -80,6 +82,10 @@ const configureRequest = async (
processEnvVars,
collectionPath
) => {
if (!protocolRegex.test(request.url)) {
request.url = `http://${request.url}`;
}
const httpsAgentRequestFields = {};
if (!preferencesUtil.shouldVerifyTls()) {
httpsAgentRequestFields['rejectUnauthorized'] = false;
@ -932,3 +938,4 @@ const registerNetworkIpc = (mainWindow) => {
};
module.exports = registerNetworkIpc;
module.exports.configureRequest = configureRequest;

View File

@ -70,18 +70,11 @@ const setAuthHeaders = (axiosRequest, request, collectionRoot) => {
return axiosRequest;
};
const protocolRegex = /([a-zA-Z]{2,20}:\/\/)(.*)/;
const prepareRequest = (request, collectionRoot) => {
const headers = {};
let contentTypeDefined = false;
let url = request.url;
// Temporarily disabling this as this fails when url has vars Ex: {{baseUrl}}/api
// if (!protocolRegex.test(url)) {
// url = `http://${url}`;
// }
// collection headers
each(get(collectionRoot, 'request.headers', []), (h) => {
if (h.enabled) {

View File

@ -0,0 +1,15 @@
const { configureRequest } = require('../../src/ipc/network/index');
describe('index: configureRequest', () => {
it("Should add 'http://' to the URL if no protocol is specified", async () => {
const request = { method: 'GET', url: 'test-domain', body: {} };
await configureRequest(null, request, null, null, null, null);
expect(request.url).toEqual('http://test-domain');
});
it("Should NOT add 'http://' to the URL if a protocol is specified", async () => {
const request = { method: 'GET', url: 'ftp://test-domain', body: {} };
await configureRequest(null, request, null, null, null, null);
expect(request.url).toEqual('ftp://test-domain');
});
});

View File

@ -1,13 +0,0 @@
const prepareRequest = require('../../src/ipc/network/prepare-request');
describe('prepare-request: prepareRequest', () => {
it("Should add 'http://' to the URL if no protocol is specified", () => {
const request = prepareRequest({ method: 'GET', url: 'test', body: {} });
expect(request.url).toEqual('http://test');
});
it("Should NOT add 'http://' to the URL if a protocol is specified", () => {
const request = prepareRequest({ method: 'GET', url: 'ftp://test', body: {} });
expect(request.url).toEqual('ftp://test');
});
});