@requestly/requestly-proxy 1.1.4 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/proxy-middleware/constants.js +1 -0
- package/dist/components/proxy-middleware/helpers/http_helpers.d.ts +1 -0
- package/dist/components/proxy-middleware/helpers/http_helpers.js +11 -1
- package/dist/components/proxy-middleware/rule_action_processor/index.js +1 -1
- package/dist/components/proxy-middleware/rule_action_processor/processors/modify_response_processor.d.ts +2 -2
- package/dist/components/proxy-middleware/rule_action_processor/processors/modify_response_processor.js +8 -7
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getContentType = exports.bodyParser = void 0;
|
|
6
|
+
exports.parseJsonBody = exports.getContentType = exports.bodyParser = void 0;
|
|
7
7
|
const charset_1 = __importDefault(require("charset"));
|
|
8
8
|
const mime_types_1 = __importDefault(require("mime-types"));
|
|
9
9
|
const bodyParser = (contentTypeHeader, buffer) => {
|
|
@@ -45,3 +45,13 @@ const getContentType = (contentTypeHeader) => {
|
|
|
45
45
|
return contentType;
|
|
46
46
|
};
|
|
47
47
|
exports.getContentType = getContentType;
|
|
48
|
+
const parseJsonBody = (data) => {
|
|
49
|
+
try {
|
|
50
|
+
return JSON.parse(data);
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
/* Body is still buffer array */
|
|
54
|
+
}
|
|
55
|
+
return data;
|
|
56
|
+
};
|
|
57
|
+
exports.parseJsonBody = parseJsonBody;
|
|
@@ -90,7 +90,7 @@ class RuleActionProcessor {
|
|
|
90
90
|
action_result = (0, modify_request_processor_1.default)(rule_action, ctx);
|
|
91
91
|
break;
|
|
92
92
|
case constants_1.RULE_ACTION.MODIFY_RESPONSE:
|
|
93
|
-
action_result = (0, modify_response_processor_1.default)(rule_action, ctx);
|
|
93
|
+
action_result = yield (0, modify_response_processor_1.default)(rule_action, ctx);
|
|
94
94
|
break;
|
|
95
95
|
case constants_1.RULE_ACTION.INSERT:
|
|
96
96
|
action_result = (0, insert_processor_1.default)(rule_action, ctx);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default process_modify_response_action;
|
|
2
|
-
declare function process_modify_response_action(action: any, ctx: any): {
|
|
2
|
+
declare function process_modify_response_action(action: any, ctx: any): Promise<{
|
|
3
3
|
action: any;
|
|
4
4
|
success: boolean;
|
|
5
5
|
post_process_data: any;
|
|
6
|
-
}
|
|
6
|
+
}>;
|
|
@@ -17,15 +17,16 @@ const requestly_core_1 = require("@requestly/requestly-core");
|
|
|
17
17
|
const proxy_ctx_helper_1 = require("../../helpers/proxy_ctx_helper");
|
|
18
18
|
const utils_1 = require("../utils");
|
|
19
19
|
const fs_1 = __importDefault(require("fs"));
|
|
20
|
+
const http_helpers_1 = require("../../helpers/http_helpers");
|
|
20
21
|
const { types } = require("util");
|
|
21
|
-
const process_modify_response_action = (action, ctx) => {
|
|
22
|
+
const process_modify_response_action = (action, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
23
|
const allowed_handlers = [proxy_1.PROXY_HANDLER_TYPE.ON_RESPONSE_END];
|
|
23
24
|
if (!allowed_handlers.includes(ctx.currentHandler)) {
|
|
24
25
|
return (0, utils_1.build_action_processor_response)(action, false);
|
|
25
26
|
}
|
|
26
27
|
if (action.responseType &&
|
|
27
28
|
action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.CODE) {
|
|
28
|
-
modify_response_using_code(action, ctx);
|
|
29
|
+
yield modify_response_using_code(action, ctx);
|
|
29
30
|
return (0, utils_1.build_action_processor_response)(action, true);
|
|
30
31
|
}
|
|
31
32
|
else if (action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.LOCAL_FILE) {
|
|
@@ -36,7 +37,7 @@ const process_modify_response_action = (action, ctx) => {
|
|
|
36
37
|
modify_response(ctx, action.response, action.statusCode);
|
|
37
38
|
return (0, utils_1.build_action_processor_response)(action, true);
|
|
38
39
|
}
|
|
39
|
-
};
|
|
40
|
+
});
|
|
40
41
|
const modify_response = (ctx, new_resp, status_code) => {
|
|
41
42
|
ctx.rq_response_body = new_resp;
|
|
42
43
|
ctx.rq_response_status_code = status_code;
|
|
@@ -52,6 +53,7 @@ const modify_response_using_local = (action, ctx) => {
|
|
|
52
53
|
}
|
|
53
54
|
};
|
|
54
55
|
const modify_response_using_code = (action, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
var _a, _b;
|
|
55
57
|
let userFunction = null;
|
|
56
58
|
try {
|
|
57
59
|
userFunction = requestly_core_1.UTILS.GET_FUNCTION_FROM_STRING(action.response);
|
|
@@ -78,20 +80,19 @@ const modify_response_using_code = (action, ctx) => __awaiter(void 0, void 0, vo
|
|
|
78
80
|
url: (0, proxy_ctx_helper_1.get_request_url)(ctx),
|
|
79
81
|
responseType: ctx.serverToProxyResponse.headers["content-type"],
|
|
80
82
|
requestHeaders: ctx.clientToProxyRequest.headers,
|
|
81
|
-
requestData: null,
|
|
83
|
+
requestData: (0, http_helpers_1.parseJsonBody)((_b = (_a = ctx.rq) === null || _a === void 0 ? void 0 : _a.final_request) === null || _b === void 0 ? void 0 : _b.body) || null,
|
|
82
84
|
};
|
|
83
85
|
try {
|
|
84
86
|
args.responseJSON = JSON.parse(args.response);
|
|
85
87
|
}
|
|
86
|
-
catch (
|
|
88
|
+
catch (_c) {
|
|
87
89
|
/*Do nothing -- could not parse body as JSON */
|
|
88
90
|
}
|
|
89
91
|
finalResponse = userFunction(args);
|
|
90
92
|
if (types.isPromise(finalResponse)) {
|
|
91
93
|
finalResponse = yield finalResponse;
|
|
92
94
|
}
|
|
93
|
-
|
|
94
|
-
if (typeof finalResponse === "object" && isResponseJSON) {
|
|
95
|
+
if (typeof finalResponse === "object") {
|
|
95
96
|
finalResponse = JSON.stringify(finalResponse);
|
|
96
97
|
}
|
|
97
98
|
if (finalResponse && typeof finalResponse === "string") {
|