@requestly/requestly-proxy 1.3.12 → 1.3.13

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.
@@ -9,3 +9,4 @@ export namespace RULE_ACTION {
9
9
  let MODIFY_REQUEST: string;
10
10
  }
11
11
  export const RQ_INTERCEPTED_CONTENT_TYPES: string[];
12
+ export const RQ_INTERCEPTED_CONTENT_TYPES_REGEX: RegExp;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RQ_INTERCEPTED_CONTENT_TYPES = exports.RULE_ACTION = void 0;
3
+ exports.RQ_INTERCEPTED_CONTENT_TYPES_REGEX = exports.RQ_INTERCEPTED_CONTENT_TYPES = exports.RULE_ACTION = void 0;
4
4
  exports.RULE_ACTION = {
5
5
  REDIRECT: "redirect",
6
6
  MODIFY_HEADERS: "modify_headers",
@@ -22,3 +22,15 @@ exports.RQ_INTERCEPTED_CONTENT_TYPES = [
22
22
  "application/json",
23
23
  "application/manifest+json"
24
24
  ];
25
+ exports.RQ_INTERCEPTED_CONTENT_TYPES_REGEX = new RegExp([
26
+ 'text/html', // HTML documents
27
+ 'text/plain', // Plain text
28
+ 'text/javascript', // JavaScript files
29
+ 'application/javascript', // JavaScript (standard MIME)
30
+ 'application/x-javascript', // JavaScript (legacy)
31
+ 'text/css', // CSS files
32
+ 'application/css', // CSS (alternative)
33
+ 'application/json', // JSON data
34
+ 'application/.+\\+json', // JSON-based media types (including vendor-specific like application/vnd.*)
35
+ ].join('|'), 'i');
36
+ // console.log(RQ_INTERCEPTED_CONTENT_TYPES_REGEX);
@@ -147,7 +147,7 @@ class ProxyMiddlewareManager {
147
147
  ctx.rq.set_original_request({ body: pre_final_body });
148
148
  ctx.rq_request_body = pre_final_body;
149
149
  let request_rule_applied = false;
150
- if (parsedBody && constants_1.RQ_INTERCEPTED_CONTENT_TYPES.includes(contentType)) {
150
+ if (parsedBody && constants_1.RQ_INTERCEPTED_CONTENT_TYPES_REGEX.test(contentType)) {
151
151
  // Do modifications, if any
152
152
  const { action_result_objs, continue_request } = await rules_middleware.on_request_end(ctx);
153
153
  if (!continue_request) {
@@ -189,13 +189,21 @@ class ProxyMiddlewareManager {
189
189
  ctx.rq_response_body = body;
190
190
  ctx.rq_parsed_response_body = parsedBody;
191
191
  ctx.rq_response_status_code = (0, proxy_ctx_helper_1.getResponseStatusCode)(ctx);
192
- if (constants_1.RQ_INTERCEPTED_CONTENT_TYPES.includes(contentType) && parsedBody) {
192
+ if (constants_1.RQ_INTERCEPTED_CONTENT_TYPES_REGEX.test(contentType) && parsedBody) {
193
193
  ctx.rq_response_body = parsedBody;
194
194
  ctx.rq.set_original_response({ body: parsedBody });
195
195
  }
196
196
  const { action_result_objs, continue_request } = await rules_middleware.on_response_end(ctx);
197
197
  const statusCode = ctx.rq_response_status_code || (0, proxy_ctx_helper_1.getResponseStatusCode)(ctx);
198
- ctx.proxyToClientResponse.writeHead(statusCode, http_1.default.STATUS_CODES[statusCode], (0, proxy_ctx_helper_1.getResponseHeaders)(ctx));
198
+ const responseHeaders = (0, proxy_ctx_helper_1.getResponseHeaders)(ctx);
199
+ // For 204/304/1xx, remove content headers to prevent errors
200
+ if (statusCode === 204 || statusCode === 304 || (statusCode >= 100 && statusCode < 200)) {
201
+ delete responseHeaders['content-length'];
202
+ delete responseHeaders['Content-Length'];
203
+ delete responseHeaders['transfer-encoding'];
204
+ delete responseHeaders['Transfer-Encoding'];
205
+ }
206
+ ctx.proxyToClientResponse.writeHead(statusCode, http_1.default.STATUS_CODES[statusCode], responseHeaders);
199
207
  ctx.proxyToClientResponse.write(ctx.rq_response_body);
200
208
  ctx.rq.set_final_response({
201
209
  ...(0, proxy_ctx_helper_1.get_response_options)(ctx),
@@ -63,7 +63,7 @@ const process_modify_response_action = async (action, ctx) => {
63
63
  action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.CODE) {
64
64
  const contentTypeHeader = (0, proxy_ctx_helper_1.getResponseContentTypeHeader)(ctx);
65
65
  const contentType = (0, http_helpers_1.getContentType)(contentTypeHeader);
66
- if (constants_1.RQ_INTERCEPTED_CONTENT_TYPES.includes(contentType) || contentType == null) {
66
+ if (constants_1.RQ_INTERCEPTED_CONTENT_TYPES_REGEX.test(contentType) || contentType == null) {
67
67
  await modify_response_using_code(action, ctx);
68
68
  delete_breaking_headers(ctx);
69
69
  return (0, utils_1.build_action_processor_response)(action, true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@requestly/requestly-proxy",
3
- "version": "1.3.12",
3
+ "version": "1.3.13",
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",
@@ -9,11 +9,12 @@
9
9
  "test": "echo \"Error: no test specified\" && exit 1",
10
10
  "dev": "nodemon src/test.ts",
11
11
  "build": "tsc",
12
- "watch": "tsc --watch"
12
+ "watch": "tsc --watch",
13
+ "release": "release-it"
13
14
  },
14
15
  "repository": {
15
16
  "type": "git",
16
- "url": "git+https://github.com/requestly/rq-proxy.git"
17
+ "url": "git+https://github.com/requestly/requestly-proxy.git"
17
18
  },
18
19
  "exports": {
19
20
  ".": {
@@ -45,10 +46,12 @@
45
46
  "ws": "^8.16.0"
46
47
  },
47
48
  "devDependencies": {
49
+ "@release-it/conventional-changelog": "^8.0.2",
48
50
  "@types/har-format": "^1.2.15",
49
51
  "@types/node": "^20.12.12",
50
52
  "ajv": "^8.13.0",
51
53
  "nodemon": "^3.1.0",
54
+ "release-it": "^17.10.0",
52
55
  "type-fest": "^2.12.2",
53
56
  "typescript": "^5.6.3"
54
57
  },