@requestly/requestly-proxy 1.3.4 → 1.3.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.
@@ -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();
@@ -8,6 +8,21 @@ declare function handleMixedResponse(ctx: any, destinationUrl: any): Promise<{
8
8
  status_code: number;
9
9
  body: any;
10
10
  };
11
+ } | {
12
+ status: boolean;
13
+ response_data: {
14
+ headers: {
15
+ "Content-Type": any;
16
+ "Content-Length": number;
17
+ "Cache-Control": string;
18
+ } | {
19
+ "Cache-Control": string;
20
+ "Content-Type"?: undefined;
21
+ "Content-Length"?: undefined;
22
+ };
23
+ status_code: number;
24
+ body: string;
25
+ };
11
26
  } | {
12
27
  status: boolean;
13
28
  response_data?: undefined;
@@ -30,6 +30,7 @@ const axios = require("axios");
30
30
  const parser = require("ua-parser-js");
31
31
  const fs_1 = __importDefault(require("fs"));
32
32
  const Sentry = __importStar(require("@sentry/browser"));
33
+ const mime = require('mime-types');
33
34
  const handleMixedResponse = async (ctx, destinationUrl) => {
34
35
  var _a, _b, _c;
35
36
  // Handling mixed response from safari
@@ -71,14 +72,22 @@ const handleMixedResponse = async (ctx, destinationUrl) => {
71
72
  if (destinationUrl === null || destinationUrl === void 0 ? void 0 : destinationUrl.startsWith("file://")) {
72
73
  const path = destinationUrl.slice(7);
73
74
  try {
74
- // utf-8 is common assumption, but this introduces edge cases
75
- const data = fs_1.default.readFileSync(path, "utf-8");
75
+ const buffers = fs_1.default.readFileSync(path);
76
+ const mimeType = mime.lookup(path);
77
+ const bodyContent = buffers.toString("utf-8"); // assuming utf-8 encoding
78
+ const headers = mimeType ? {
79
+ "Content-Type": mimeType,
80
+ "Content-Length": Buffer.byteLength(bodyContent),
81
+ "Cache-Control": "no-cache"
82
+ } : {
83
+ "Cache-Control": "no-cache"
84
+ };
76
85
  return {
77
86
  status: true,
78
87
  response_data: {
79
- headers: { "Cache-Control": "no-cache" },
88
+ headers,
80
89
  status_code: 200,
81
- body: data,
90
+ body: buffers.toString("utf-8"), // assuming utf-8 encoding
82
91
  },
83
92
  };
84
93
  }
@@ -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.4",
3
+ "version": "1.3.6",
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",