@requestly/requestly-proxy 1.3.7 → 1.3.9

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.
@@ -96,7 +96,12 @@ class ProxyMiddlewareManager {
96
96
  headers: responseHeaders,
97
97
  body: ctx.rq_response_body,
98
98
  });
99
- logger_middleware.send_network_log(ctx, rules_middleware.action_result_objs, requestly_core_1.CONSTANTS.REQUEST_STATE.COMPLETE);
99
+ if (!ctx.rq.request_finished) {
100
+ logger_middleware.send_network_log(ctx, rules_middleware.action_result_objs, requestly_core_1.CONSTANTS.REQUEST_STATE.COMPLETE);
101
+ }
102
+ else {
103
+ console.log("Expected Error after early termination of request: ", err);
104
+ }
100
105
  }
101
106
  return callback();
102
107
  });
@@ -119,6 +124,10 @@ class ProxyMiddlewareManager {
119
124
  if (parsedBody && constants_1.RQ_INTERCEPTED_CONTENT_TYPES.includes(contentType)) {
120
125
  // Do modifications, if any
121
126
  const { action_result_objs, continue_request } = await rules_middleware.on_request_end(ctx);
127
+ if (!continue_request) {
128
+ logger_middleware.send_network_log(ctx, rules_middleware.action_result_objs, requestly_core_1.CONSTANTS.REQUEST_STATE.COMPLETE);
129
+ return;
130
+ }
122
131
  }
123
132
  // Use the updated request
124
133
  ctx.proxyToServerRequest.write(ctx.rq_request_body);
@@ -78,6 +78,7 @@ class RulesMiddleware {
78
78
  return [];
79
79
  }
80
80
  this._update_request_data({ request_body: ctx.rq.get_json_request_body() });
81
+ this.on_request_actions = this._process_rules();
81
82
  const { action_result_objs, continue_request } = await this.rule_action_processor.process_actions(this.on_request_actions, ctx);
82
83
  this._update_action_result_objs(action_result_objs);
83
84
  return { action_result_objs, continue_request };
@@ -45,6 +45,7 @@ class RuleActionProcessor {
45
45
  body = JSON.stringify(body);
46
46
  }
47
47
  ctx.proxyToClientResponse.writeHead(status_code, headers).end(body);
48
+ ctx.rq.request_finished = true;
48
49
  ctx.rq.set_final_response({
49
50
  status_code: status_code,
50
51
  headers: headers,
@@ -8,11 +8,17 @@ const http_helpers_1 = require("../../helpers/http_helpers");
8
8
  const utils_2 = require("../../../../utils");
9
9
  const constants_1 = require("../../constants");
10
10
  const process_modify_response_action = async (action, ctx) => {
11
- 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];
11
+ const allowed_handlers = [
12
+ proxy_1.PROXY_HANDLER_TYPE.ON_REQUEST,
13
+ proxy_1.PROXY_HANDLER_TYPE.ON_REQUEST_END,
14
+ proxy_1.PROXY_HANDLER_TYPE.ON_RESPONSE_END,
15
+ proxy_1.PROXY_HANDLER_TYPE.ON_ERROR
16
+ ];
12
17
  if (!allowed_handlers.includes(ctx.currentHandler)) {
13
18
  return (0, utils_1.build_action_processor_response)(action, false);
14
19
  }
15
- if (ctx.currentHandler === proxy_1.PROXY_HANDLER_TYPE.ON_REQUEST) {
20
+ if (ctx.currentHandler === proxy_1.PROXY_HANDLER_TYPE.ON_REQUEST ||
21
+ ctx.currentHandler === proxy_1.PROXY_HANDLER_TYPE.ON_REQUEST_END) {
16
22
  if (action.serveWithoutRequest) {
17
23
  let contentType, finalBody;
18
24
  if (action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.LOCAL_FILE) {
@@ -41,7 +47,13 @@ const process_modify_response_action = async (action, ctx) => {
41
47
  contentType = "text/plain";
42
48
  }
43
49
  const status = action.statusCode || 200;
44
- const finalHeaders = { "Content-Type": contentType };
50
+ const finalHeaders = {
51
+ "content-type": contentType,
52
+ "access-control-allow-origin": "*",
53
+ "access-control-allow-methods": "*",
54
+ "access-control-allow-headers": "*",
55
+ "access-control-allow-credentials": "true",
56
+ };
45
57
  modify_response(ctx, finalBody, status);
46
58
  return (0, utils_1.build_action_processor_response)(action, true, (0, utils_1.build_post_process_data)(status, finalHeaders, finalBody));
47
59
  }
@@ -36,6 +36,6 @@ const get_success_actions_from_action_results = (action_result_objs = []) => {
36
36
  };
37
37
  exports.get_success_actions_from_action_results = get_success_actions_from_action_results;
38
38
  const get_file_contents = (file_path) => {
39
- return fs_1.default.readFileSync(action.response, "utf-8");
39
+ return fs_1.default.readFileSync(file_path, "utf-8");
40
40
  };
41
41
  exports.get_file_contents = get_file_contents;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@requestly/requestly-proxy",
3
- "version": "1.3.7",
3
+ "version": "1.3.9",
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",