@requestly/requestly-proxy 1.3.4 → 1.3.5

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.
@@ -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
  }
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.5",
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",