Skip to content

Commit

Permalink
Make pre-request scripts operate on completely prepared request
Browse files Browse the repository at this point in the history
The pre-request script phase is now executed after configureRequest. That means the
'req' object in pre-request script has access to more data, including evaluated variables, set authorization headers, etc.

fixes usebruno#2249
  • Loading branch information
Mateusz Pietryga committed May 6, 2024
1 parent 392cc80 commit 6459448
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions packages/bruno-electron/src/ipc/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,25 +449,26 @@ const registerNetworkIpc = (mainWindow) => {
request.signal = controller.signal;
saveCancelToken(cancelTokenUid, controller);

await runPreRequest(
interpolateVars(request, envVars, collection.collectionVariables, processEnvVars);
const axiosInstance = await configureRequest(
collectionUid,
request,
requestUid,
envVars,
collectionPath,
collectionRoot,
collectionUid,
collectionVariables,
processEnvVars,
scriptingConfig
collectionPath
);

const axiosInstance = await configureRequest(
collectionUid,
await runPreRequest(
request,
requestUid,
envVars,
collectionPath,
collectionRoot,
collectionUid,
collectionVariables,
processEnvVars,
collectionPath
scriptingConfig
);

mainWindow.webContents.send('main:run-request-event', {
Expand Down Expand Up @@ -642,6 +643,16 @@ const registerNetworkIpc = (mainWindow) => {
const brunoConfig = getBrunoConfig(collectionUid);
const scriptingConfig = get(brunoConfig, 'scripts', {});

interpolateVars(request, envVars, collection.collectionVariables, processEnvVars);
const axiosInstance = await configureRequest(
collection.uid,
request,
envVars,
collection.collectionVariables,
processEnvVars,
collectionPath
);

await runPreRequest(
request,
requestUid,
Expand All @@ -654,16 +665,6 @@ const registerNetworkIpc = (mainWindow) => {
scriptingConfig
);

interpolateVars(request, envVars, collection.collectionVariables, processEnvVars);
const axiosInstance = await configureRequest(
collection.uid,
request,
envVars,
collection.collectionVariables,
processEnvVars,
collectionPath
);

try {
response = await axiosInstance(request);
} catch (error) {
Expand All @@ -674,9 +675,6 @@ const registerNetworkIpc = (mainWindow) => {
}
}

const { data } = parseDataFromResponse(response);
response.data = data;

await runPostResponse(
request,
response,
Expand Down Expand Up @@ -747,6 +745,16 @@ const registerNetworkIpc = (mainWindow) => {
const brunoConfig = getBrunoConfig(collection.uid);
const scriptingConfig = get(brunoConfig, 'scripts', {});

interpolateVars(preparedRequest, envVars, collection.collectionVariables, processEnvVars);
const axiosInstance = await configureRequest(
collection.uid,
preparedRequest,
envVars,
collection.collectionVariables,
processEnvVars,
collectionPath
);

await runPreRequest(
request,
requestUid,
Expand All @@ -759,15 +767,6 @@ const registerNetworkIpc = (mainWindow) => {
scriptingConfig
);

interpolateVars(preparedRequest, envVars, collection.collectionVariables, processEnvVars);
const axiosInstance = await configureRequest(
collection.uid,
preparedRequest,
envVars,
collection.collectionVariables,
processEnvVars,
collectionPath
);
const response = await axiosInstance(preparedRequest);

await runPostResponse(
Expand Down Expand Up @@ -882,6 +881,15 @@ const registerNetworkIpc = (mainWindow) => {
const processEnvVars = getProcessEnvVars(collectionUid);

try {
const axiosInstance = await configureRequest(
collectionUid,
request,
envVars,
collectionVariables,
processEnvVars,
collectionPath
);

const preRequestScriptResult = await runPreRequest(
request,
requestUid,
Expand Down Expand Up @@ -913,14 +921,6 @@ const registerNetworkIpc = (mainWindow) => {
});

request.signal = abortController.signal;
const axiosInstance = await configureRequest(
collectionUid,
request,
envVars,
collectionVariables,
processEnvVars,
collectionPath
);

timeStart = Date.now();
let response, responseTime;
Expand Down

0 comments on commit 6459448

Please sign in to comment.