Skip to content

Commit 38c5aa9

Browse files
authored
Merge pull request #9 from requestly/fix-async-programmatic-modify
fix: async function for programmatically changing response
2 parents b9010e5 + fa04d25 commit 38c5aa9

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/components/proxy-middleware/rule_action_processor/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class RuleActionProcessor {
8888
action_result = process_modify_request_action(rule_action, ctx);
8989
break;
9090
case RULE_ACTION.MODIFY_RESPONSE:
91-
action_result = process_modify_response_action(rule_action, ctx);
91+
action_result = await process_modify_response_action(rule_action, ctx);
9292
break;
9393
case RULE_ACTION.INSERT:
9494
action_result = process_insert_action(rule_action, ctx);

src/components/proxy-middleware/rule_action_processor/processors/modify_response_processor.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { build_action_processor_response } from "../utils";
99
import fs from "fs";
1010
const { types } = require("util");
1111

12-
const process_modify_response_action = (action, ctx) => {
12+
const process_modify_response_action = async (action, ctx) => {
1313
const allowed_handlers = [PROXY_HANDLER_TYPE.ON_RESPONSE_END];
1414

1515
if (!allowed_handlers.includes(ctx.currentHandler)) {
@@ -20,7 +20,7 @@ const process_modify_response_action = (action, ctx) => {
2020
action.responseType &&
2121
action.responseType === GLOBAL_CONSTANTS.RESPONSE_BODY_TYPES.CODE
2222
) {
23-
modify_response_using_code(action, ctx);
23+
await modify_response_using_code(action, ctx);
2424
return build_action_processor_response(action, true);
2525
} else if (
2626
action.responseType === GLOBAL_CONSTANTS.RESPONSE_BODY_TYPES.LOCAL_FILE
@@ -98,9 +98,7 @@ const modify_response_using_code = async (action, ctx) => {
9898
finalResponse = await finalResponse;
9999
}
100100

101-
const isResponseJSON =
102-
args.responseType && args.responseType.includes("application/json");
103-
if (typeof finalResponse === "object" && isResponseJSON) {
101+
if (typeof finalResponse === "object") {
104102
finalResponse = JSON.stringify(finalResponse);
105103
}
106104

0 commit comments

Comments
 (0)