@requestly/requestly-proxy 1.1.5 → 1.1.6

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.
@@ -1,2 +1,3 @@
1
1
  export function bodyParser(contentTypeHeader: any, buffer: any): any;
2
2
  export function getContentType(contentTypeHeader: any): any;
3
+ export function parseJsonBody(data: any): any;
@@ -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.getContentType = exports.bodyParser = void 0;
6
+ exports.parseJsonBody = exports.getContentType = exports.bodyParser = void 0;
7
7
  const charset_1 = __importDefault(require("charset"));
8
8
  const mime_types_1 = __importDefault(require("mime-types"));
9
9
  const bodyParser = (contentTypeHeader, buffer) => {
@@ -45,3 +45,13 @@ const getContentType = (contentTypeHeader) => {
45
45
  return contentType;
46
46
  };
47
47
  exports.getContentType = getContentType;
48
+ const parseJsonBody = (data) => {
49
+ try {
50
+ return JSON.parse(data);
51
+ }
52
+ catch (e) {
53
+ /* Body is still buffer array */
54
+ }
55
+ return data;
56
+ };
57
+ exports.parseJsonBody = parseJsonBody;
@@ -17,6 +17,7 @@ const requestly_core_1 = require("@requestly/requestly-core");
17
17
  const proxy_ctx_helper_1 = require("../../helpers/proxy_ctx_helper");
18
18
  const utils_1 = require("../utils");
19
19
  const fs_1 = __importDefault(require("fs"));
20
+ const http_helpers_1 = require("../../helpers/http_helpers");
20
21
  const { types } = require("util");
21
22
  const process_modify_response_action = (action, ctx) => __awaiter(void 0, void 0, void 0, function* () {
22
23
  const allowed_handlers = [proxy_1.PROXY_HANDLER_TYPE.ON_RESPONSE_END];
@@ -52,6 +53,7 @@ const modify_response_using_local = (action, ctx) => {
52
53
  }
53
54
  };
54
55
  const modify_response_using_code = (action, ctx) => __awaiter(void 0, void 0, void 0, function* () {
56
+ var _a, _b;
55
57
  let userFunction = null;
56
58
  try {
57
59
  userFunction = requestly_core_1.UTILS.GET_FUNCTION_FROM_STRING(action.response);
@@ -78,12 +80,12 @@ const modify_response_using_code = (action, ctx) => __awaiter(void 0, void 0, vo
78
80
  url: (0, proxy_ctx_helper_1.get_request_url)(ctx),
79
81
  responseType: ctx.serverToProxyResponse.headers["content-type"],
80
82
  requestHeaders: ctx.clientToProxyRequest.headers,
81
- requestData: null,
83
+ requestData: (0, http_helpers_1.parseJsonBody)((_b = (_a = ctx.rq) === null || _a === void 0 ? void 0 : _a.final_request) === null || _b === void 0 ? void 0 : _b.body) || null,
82
84
  };
83
85
  try {
84
86
  args.responseJSON = JSON.parse(args.response);
85
87
  }
86
- catch (_a) {
88
+ catch (_c) {
87
89
  /*Do nothing -- could not parse body as JSON */
88
90
  }
89
91
  finalResponse = userFunction(args);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@requestly/requestly-proxy",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "Proxy that gives superpowers to all the Requestly clients",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {