@requestly/requestly-proxy 1.3.10 → 1.3.12

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.
@@ -146,6 +146,7 @@ class ProxyMiddlewareManager {
146
146
  let pre_final_body = parsedBody || body.toString("utf8");
147
147
  ctx.rq.set_original_request({ body: pre_final_body });
148
148
  ctx.rq_request_body = pre_final_body;
149
+ let request_rule_applied = false;
149
150
  if (parsedBody && constants_1.RQ_INTERCEPTED_CONTENT_TYPES.includes(contentType)) {
150
151
  // Do modifications, if any
151
152
  const { action_result_objs, continue_request } = await rules_middleware.on_request_end(ctx);
@@ -153,9 +154,15 @@ class ProxyMiddlewareManager {
153
154
  logger_middleware.send_network_log(ctx, rules_middleware.action_result_objs, requestly_core_1.CONSTANTS.REQUEST_STATE.COMPLETE);
154
155
  return;
155
156
  }
157
+ request_rule_applied = action_result_objs === null || action_result_objs === void 0 ? void 0 : action_result_objs.some((obj) => { var _a; return ((_a = obj === null || obj === void 0 ? void 0 : obj.action) === null || _a === void 0 ? void 0 : _a.action) === constants_1.RULE_ACTION.MODIFY_REQUEST; });
158
+ }
159
+ if (request_rule_applied) {
160
+ ctx.proxyToServerRequest.write(ctx.rq_request_body);
161
+ }
162
+ else {
163
+ // If no modifications, write the original request body buffer so that we don't mess up during decoding
164
+ ctx.proxyToServerRequest.write(body);
156
165
  }
157
- // Use the updated request
158
- ctx.proxyToServerRequest.write(ctx.rq_request_body);
159
166
  ctx.rq.set_final_request({ body: ctx.rq_request_body });
160
167
  return callback();
161
168
  });
@@ -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.rq.final_request.host, 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),
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,
@@ -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.10",
3
+ "version": "1.3.12",
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",
@@ -26,7 +26,7 @@
26
26
  "author": "",
27
27
  "license": "ISC",
28
28
  "dependencies": {
29
- "@requestly/requestly-core": "^1.1.0",
29
+ "@requestly/requestly-core": "1.1.1",
30
30
  "@sentry/browser": "^8.33.1",
31
31
  "async": "^3.2.5",
32
32
  "axios": "^1.7.2",