@requestly/requestly-proxy 1.1.20 → 1.1.21
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.
|
@@ -160,18 +160,11 @@ class ProxyMiddlewareManager {
|
|
|
160
160
|
const contentTypeHeader = (0, proxy_ctx_helper_1.getResponseContentTypeHeader)(ctx);
|
|
161
161
|
const contentType = (0, http_helpers_1.getContentType)(contentTypeHeader);
|
|
162
162
|
const parsedBody = (0, http_helpers_1.bodyParser)(contentTypeHeader, body);
|
|
163
|
+
ctx.rq.set_original_response({ body: parsedBody });
|
|
163
164
|
ctx.rq_response_body = body;
|
|
165
|
+
ctx.rq_parsed_response_body = parsedBody;
|
|
164
166
|
ctx.rq_response_status_code = (0, proxy_ctx_helper_1.getResponseStatusCode)(ctx);
|
|
165
|
-
|
|
166
|
-
ctx.rq.set_original_response({ body: parsedBody });
|
|
167
|
-
// Body and status code before any modifications
|
|
168
|
-
ctx.rq_response_body = parsedBody;
|
|
169
|
-
const { action_result_objs, continue_request } = yield rules_middleware.on_response_end(ctx);
|
|
170
|
-
// ctx.rq_response_body, ctx.rq_response_status_code after modifications
|
|
171
|
-
// TODO: @sahil to investigate why this is need
|
|
172
|
-
// Remove some conflicting headers like content-length, if any
|
|
173
|
-
delete (0, proxy_ctx_helper_1.getResponseHeaders)(ctx)["content-length"];
|
|
174
|
-
}
|
|
167
|
+
const { action_result_objs, continue_request } = yield rules_middleware.on_response_end(ctx);
|
|
175
168
|
const statusCode = ctx.rq_response_status_code || (0, proxy_ctx_helper_1.getResponseStatusCode)(ctx);
|
|
176
169
|
ctx.proxyToClientResponse.writeHead(statusCode, http_1.default.STATUS_CODES[statusCode], (0, proxy_ctx_helper_1.getResponseHeaders)(ctx));
|
|
177
170
|
ctx.proxyToClientResponse.write(ctx.rq_response_body);
|
|
@@ -20,6 +20,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
20
20
|
const http_helpers_1 = require("../../helpers/http_helpers");
|
|
21
21
|
const capture_console_logs_1 = __importDefault(require("capture-console-logs"));
|
|
22
22
|
const utils_2 = require("../../../../utils");
|
|
23
|
+
const constants_1 = require("../../constants");
|
|
23
24
|
const { types } = require("util");
|
|
24
25
|
const process_modify_response_action = (action, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
26
|
const allowed_handlers = [proxy_1.PROXY_HANDLER_TYPE.ON_REQUEST, proxy_1.PROXY_HANDLER_TYPE.ON_RESPONSE_END, proxy_1.PROXY_HANDLER_TYPE.ON_ERROR];
|
|
@@ -47,18 +48,32 @@ const process_modify_response_action = (action, ctx) => __awaiter(void 0, void 0
|
|
|
47
48
|
}
|
|
48
49
|
if (action.responseType &&
|
|
49
50
|
action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.CODE) {
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
const contentTypeHeader = (0, proxy_ctx_helper_1.getResponseContentTypeHeader)(ctx);
|
|
52
|
+
const contentType = (0, http_helpers_1.getContentType)(contentTypeHeader);
|
|
53
|
+
if (constants_1.RQ_INTERCEPTED_CONTENT_TYPES.includes(contentType) || contentType == null) {
|
|
54
|
+
yield modify_response_using_code(action, ctx);
|
|
55
|
+
delete_breaking_headers(ctx);
|
|
56
|
+
return (0, utils_1.build_action_processor_response)(action, true);
|
|
57
|
+
}
|
|
58
|
+
// Sentry not working
|
|
59
|
+
// Sentry.captureException(new Error(`Content Type ${contentType} not supported for modification in programmatic mode`));
|
|
60
|
+
console.log(`Content Type ${contentType} not supported for modification in programmatic mode`);
|
|
61
|
+
return (0, utils_1.build_action_processor_response)(action, false);
|
|
52
62
|
}
|
|
53
63
|
else if (action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.LOCAL_FILE) {
|
|
54
64
|
modify_response_using_local(action, ctx);
|
|
65
|
+
delete_breaking_headers(ctx);
|
|
55
66
|
return (0, utils_1.build_action_processor_response)(action, true);
|
|
56
67
|
}
|
|
57
68
|
else {
|
|
58
69
|
modify_response(ctx, action.response, action.statusCode);
|
|
70
|
+
delete_breaking_headers(ctx);
|
|
59
71
|
return (0, utils_1.build_action_processor_response)(action, true);
|
|
60
72
|
}
|
|
61
73
|
});
|
|
74
|
+
const delete_breaking_headers = (ctx) => {
|
|
75
|
+
delete (0, proxy_ctx_helper_1.getResponseHeaders)(ctx)['content-length'];
|
|
76
|
+
};
|
|
62
77
|
const modify_response = (ctx, new_resp, status_code) => {
|
|
63
78
|
ctx.rq_response_body = new_resp;
|
|
64
79
|
ctx.rq_response_status_code = status_code;
|
|
@@ -97,7 +112,7 @@ const modify_response_using_code = (action, ctx) => __awaiter(void 0, void 0, vo
|
|
|
97
112
|
? ctx.clientToProxyRequest.method
|
|
98
113
|
: null
|
|
99
114
|
: null,
|
|
100
|
-
response: ctx === null || ctx === void 0 ? void 0 : ctx.
|
|
115
|
+
response: ctx === null || ctx === void 0 ? void 0 : ctx.rq_parsed_response_body,
|
|
101
116
|
url: (0, proxy_ctx_helper_1.get_request_url)(ctx),
|
|
102
117
|
responseType: (_c = (_b = ctx === null || ctx === void 0 ? void 0 : ctx.serverToProxyResponse) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c["content-type"],
|
|
103
118
|
requestHeaders: ctx.clientToProxyRequest.headers,
|