Skip to content

Commit e8904df

Browse files
committed
chore: Version bump v1.1.18
1 parent 8f972be commit e8904df

File tree

3 files changed

+183
-475
lines changed

3 files changed

+183
-475
lines changed

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,29 @@ const capture_console_logs_1 = __importDefault(require("capture-console-logs"));
2222
const utils_2 = require("../../../../utils");
2323
const { types } = require("util");
2424
const process_modify_response_action = (action, ctx) => __awaiter(void 0, void 0, void 0, function* () {
25-
const allowed_handlers = [proxy_1.PROXY_HANDLER_TYPE.ON_RESPONSE_END, proxy_1.PROXY_HANDLER_TYPE.ON_ERROR];
25+
const allowed_handlers = [proxy_1.PROXY_HANDLER_TYPE.ON_REQUEST, proxy_1.PROXY_HANDLER_TYPE.ON_RESPONSE_END, proxy_1.PROXY_HANDLER_TYPE.ON_ERROR];
2626
if (!allowed_handlers.includes(ctx.currentHandler)) {
2727
return (0, utils_1.build_action_processor_response)(action, false);
2828
}
29+
if (ctx.currentHandler === proxy_1.PROXY_HANDLER_TYPE.ON_REQUEST) {
30+
if (action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.STATIC
31+
&& action.serveWithoutRequest) {
32+
let contentType, finalBody;
33+
try {
34+
finalBody = JSON.parse(action.response);
35+
contentType = "application/json";
36+
}
37+
catch (_a) {
38+
contentType = "text/plain";
39+
finalBody = action.response;
40+
}
41+
const status = action.statusCode || 200;
42+
const finalHeaders = { "Content-Type": contentType };
43+
modify_response(ctx, finalBody, status);
44+
return (0, utils_1.build_action_processor_response)(action, true, (0, utils_1.build_post_process_data)(status, finalHeaders, finalBody));
45+
}
46+
return (0, utils_1.build_action_processor_response)(action, false);
47+
}
2948
if (action.responseType &&
3049
action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.CODE) {
3150
yield modify_response_using_code(action, ctx);
@@ -55,7 +74,7 @@ const modify_response_using_local = (action, ctx) => {
5574
}
5675
};
5776
const modify_response_using_code = (action, ctx) => __awaiter(void 0, void 0, void 0, function* () {
58-
var _a, _b, _c, _d;
77+
var _b, _c, _d, _e;
5978
let userFunction = null;
6079
try {
6180
userFunction = (0, utils_2.getFunctionFromString)(action.response);
@@ -80,14 +99,14 @@ const modify_response_using_code = (action, ctx) => __awaiter(void 0, void 0, vo
8099
: null,
81100
response: ctx === null || ctx === void 0 ? void 0 : ctx.rq_response_body,
82101
url: (0, proxy_ctx_helper_1.get_request_url)(ctx),
83-
responseType: (_b = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.serverToProxyResponse) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b["content-type"],
102+
responseType: (_c = (_b = ctx === null || ctx === void 0 ? void 0 : ctx.serverToProxyResponse) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c["content-type"],
84103
requestHeaders: ctx.clientToProxyRequest.headers,
85-
requestData: (0, http_helpers_1.parseJsonBody)((_d = (_c = ctx.rq) === null || _c === void 0 ? void 0 : _c.final_request) === null || _d === void 0 ? void 0 : _d.body) || null,
104+
requestData: (0, http_helpers_1.parseJsonBody)((_e = (_d = ctx.rq) === null || _d === void 0 ? void 0 : _d.final_request) === null || _e === void 0 ? void 0 : _e.body) || null,
86105
};
87106
try {
88107
args.responseJSON = JSON.parse(args.response);
89108
}
90-
catch (_e) {
109+
catch (_f) {
91110
/*Do nothing -- could not parse body as JSON */
92111
}
93112
const consoleCapture = new capture_console_logs_1.default();

0 commit comments

Comments
 (0)