@requestly/requestly-proxy 1.3.5 → 1.3.7

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.
@@ -236,7 +236,7 @@ class ProxyMiddlewareManager {
236
236
  this.init_handlers = () => {
237
237
  this.proxy.onRequestHandlers = [];
238
238
  this.proxy.onConnectHandlers = [];
239
- this.proxy.use(proxy_1.default.gunzip);
239
+ this.proxy.use(proxy_1.default.decompress);
240
240
  // this.init_ssl_tunneling_handler();
241
241
  this.init_amiusing_handler();
242
242
  this.init_ssl_cert_handler();
@@ -1,13 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  const proxy_1 = require("../../../../lib/proxy");
7
4
  const requestly_core_1 = require("@requestly/requestly-core");
8
5
  const proxy_ctx_helper_1 = require("../../helpers/proxy_ctx_helper");
9
6
  const utils_1 = require("../utils");
10
- const fs_1 = __importDefault(require("fs"));
11
7
  const http_helpers_1 = require("../../helpers/http_helpers");
12
8
  const utils_2 = require("../../../../utils");
13
9
  const constants_1 = require("../../constants");
@@ -17,16 +13,32 @@ const process_modify_response_action = async (action, ctx) => {
17
13
  return (0, utils_1.build_action_processor_response)(action, false);
18
14
  }
19
15
  if (ctx.currentHandler === proxy_1.PROXY_HANDLER_TYPE.ON_REQUEST) {
20
- if (action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.STATIC
21
- && action.serveWithoutRequest) {
16
+ if (action.serveWithoutRequest) {
22
17
  let contentType, finalBody;
18
+ if (action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.LOCAL_FILE) {
19
+ try {
20
+ finalBody = (0, utils_1.get_file_contents)(action.response);
21
+ }
22
+ catch (err) {
23
+ console.log("Error reading file", err);
24
+ return (0, utils_1.build_action_processor_response)(action, false);
25
+ }
26
+ }
27
+ else if (action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.STATIC) {
28
+ finalBody = action.response;
29
+ }
30
+ else {
31
+ return (0, utils_1.build_action_processor_response)(action, false);
32
+ }
23
33
  try {
24
- finalBody = JSON.parse(action.response);
34
+ const parsedResponse = JSON.parse(finalBody);
35
+ if (action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.STATIC) {
36
+ finalBody = parsedResponse;
37
+ }
25
38
  contentType = "application/json";
26
39
  }
27
40
  catch (_a) {
28
41
  contentType = "text/plain";
29
- finalBody = action.response;
30
42
  }
31
43
  const status = action.statusCode || 200;
32
44
  const finalHeaders = { "Content-Type": contentType };
@@ -70,7 +82,7 @@ const modify_response = (ctx, new_resp, status_code) => {
70
82
  const modify_response_using_local = (action, ctx) => {
71
83
  let data;
72
84
  try {
73
- data = fs_1.default.readFileSync(action.response, "utf-8");
85
+ data = (0, utils_1.get_file_contents)(action.response);
74
86
  modify_response(ctx, data, action.statusCode);
75
87
  }
76
88
  catch (err) {
@@ -9,3 +9,4 @@ 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 get_file_contents(file_path: any): string;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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.get_success_actions_from_action_results = exports.build_post_process_data = exports.build_action_processor_response = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
4
8
  const build_action_processor_response = (action, success = false, post_process_data = null) => {
5
9
  let resp = {
6
10
  action: action,
@@ -31,3 +35,7 @@ const get_success_actions_from_action_results = (action_result_objs = []) => {
31
35
  return success_action_results_objs.map((obj) => obj.action);
32
36
  };
33
37
  exports.get_success_actions_from_action_results = get_success_actions_from_action_results;
38
+ const get_file_contents = (file_path) => {
39
+ return fs_1.default.readFileSync(action.response, "utf-8");
40
+ };
41
+ exports.get_file_contents = get_file_contents;
@@ -1,2 +1,2 @@
1
1
  export default DefaultExport;
2
- export { Proxy, PROXY_HANDLER_TYPE, gunzip, wildcard };
2
+ export { Proxy, PROXY_HANDLER_TYPE, gunzip, decompress, wildcard };
@@ -23,10 +23,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.wildcard = exports.gunzip = exports.PROXY_HANDLER_TYPE = exports.Proxy = void 0;
26
+ exports.wildcard = exports.decompress = exports.gunzip = exports.PROXY_HANDLER_TYPE = exports.Proxy = void 0;
27
27
  const proxy_1 = __importStar(require("./lib/proxy"));
28
28
  Object.defineProperty(exports, "Proxy", { enumerable: true, get: function () { return proxy_1.Proxy; } });
29
29
  Object.defineProperty(exports, "PROXY_HANDLER_TYPE", { enumerable: true, get: function () { return proxy_1.PROXY_HANDLER_TYPE; } });
30
30
  Object.defineProperty(exports, "gunzip", { enumerable: true, get: function () { return proxy_1.gunzip; } });
31
+ Object.defineProperty(exports, "decompress", { enumerable: true, get: function () { return proxy_1.decompress; } });
31
32
  Object.defineProperty(exports, "wildcard", { enumerable: true, get: function () { return proxy_1.wildcard; } });
32
33
  exports.default = proxy_1.default;
@@ -0,0 +1,2 @@
1
+ export function onResponse(ctx: any, callback: any): any;
2
+ export function onRequest(ctx: any, callback: any): any;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var zlib = require("zlib");
3
+ const decompressMiddleware = {
4
+ onResponse: function (ctx, callback) {
5
+ if (ctx.serverToProxyResponse.headers["content-encoding"] &&
6
+ ctx.serverToProxyResponse.headers["content-encoding"].toLowerCase() ==
7
+ "gzip") {
8
+ delete ctx.serverToProxyResponse.headers["content-encoding"];
9
+ ctx.addResponseFilter(zlib.createGunzip());
10
+ }
11
+ else if (ctx.serverToProxyResponse.headers["content-encoding"] &&
12
+ ctx.serverToProxyResponse.headers["content-encoding"].toLowerCase() ==
13
+ "br") {
14
+ delete ctx.serverToProxyResponse.headers["content-encoding"];
15
+ ctx.addResponseFilter(zlib.createBrotliDecompress());
16
+ }
17
+ return callback();
18
+ },
19
+ onRequest: function (ctx, callback) {
20
+ ctx.proxyToServerRequestOptions.headers["accept-encoding"] = "gzip";
21
+ return callback();
22
+ },
23
+ };
24
+ module.exports = decompressMiddleware;
@@ -21,6 +21,7 @@ module.exports = function () {
21
21
  return new Proxy();
22
22
  };
23
23
  module.exports.gunzip = require("./middleware/gunzip");
24
+ module.exports.decompress = require("./middleware/decompress");
24
25
  module.exports.wildcard = require("./middleware/wildcard");
25
26
  var Proxy = function () {
26
27
  this.onConnectHandlers = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@requestly/requestly-proxy",
3
- "version": "1.3.5",
3
+ "version": "1.3.7",
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",