@requestly/requestly-proxy 1.3.11 → 1.3.13
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 +1 -0
- package/dist/components/proxy-middleware/constants.js +13 -1
- package/dist/components/proxy-middleware/index.js +11 -3
- package/dist/components/proxy-middleware/middlewares/logger_middleware.js +1 -1
- package/dist/components/proxy-middleware/rule_action_processor/processors/modify_response_processor.js +1 -1
- package/dist/components/proxy-middleware/rule_action_processor/utils.d.ts +1 -0
- package/dist/components/proxy-middleware/rule_action_processor/utils.js +13 -1
- package/package.json +6 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RQ_INTERCEPTED_CONTENT_TYPES = exports.RULE_ACTION = void 0;
|
|
3
|
+
exports.RQ_INTERCEPTED_CONTENT_TYPES_REGEX = exports.RQ_INTERCEPTED_CONTENT_TYPES = exports.RULE_ACTION = void 0;
|
|
4
4
|
exports.RULE_ACTION = {
|
|
5
5
|
REDIRECT: "redirect",
|
|
6
6
|
MODIFY_HEADERS: "modify_headers",
|
|
@@ -22,3 +22,15 @@ exports.RQ_INTERCEPTED_CONTENT_TYPES = [
|
|
|
22
22
|
"application/json",
|
|
23
23
|
"application/manifest+json"
|
|
24
24
|
];
|
|
25
|
+
exports.RQ_INTERCEPTED_CONTENT_TYPES_REGEX = new RegExp([
|
|
26
|
+
'text/html', // HTML documents
|
|
27
|
+
'text/plain', // Plain text
|
|
28
|
+
'text/javascript', // JavaScript files
|
|
29
|
+
'application/javascript', // JavaScript (standard MIME)
|
|
30
|
+
'application/x-javascript', // JavaScript (legacy)
|
|
31
|
+
'text/css', // CSS files
|
|
32
|
+
'application/css', // CSS (alternative)
|
|
33
|
+
'application/json', // JSON data
|
|
34
|
+
'application/.+\\+json', // JSON-based media types (including vendor-specific like application/vnd.*)
|
|
35
|
+
].join('|'), 'i');
|
|
36
|
+
// console.log(RQ_INTERCEPTED_CONTENT_TYPES_REGEX);
|
|
@@ -147,7 +147,7 @@ class ProxyMiddlewareManager {
|
|
|
147
147
|
ctx.rq.set_original_request({ body: pre_final_body });
|
|
148
148
|
ctx.rq_request_body = pre_final_body;
|
|
149
149
|
let request_rule_applied = false;
|
|
150
|
-
if (parsedBody && constants_1.
|
|
150
|
+
if (parsedBody && constants_1.RQ_INTERCEPTED_CONTENT_TYPES_REGEX.test(contentType)) {
|
|
151
151
|
// Do modifications, if any
|
|
152
152
|
const { action_result_objs, continue_request } = await rules_middleware.on_request_end(ctx);
|
|
153
153
|
if (!continue_request) {
|
|
@@ -189,13 +189,21 @@ class ProxyMiddlewareManager {
|
|
|
189
189
|
ctx.rq_response_body = body;
|
|
190
190
|
ctx.rq_parsed_response_body = parsedBody;
|
|
191
191
|
ctx.rq_response_status_code = (0, proxy_ctx_helper_1.getResponseStatusCode)(ctx);
|
|
192
|
-
if (constants_1.
|
|
192
|
+
if (constants_1.RQ_INTERCEPTED_CONTENT_TYPES_REGEX.test(contentType) && parsedBody) {
|
|
193
193
|
ctx.rq_response_body = parsedBody;
|
|
194
194
|
ctx.rq.set_original_response({ body: parsedBody });
|
|
195
195
|
}
|
|
196
196
|
const { action_result_objs, continue_request } = await rules_middleware.on_response_end(ctx);
|
|
197
197
|
const statusCode = ctx.rq_response_status_code || (0, proxy_ctx_helper_1.getResponseStatusCode)(ctx);
|
|
198
|
-
|
|
198
|
+
const responseHeaders = (0, proxy_ctx_helper_1.getResponseHeaders)(ctx);
|
|
199
|
+
// For 204/304/1xx, remove content headers to prevent errors
|
|
200
|
+
if (statusCode === 204 || statusCode === 304 || (statusCode >= 100 && statusCode < 200)) {
|
|
201
|
+
delete responseHeaders['content-length'];
|
|
202
|
+
delete responseHeaders['Content-Length'];
|
|
203
|
+
delete responseHeaders['transfer-encoding'];
|
|
204
|
+
delete responseHeaders['Transfer-Encoding'];
|
|
205
|
+
}
|
|
206
|
+
ctx.proxyToClientResponse.writeHead(statusCode, http_1.default.STATUS_CODES[statusCode], responseHeaders);
|
|
199
207
|
ctx.proxyToClientResponse.write(ctx.rq_response_body);
|
|
200
208
|
ctx.rq.set_final_response({
|
|
201
209
|
...(0, proxy_ctx_helper_1.get_response_options)(ctx),
|
|
@@ -71,7 +71,7 @@ class LoggerMiddleware {
|
|
|
71
71
|
const rqLog = {
|
|
72
72
|
id: ctx.uuid,
|
|
73
73
|
timestamp: Math.floor(Date.now() / 1000),
|
|
74
|
-
finalHar: (0, harObectCreator_1.createHar)(ctx.rq.final_request.headers, ctx.rq.final_request.method, protocol, ctx
|
|
74
|
+
finalHar: (0, harObectCreator_1.createHar)(ctx.rq.final_request.headers, ctx.rq.final_request.method, protocol, (0, utils_1.getHost)(ctx), ctx.rq.final_request.path, ctx.rq.final_request.body, ctx.rq.final_response.status_code, ctx.rq.final_response.body, ctx.rq.final_response.headers || {}, ctx.rq.final_request.query_params),
|
|
75
75
|
requestShellCurl: this.generate_curl_from_har((_b = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.rq) === null || _a === void 0 ? void 0 : _a.final_request) === null || _b === void 0 ? void 0 : _b.requestHarObject), // TODO: Move this to client side
|
|
76
76
|
actions: (0, utils_1.get_success_actions_from_action_results)(action_result_objs),
|
|
77
77
|
consoleLogs: (_c = ctx === null || ctx === void 0 ? void 0 : ctx.rq) === null || _c === void 0 ? void 0 : _c.consoleLogs,
|
|
@@ -63,7 +63,7 @@ const process_modify_response_action = async (action, ctx) => {
|
|
|
63
63
|
action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.CODE) {
|
|
64
64
|
const contentTypeHeader = (0, proxy_ctx_helper_1.getResponseContentTypeHeader)(ctx);
|
|
65
65
|
const contentType = (0, http_helpers_1.getContentType)(contentTypeHeader);
|
|
66
|
-
if (constants_1.
|
|
66
|
+
if (constants_1.RQ_INTERCEPTED_CONTENT_TYPES_REGEX.test(contentType) || contentType == null) {
|
|
67
67
|
await modify_response_using_code(action, ctx);
|
|
68
68
|
delete_breaking_headers(ctx);
|
|
69
69
|
return (0, utils_1.build_action_processor_response)(action, true);
|
|
@@ -9,4 +9,5 @@ export function build_post_process_data(status_code: any, headers: any, body: an
|
|
|
9
9
|
body: any;
|
|
10
10
|
};
|
|
11
11
|
export function get_success_actions_from_action_results(action_result_objs?: any[]): any[];
|
|
12
|
+
export function getHost(ctx: any): any;
|
|
12
13
|
export function get_file_contents(file_path: any): string;
|
|
@@ -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.get_file_contents = exports.get_success_actions_from_action_results = exports.build_post_process_data = exports.build_action_processor_response = void 0;
|
|
6
|
+
exports.get_file_contents = exports.getHost = exports.get_success_actions_from_action_results = exports.build_post_process_data = exports.build_action_processor_response = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const build_action_processor_response = (action, success = false, post_process_data = null) => {
|
|
9
9
|
let resp = {
|
|
@@ -35,6 +35,18 @@ const get_success_actions_from_action_results = (action_result_objs = []) => {
|
|
|
35
35
|
return success_action_results_objs.map((obj) => obj.action);
|
|
36
36
|
};
|
|
37
37
|
exports.get_success_actions_from_action_results = get_success_actions_from_action_results;
|
|
38
|
+
const getHost = (ctx) => {
|
|
39
|
+
const finalHost = ctx.rq.final_request.host;
|
|
40
|
+
const port = ctx.rq.final_request.port;
|
|
41
|
+
const protocol = ctx.isSSL ? "https" : "http";
|
|
42
|
+
const standardPort = protocol === "https" ? 443 : 80;
|
|
43
|
+
// Only append port if it's non-standard and not already in the host
|
|
44
|
+
if (port && port !== standardPort && !finalHost.includes(':')) {
|
|
45
|
+
return `${finalHost}:${port}`;
|
|
46
|
+
}
|
|
47
|
+
return finalHost;
|
|
48
|
+
};
|
|
49
|
+
exports.getHost = getHost;
|
|
38
50
|
const get_file_contents = (file_path) => {
|
|
39
51
|
return fs_1.default.readFileSync(file_path, "utf-8");
|
|
40
52
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@requestly/requestly-proxy",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.13",
|
|
4
4
|
"description": "Proxy that gives superpowers to all the Requestly clients",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -9,11 +9,12 @@
|
|
|
9
9
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
10
10
|
"dev": "nodemon src/test.ts",
|
|
11
11
|
"build": "tsc",
|
|
12
|
-
"watch": "tsc --watch"
|
|
12
|
+
"watch": "tsc --watch",
|
|
13
|
+
"release": "release-it"
|
|
13
14
|
},
|
|
14
15
|
"repository": {
|
|
15
16
|
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/requestly/
|
|
17
|
+
"url": "git+https://github.com/requestly/requestly-proxy.git"
|
|
17
18
|
},
|
|
18
19
|
"exports": {
|
|
19
20
|
".": {
|
|
@@ -45,10 +46,12 @@
|
|
|
45
46
|
"ws": "^8.16.0"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
49
|
+
"@release-it/conventional-changelog": "^8.0.2",
|
|
48
50
|
"@types/har-format": "^1.2.15",
|
|
49
51
|
"@types/node": "^20.12.12",
|
|
50
52
|
"ajv": "^8.13.0",
|
|
51
53
|
"nodemon": "^3.1.0",
|
|
54
|
+
"release-it": "^17.10.0",
|
|
52
55
|
"type-fest": "^2.12.2",
|
|
53
56
|
"typescript": "^5.6.3"
|
|
54
57
|
},
|