mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-22 16:03:39 +01:00
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:
commit
d23bd85cc6
2
package-lock.json
generated
2
package-lock.json
generated
@ -30182,4 +30182,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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 = {};
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
15
packages/bruno-electron/tests/network/index.spec.js
Normal file
15
packages/bruno-electron/tests/network/index.spec.js
Normal 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');
|
||||
});
|
||||
});
|
@ -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');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user