@requestly/requestly-proxy 1.3.2 → 1.3.3
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.d.ts +8 -8
- package/dist/components/proxy-middleware/helpers/ctx_rq_namespace.js +4 -4
- package/dist/components/proxy-middleware/helpers/harObectCreator.js +7 -7
- package/dist/components/proxy-middleware/helpers/proxy_ctx_helper.js +6 -9
- package/dist/components/proxy-middleware/helpers/rule_processor_helper.js +2 -2
- package/dist/components/proxy-middleware/index.d.ts +5 -5
- package/dist/components/proxy-middleware/index.js +97 -114
- package/dist/components/proxy-middleware/middlewares/amiusing_middleware.js +2 -11
- package/dist/components/proxy-middleware/middlewares/logger_middleware.js +12 -16
- package/dist/components/proxy-middleware/middlewares/rules_middleware.js +20 -26
- package/dist/components/proxy-middleware/middlewares/ssl_cert_middleware.js +2 -11
- package/dist/components/proxy-middleware/rule_action_processor/handle_mixed_response.js +3 -12
- package/dist/components/proxy-middleware/rule_action_processor/index.js +9 -18
- package/dist/components/proxy-middleware/rule_action_processor/processors/block_processor.js +2 -11
- package/dist/components/proxy-middleware/rule_action_processor/processors/delay_processor.js +5 -14
- package/dist/components/proxy-middleware/rule_action_processor/processors/modify_request_processor.js +3 -12
- package/dist/components/proxy-middleware/rule_action_processor/processors/modify_response_processor.js +11 -20
- package/dist/components/proxy-middleware/rule_action_processor/processors/redirect_processor.js +3 -12
- package/dist/components/ssl-proxying/ssl-proxying-manager.js +5 -0
- package/dist/lib/proxy/index.d.ts +2 -2
- package/dist/lib/proxy/index.js +31 -1
- package/dist/lib/proxy/lib/middleware/gunzip.js +2 -1
- package/dist/lib/proxy/lib/middleware/wildcard.js +2 -1
- package/dist/lib/proxy/lib/proxy.d.ts +5 -5
- package/dist/test.js +5 -14
- package/dist/utils/helpers/rules-helper.js +10 -19
- package/dist/utils/index.js +31 -42
- package/package.json +12 -4
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const fs = require("fs");
|
|
13
4
|
class SslCertMiddleware {
|
|
14
5
|
constructor(is_active, rootCertPath) {
|
|
15
|
-
this.on_request = (ctx) =>
|
|
6
|
+
this.on_request = async (ctx) => {
|
|
16
7
|
if (!this.is_active) {
|
|
17
8
|
return true;
|
|
18
9
|
}
|
|
@@ -25,7 +16,7 @@ class SslCertMiddleware {
|
|
|
25
16
|
const certificateString = fs.readFileSync(this.rootCertPath);
|
|
26
17
|
ctx.proxyToClientResponse.end(certificateString);
|
|
27
18
|
}
|
|
28
|
-
}
|
|
19
|
+
};
|
|
29
20
|
this.is_active = is_active;
|
|
30
21
|
this.rootCertPath = rootCertPath;
|
|
31
22
|
}
|
|
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
27
|
};
|
|
@@ -39,7 +30,7 @@ const axios = require("axios");
|
|
|
39
30
|
const parser = require("ua-parser-js");
|
|
40
31
|
const fs_1 = __importDefault(require("fs"));
|
|
41
32
|
const Sentry = __importStar(require("@sentry/browser"));
|
|
42
|
-
const handleMixedResponse = (ctx, destinationUrl) =>
|
|
33
|
+
const handleMixedResponse = async (ctx, destinationUrl) => {
|
|
43
34
|
var _a, _b, _c;
|
|
44
35
|
// Handling mixed response from safari
|
|
45
36
|
let user_agent_str = null;
|
|
@@ -50,7 +41,7 @@ const handleMixedResponse = (ctx, destinationUrl) => __awaiter(void 0, void 0, v
|
|
|
50
41
|
if (user_agent === "Safari" ||
|
|
51
42
|
!LOCAL_DOMAINS.some((domain) => destinationUrl.includes(domain))) {
|
|
52
43
|
try {
|
|
53
|
-
const resp =
|
|
44
|
+
const resp = await axios.get(destinationUrl, {
|
|
54
45
|
headers: {
|
|
55
46
|
"Cache-Control": "no-cache",
|
|
56
47
|
},
|
|
@@ -106,5 +97,5 @@ const handleMixedResponse = (ctx, destinationUrl) => __awaiter(void 0, void 0, v
|
|
|
106
97
|
}
|
|
107
98
|
}
|
|
108
99
|
return { status: false };
|
|
109
|
-
}
|
|
100
|
+
};
|
|
110
101
|
exports.default = handleMixedResponse;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -27,18 +18,18 @@ class RuleActionProcessor {
|
|
|
27
18
|
/*
|
|
28
19
|
@return: Whether to continue with the proxy callback. & of all the continue_request from actions
|
|
29
20
|
*/
|
|
30
|
-
this.process_actions = (rule_actions, ctx) =>
|
|
21
|
+
this.process_actions = async (rule_actions, ctx) => {
|
|
31
22
|
/*
|
|
32
23
|
action_result_objs = [{action: {}, result: {}}}]
|
|
33
24
|
*/
|
|
34
|
-
const action_result_objs =
|
|
35
|
-
let action_result_obj =
|
|
25
|
+
const action_result_objs = await Promise.all(rule_actions.map(async (action) => {
|
|
26
|
+
let action_result_obj = await this.process_action(action, ctx);
|
|
36
27
|
return action_result_obj;
|
|
37
|
-
}))
|
|
28
|
+
}));
|
|
38
29
|
let continue_request = true;
|
|
39
30
|
continue_request = this.post_process_actions(action_result_objs, ctx);
|
|
40
31
|
return { action_result_objs, continue_request };
|
|
41
|
-
}
|
|
32
|
+
};
|
|
42
33
|
this.post_process_actions = (action_result_objs, ctx) => {
|
|
43
34
|
let continue_request = true;
|
|
44
35
|
action_result_objs.forEach((action_result) => {
|
|
@@ -66,7 +57,7 @@ class RuleActionProcessor {
|
|
|
66
57
|
/*
|
|
67
58
|
@return: Whether to continue with the proxy callback
|
|
68
59
|
*/
|
|
69
|
-
this.process_action = (rule_action, ctx) =>
|
|
60
|
+
this.process_action = async (rule_action, ctx) => {
|
|
70
61
|
let action_result = (0, utils_1.build_action_processor_response)(rule_action, false);
|
|
71
62
|
if (!rule_action) {
|
|
72
63
|
return action_result;
|
|
@@ -81,7 +72,7 @@ class RuleActionProcessor {
|
|
|
81
72
|
case constants_1.RULE_ACTION.MODIFY_USER_AGENT:
|
|
82
73
|
action_result = (0, modify_user_agent_processor_1.default)(rule_action, ctx);
|
|
83
74
|
case constants_1.RULE_ACTION.DELAY:
|
|
84
|
-
action_result =
|
|
75
|
+
action_result = await (0, delay_processor_1.default)(rule_action, ctx);
|
|
85
76
|
break;
|
|
86
77
|
case constants_1.RULE_ACTION.BLOCK:
|
|
87
78
|
action_result = (0, block_processor_1.default)(rule_action, ctx);
|
|
@@ -90,7 +81,7 @@ class RuleActionProcessor {
|
|
|
90
81
|
action_result = (0, modify_request_processor_1.default)(rule_action, ctx);
|
|
91
82
|
break;
|
|
92
83
|
case constants_1.RULE_ACTION.MODIFY_RESPONSE:
|
|
93
|
-
action_result =
|
|
84
|
+
action_result = await (0, modify_response_processor_1.default)(rule_action, ctx);
|
|
94
85
|
break;
|
|
95
86
|
case constants_1.RULE_ACTION.INSERT:
|
|
96
87
|
action_result = (0, insert_processor_1.default)(rule_action, ctx);
|
|
@@ -98,7 +89,7 @@ class RuleActionProcessor {
|
|
|
98
89
|
break;
|
|
99
90
|
}
|
|
100
91
|
return action_result;
|
|
101
|
-
}
|
|
92
|
+
};
|
|
102
93
|
}
|
|
103
94
|
}
|
|
104
95
|
exports.default = RuleActionProcessor;
|
package/dist/components/proxy-middleware/rule_action_processor/processors/block_processor.js
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const proxy_1 = require("../../../../lib/proxy");
|
|
13
4
|
const utils_1 = require("../utils");
|
|
14
|
-
const process_block_action = (action, ctx) =>
|
|
5
|
+
const process_block_action = async (action, ctx) => {
|
|
15
6
|
const allowed_handlers = [proxy_1.PROXY_HANDLER_TYPE.ON_REQUEST];
|
|
16
7
|
if (!allowed_handlers.includes(ctx.currentHandler)) {
|
|
17
8
|
return (0, utils_1.build_action_processor_response)(action, false);
|
|
18
9
|
}
|
|
19
10
|
return (0, utils_1.build_action_processor_response)(action, true, (0, utils_1.build_post_process_data)(418 /** Move this to temporarily out of coffee (503) if causes issues in someone production use case. // https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/418 */, { "Cache-Control": "no-cache" }, "Access to this URL has been blocked by Requestly"));
|
|
20
|
-
}
|
|
11
|
+
};
|
|
21
12
|
exports.default = process_block_action;
|
package/dist/components/proxy-middleware/rule_action_processor/processors/delay_processor.js
CHANGED
|
@@ -1,29 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const proxy_1 = require("../../../../lib/proxy");
|
|
13
4
|
const utils_1 = require("../utils");
|
|
14
|
-
const resolveAfterDelay = (durationInMs) =>
|
|
5
|
+
const resolveAfterDelay = async (durationInMs) => {
|
|
15
6
|
return new Promise((resolve) => {
|
|
16
7
|
setTimeout(() => {
|
|
17
8
|
resolve("resolved");
|
|
18
9
|
}, durationInMs);
|
|
19
10
|
});
|
|
20
|
-
}
|
|
21
|
-
const process_delay_action = (action, ctx) =>
|
|
11
|
+
};
|
|
12
|
+
const process_delay_action = async (action, ctx) => {
|
|
22
13
|
const allowed_handlers = [proxy_1.PROXY_HANDLER_TYPE.ON_REQUEST];
|
|
23
14
|
if (!allowed_handlers.includes(ctx.currentHandler)) {
|
|
24
15
|
return (0, utils_1.build_action_processor_response)(action, false);
|
|
25
16
|
}
|
|
26
|
-
|
|
17
|
+
await resolveAfterDelay(action.delay);
|
|
27
18
|
return (0, utils_1.build_action_processor_response)(action, true);
|
|
28
|
-
}
|
|
19
|
+
};
|
|
29
20
|
exports.default = process_delay_action;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const proxy_1 = require("../../../../lib/proxy");
|
|
13
4
|
const requestly_core_1 = require("@requestly/requestly-core");
|
|
@@ -33,7 +24,7 @@ const modify_request = (ctx, new_req) => {
|
|
|
33
24
|
if (new_req)
|
|
34
25
|
ctx.rq_request_body = new_req;
|
|
35
26
|
};
|
|
36
|
-
const modify_request_using_code = (action, ctx) =>
|
|
27
|
+
const modify_request_using_code = async (action, ctx) => {
|
|
37
28
|
let userFunction = null;
|
|
38
29
|
try {
|
|
39
30
|
userFunction = (0, utils_2.getFunctionFromString)(action.request);
|
|
@@ -67,7 +58,7 @@ const modify_request_using_code = (action, ctx) => __awaiter(void 0, void 0, voi
|
|
|
67
58
|
catch (_a) {
|
|
68
59
|
/*Do nothing -- could not parse body as JSON */
|
|
69
60
|
}
|
|
70
|
-
finalRequest =
|
|
61
|
+
finalRequest = await (0, utils_2.executeUserFunction)(ctx, userFunction, args);
|
|
71
62
|
if (finalRequest && typeof finalRequest === "string") {
|
|
72
63
|
return modify_request(ctx, finalRequest);
|
|
73
64
|
}
|
|
@@ -79,5 +70,5 @@ const modify_request_using_code = (action, ctx) => __awaiter(void 0, void 0, voi
|
|
|
79
70
|
return modify_request(ctx, "Can't execute Requestly function. Please recheck. Error Code 187. Actual Error: " +
|
|
80
71
|
error.message);
|
|
81
72
|
}
|
|
82
|
-
}
|
|
73
|
+
};
|
|
83
74
|
exports.default = process_modify_request_action;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -20,7 +11,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
20
11
|
const http_helpers_1 = require("../../helpers/http_helpers");
|
|
21
12
|
const utils_2 = require("../../../../utils");
|
|
22
13
|
const constants_1 = require("../../constants");
|
|
23
|
-
const process_modify_response_action = (action, ctx) =>
|
|
14
|
+
const process_modify_response_action = async (action, ctx) => {
|
|
24
15
|
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];
|
|
25
16
|
if (!allowed_handlers.includes(ctx.currentHandler)) {
|
|
26
17
|
return (0, utils_1.build_action_processor_response)(action, false);
|
|
@@ -49,7 +40,7 @@ const process_modify_response_action = (action, ctx) => __awaiter(void 0, void 0
|
|
|
49
40
|
const contentTypeHeader = (0, proxy_ctx_helper_1.getResponseContentTypeHeader)(ctx);
|
|
50
41
|
const contentType = (0, http_helpers_1.getContentType)(contentTypeHeader);
|
|
51
42
|
if (constants_1.RQ_INTERCEPTED_CONTENT_TYPES.includes(contentType) || contentType == null) {
|
|
52
|
-
|
|
43
|
+
await modify_response_using_code(action, ctx);
|
|
53
44
|
delete_breaking_headers(ctx);
|
|
54
45
|
return (0, utils_1.build_action_processor_response)(action, true);
|
|
55
46
|
}
|
|
@@ -68,7 +59,7 @@ const process_modify_response_action = (action, ctx) => __awaiter(void 0, void 0
|
|
|
68
59
|
delete_breaking_headers(ctx);
|
|
69
60
|
return (0, utils_1.build_action_processor_response)(action, true);
|
|
70
61
|
}
|
|
71
|
-
}
|
|
62
|
+
};
|
|
72
63
|
const delete_breaking_headers = (ctx) => {
|
|
73
64
|
delete (0, proxy_ctx_helper_1.getResponseHeaders)(ctx)['content-length'];
|
|
74
65
|
};
|
|
@@ -83,11 +74,11 @@ const modify_response_using_local = (action, ctx) => {
|
|
|
83
74
|
modify_response(ctx, data, action.statusCode);
|
|
84
75
|
}
|
|
85
76
|
catch (err) {
|
|
86
|
-
console.log("
|
|
77
|
+
console.log("Error reading file", err);
|
|
87
78
|
}
|
|
88
79
|
};
|
|
89
|
-
const modify_response_using_code = (action, ctx) =>
|
|
90
|
-
var _b, _c, _d
|
|
80
|
+
const modify_response_using_code = async (action, ctx) => {
|
|
81
|
+
var _a, _b, _c, _d;
|
|
91
82
|
let userFunction = null;
|
|
92
83
|
try {
|
|
93
84
|
userFunction = (0, utils_2.getFunctionFromString)(action.response);
|
|
@@ -112,18 +103,18 @@ const modify_response_using_code = (action, ctx) => __awaiter(void 0, void 0, vo
|
|
|
112
103
|
: null,
|
|
113
104
|
response: ctx === null || ctx === void 0 ? void 0 : ctx.rq_parsed_response_body,
|
|
114
105
|
url: (0, proxy_ctx_helper_1.get_request_url)(ctx),
|
|
115
|
-
responseType: (
|
|
106
|
+
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"],
|
|
116
107
|
requestHeaders: ctx.clientToProxyRequest.headers,
|
|
117
|
-
requestData: (0, http_helpers_1.parseJsonBody)((
|
|
108
|
+
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,
|
|
118
109
|
statusCode: ctx.serverToProxyResponse.statusCode,
|
|
119
110
|
};
|
|
120
111
|
try {
|
|
121
112
|
args.responseJSON = JSON.parse(args.response);
|
|
122
113
|
}
|
|
123
|
-
catch (
|
|
114
|
+
catch (_e) {
|
|
124
115
|
/*Do nothing -- could not parse body as JSON */
|
|
125
116
|
}
|
|
126
|
-
finalResponse =
|
|
117
|
+
finalResponse = await (0, utils_2.executeUserFunction)(ctx, action.response, args);
|
|
127
118
|
if (finalResponse && typeof finalResponse === "string") {
|
|
128
119
|
return modify_response(ctx, finalResponse, action.statusCode);
|
|
129
120
|
}
|
|
@@ -135,5 +126,5 @@ const modify_response_using_code = (action, ctx) => __awaiter(void 0, void 0, vo
|
|
|
135
126
|
return modify_response(ctx, "Can't execute Requestly function. Please recheck. Error Code 187. Actual Error: " +
|
|
136
127
|
error.message);
|
|
137
128
|
}
|
|
138
|
-
}
|
|
129
|
+
};
|
|
139
130
|
exports.default = process_modify_response_action;
|
package/dist/components/proxy-middleware/rule_action_processor/processors/redirect_processor.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -24,7 +15,7 @@ const getRequestOrigin = (ctx) => {
|
|
|
24
15
|
originalRequestHeaders["origin"] ||
|
|
25
16
|
originalRequestHeaders["ORIGIN"]);
|
|
26
17
|
};
|
|
27
|
-
const process_redirect_action = (action, ctx) =>
|
|
18
|
+
const process_redirect_action = async (action, ctx) => {
|
|
28
19
|
const allowed_handlers = [proxy_1.PROXY_HANDLER_TYPE.ON_REQUEST];
|
|
29
20
|
if (!allowed_handlers.includes(ctx.currentHandler)) {
|
|
30
21
|
return (0, utils_1.build_action_processor_response)(action, false);
|
|
@@ -40,7 +31,7 @@ const process_redirect_action = (action, ctx) => __awaiter(void 0, void 0, void
|
|
|
40
31
|
else {
|
|
41
32
|
modified_requests_pool_1.default.add(new_url);
|
|
42
33
|
}
|
|
43
|
-
const { status: isMixedResponse, response_data } =
|
|
34
|
+
const { status: isMixedResponse, response_data } = await (0, handle_mixed_response_1.default)(ctx, new_url);
|
|
44
35
|
if (isMixedResponse) {
|
|
45
36
|
return (0, utils_1.build_action_processor_response)(action, true, (0, utils_1.build_post_process_data)(response_data.status_code, response_data.headers, response_data.body));
|
|
46
37
|
}
|
|
@@ -53,5 +44,5 @@ const process_redirect_action = (action, ctx) => __awaiter(void 0, void 0, void
|
|
|
53
44
|
"Access-Control-Allow-Credentials": "true",
|
|
54
45
|
Location: new_url,
|
|
55
46
|
}, null));
|
|
56
|
-
}
|
|
47
|
+
};
|
|
57
48
|
exports.default = process_redirect_action;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// import { ISource, SSLProxyingJsonObj } from "lib/storage/types/ssl-proxying";
|
|
3
|
+
// import BaseConfigFetcher from "renderer/lib/fetcher/base";
|
|
4
|
+
// TODO: @sahil fix this by adding type.d.ts file
|
|
5
|
+
//@ts-ignore
|
|
6
|
+
// import { RULE_PROCESSOR } from "@requestly/requestly-core";
|
|
2
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
8
|
// TODO: @sahil to add this
|
|
4
9
|
class SSLProxyingManager {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
export default DefaultExport;
|
|
2
|
+
export { Proxy, PROXY_HANDLER_TYPE, gunzip, wildcard };
|
package/dist/lib/proxy/index.js
CHANGED
|
@@ -1,2 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.wildcard = exports.gunzip = exports.PROXY_HANDLER_TYPE = exports.Proxy = void 0;
|
|
27
|
+
const proxy_1 = __importStar(require("./lib/proxy"));
|
|
28
|
+
Object.defineProperty(exports, "Proxy", { enumerable: true, get: function () { return proxy_1.Proxy; } });
|
|
29
|
+
Object.defineProperty(exports, "PROXY_HANDLER_TYPE", { enumerable: true, get: function () { return proxy_1.PROXY_HANDLER_TYPE; } });
|
|
30
|
+
Object.defineProperty(exports, "gunzip", { enumerable: true, get: function () { return proxy_1.gunzip; } });
|
|
31
|
+
Object.defineProperty(exports, "wildcard", { enumerable: true, get: function () { return proxy_1.wildcard; } });
|
|
32
|
+
exports.default = proxy_1.default;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var zlib = require("zlib");
|
|
3
|
-
|
|
3
|
+
const gunzipMiddleware = {
|
|
4
4
|
onResponse: function (ctx, callback) {
|
|
5
5
|
if (ctx.serverToProxyResponse.headers["content-encoding"] &&
|
|
6
6
|
ctx.serverToProxyResponse.headers["content-encoding"].toLowerCase() ==
|
|
@@ -15,3 +15,4 @@ module.exports = {
|
|
|
15
15
|
return callback();
|
|
16
16
|
},
|
|
17
17
|
};
|
|
18
|
+
module.exports = gunzipMiddleware;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* exclude short domains (length < 4) to avoid catching double extensions (ex: net.au, co.uk, ...)
|
|
6
6
|
*/
|
|
7
7
|
const HOSTNAME_REGEX = /^(.+)(\.[^\.]{4,}(\.[^\.]{1,3})*\.[^\.]+)$/;
|
|
8
|
-
|
|
8
|
+
const wildcaredMiddleware = {
|
|
9
9
|
onCertificateRequired: function (hostname, callback) {
|
|
10
10
|
var rootHost = hostname;
|
|
11
11
|
if (HOSTNAME_REGEX.test(hostname)) {
|
|
@@ -18,3 +18,4 @@ module.exports = {
|
|
|
18
18
|
});
|
|
19
19
|
},
|
|
20
20
|
};
|
|
21
|
+
module.exports = wildcaredMiddleware;
|
|
@@ -7,12 +7,12 @@ declare var fs: any;
|
|
|
7
7
|
declare var path: any;
|
|
8
8
|
declare var events: any;
|
|
9
9
|
declare var WebSocket: {
|
|
10
|
-
new (url: string | URL, protocols?: string | string[]): WebSocket;
|
|
11
10
|
prototype: WebSocket;
|
|
12
|
-
|
|
13
|
-
readonly
|
|
14
|
-
readonly
|
|
15
|
-
readonly
|
|
11
|
+
new (url: string | URL, protocols?: string | string[]): WebSocket;
|
|
12
|
+
readonly CONNECTING: 0;
|
|
13
|
+
readonly OPEN: 1;
|
|
14
|
+
readonly CLOSING: 2;
|
|
15
|
+
readonly CLOSED: 3;
|
|
16
16
|
};
|
|
17
17
|
declare var url: any;
|
|
18
18
|
declare var semaphore: any;
|
package/dist/test.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -24,7 +15,7 @@ const proxyConfig = {
|
|
|
24
15
|
};
|
|
25
16
|
class RulesDataSource {
|
|
26
17
|
constructor() {
|
|
27
|
-
this.getRules = (requestHeaders) =>
|
|
18
|
+
this.getRules = async (requestHeaders) => {
|
|
28
19
|
return [
|
|
29
20
|
{
|
|
30
21
|
"creationDate": 1648800254537,
|
|
@@ -71,15 +62,15 @@ class RulesDataSource {
|
|
|
71
62
|
"lastModified": 1648800283699
|
|
72
63
|
}
|
|
73
64
|
];
|
|
74
|
-
}
|
|
75
|
-
this.getGroups = (requestHeaders) =>
|
|
65
|
+
};
|
|
66
|
+
this.getGroups = async (requestHeaders) => {
|
|
76
67
|
return [
|
|
77
68
|
{
|
|
78
69
|
id: "1",
|
|
79
70
|
status: "Inactive"
|
|
80
71
|
}
|
|
81
72
|
];
|
|
82
|
-
}
|
|
73
|
+
};
|
|
83
74
|
}
|
|
84
75
|
}
|
|
85
76
|
class LoggerService {
|
|
@@ -94,7 +85,7 @@ class LoggerService {
|
|
|
94
85
|
log.finalHar = JSON.stringify(log.finalHar);
|
|
95
86
|
(0, axios_1.default)({
|
|
96
87
|
method: "post",
|
|
97
|
-
url: "http://localhost:5001/requestly-dev/us-central1/addSdkLog",
|
|
88
|
+
url: "http://localhost:5001/requestly-dev/us-central1/addSdkLog", // local
|
|
98
89
|
headers,
|
|
99
90
|
data: log
|
|
100
91
|
}).then(() => {
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
class RulesHelper {
|
|
13
4
|
// TODO: this can be static class too
|
|
@@ -30,20 +21,20 @@ class RulesHelper {
|
|
|
30
21
|
}
|
|
31
22
|
return false;
|
|
32
23
|
};
|
|
33
|
-
this.get_groups = (is_active = false, requestHeaders = {}) =>
|
|
34
|
-
let groups =
|
|
24
|
+
this.get_groups = async (is_active = false, requestHeaders = {}) => {
|
|
25
|
+
let groups = await this.rulesDataSource.getGroups(requestHeaders) || [];
|
|
35
26
|
if (is_active === true) {
|
|
36
27
|
groups = groups.filter((group) => this.is_group_active(group));
|
|
37
28
|
}
|
|
38
29
|
return groups;
|
|
39
|
-
}
|
|
40
|
-
this.get_group_ids = (is_active = false, requestHeaders = {}) =>
|
|
41
|
-
const groups =
|
|
30
|
+
};
|
|
31
|
+
this.get_group_ids = async (is_active = false, requestHeaders = {}) => {
|
|
32
|
+
const groups = await this.get_groups(is_active, requestHeaders);
|
|
42
33
|
return groups.map((group) => group.id);
|
|
43
|
-
}
|
|
44
|
-
this.get_rules = (is_active = false, requestHeaders = {}) =>
|
|
45
|
-
let rules =
|
|
46
|
-
let active_group_ids =
|
|
34
|
+
};
|
|
35
|
+
this.get_rules = async (is_active = false, requestHeaders = {}) => {
|
|
36
|
+
let rules = await this.rulesDataSource.getRules(requestHeaders) || [];
|
|
37
|
+
let active_group_ids = await this.get_group_ids(true, requestHeaders) || [];
|
|
47
38
|
if (is_active === true) {
|
|
48
39
|
rules = rules.filter((rule) => this.is_rule_active(rule, active_group_ids));
|
|
49
40
|
}
|
|
@@ -52,7 +43,7 @@ class RulesHelper {
|
|
|
52
43
|
return ("" + rule1.id).localeCompare(rule2.id);
|
|
53
44
|
});
|
|
54
45
|
return rules;
|
|
55
|
-
}
|
|
46
|
+
};
|
|
56
47
|
this.rulesDataSource = rulesDataSource;
|
|
57
48
|
}
|
|
58
49
|
}
|