@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.
- package/dist/components/proxy-middleware/index.js +1 -1
- package/dist/components/proxy-middleware/rule_action_processor/handle_mixed_response.d.ts +15 -0
- package/dist/components/proxy-middleware/rule_action_processor/handle_mixed_response.js +13 -4
- package/dist/lib/proxy/index.d.ts +1 -1
- package/dist/lib/proxy/index.js +2 -1
- package/dist/lib/proxy/lib/middleware/decompress.d.ts +2 -0
- package/dist/lib/proxy/lib/middleware/decompress.js +24 -0
- package/dist/lib/proxy/lib/proxy.js +1 -0
- package/package.json +1 -1
|
@@ -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.
|
|
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
|
-
|
|
75
|
-
const
|
|
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
|
|
88
|
+
headers,
|
|
80
89
|
status_code: 200,
|
|
81
|
-
body:
|
|
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 };
|
package/dist/lib/proxy/index.js
CHANGED
|
@@ -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,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 = [];
|