@requestly/requestly-proxy 1.3.2 → 1.3.4
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/constants.d.ts +8 -8
- package/dist/components/proxy-middleware/helpers/ctx_rq_namespace.js +4 -4
- package/dist/components/proxy-middleware/helpers/harObectCreator.js +7 -7
- package/dist/components/proxy-middleware/helpers/proxy_ctx_helper.js +6 -9
- package/dist/components/proxy-middleware/helpers/rule_processor_helper.js +2 -2
- package/dist/components/proxy-middleware/index.d.ts +5 -5
- package/dist/components/proxy-middleware/index.js +97 -114
- package/dist/components/proxy-middleware/middlewares/amiusing_middleware.js +2 -11
- package/dist/components/proxy-middleware/middlewares/logger_middleware.js +12 -16
- package/dist/components/proxy-middleware/middlewares/rules_middleware.js +20 -26
- package/dist/components/proxy-middleware/middlewares/ssl_cert_middleware.js +2 -11
- package/dist/components/proxy-middleware/rule_action_processor/handle_mixed_response.js +3 -12
- package/dist/components/proxy-middleware/rule_action_processor/index.js +9 -18
- package/dist/components/proxy-middleware/rule_action_processor/processors/block_processor.js +2 -11
- package/dist/components/proxy-middleware/rule_action_processor/processors/delay_processor.js +5 -14
- package/dist/components/proxy-middleware/rule_action_processor/processors/modify_request_processor.js +3 -12
- package/dist/components/proxy-middleware/rule_action_processor/processors/modify_response_processor.js +11 -20
- package/dist/components/proxy-middleware/rule_action_processor/processors/redirect_processor.js +3 -12
- package/dist/components/ssl-proxying/ssl-proxying-manager.js +5 -0
- package/dist/lib/proxy/index.d.ts +2 -2
- package/dist/lib/proxy/index.js +31 -1
- package/dist/lib/proxy/lib/middleware/gunzip.js +2 -1
- package/dist/lib/proxy/lib/middleware/wildcard.js +2 -1
- package/dist/lib/proxy/lib/proxy.d.ts +5 -5
- package/dist/test.js +5 -14
- package/dist/utils/helpers/rules-helper.js +10 -19
- package/dist/utils/index.js +31 -42
- package/package.json +14 -4
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export namespace RULE_ACTION {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
let REDIRECT: string;
|
|
3
|
+
let MODIFY_HEADERS: string;
|
|
4
|
+
let MODIFY_USER_AGENT: string;
|
|
5
|
+
let BLOCK: string;
|
|
6
|
+
let INSERT: string;
|
|
7
|
+
let DELAY: string;
|
|
8
|
+
let MODIFY_RESPONSE: string;
|
|
9
|
+
let MODIFY_REQUEST: string;
|
|
10
10
|
}
|
|
11
11
|
export const RQ_INTERCEPTED_CONTENT_TYPES: string[];
|
|
@@ -5,7 +5,7 @@ class CtxRQNamespace {
|
|
|
5
5
|
constructor() {
|
|
6
6
|
this.set_original_request = ({ method = null, path = null, host = null, port = null, headers = null, agent = null, body = null, query_params = null, }) => {
|
|
7
7
|
if (headers) {
|
|
8
|
-
this.original_request.headers =
|
|
8
|
+
this.original_request.headers = { ...headers };
|
|
9
9
|
}
|
|
10
10
|
this.original_request.method = method || this.original_request.method;
|
|
11
11
|
this.original_request.path = path || this.original_request.path;
|
|
@@ -18,7 +18,7 @@ class CtxRQNamespace {
|
|
|
18
18
|
};
|
|
19
19
|
this.set_original_response = ({ status_code = null, headers = null, body = null, query_params = null, }) => {
|
|
20
20
|
if (headers) {
|
|
21
|
-
this.original_response.headers =
|
|
21
|
+
this.original_response.headers = { ...headers };
|
|
22
22
|
}
|
|
23
23
|
this.original_response.status_code =
|
|
24
24
|
status_code || this.original_response.status_code;
|
|
@@ -27,7 +27,7 @@ class CtxRQNamespace {
|
|
|
27
27
|
this.set_final_request = (proxyToServerRequestOptions) => {
|
|
28
28
|
const { method, path, host, port, headers, agent, body, query_params, } = proxyToServerRequestOptions;
|
|
29
29
|
if (headers) {
|
|
30
|
-
this.final_request.headers =
|
|
30
|
+
this.final_request.headers = { ...headers };
|
|
31
31
|
}
|
|
32
32
|
this.final_request.method = method || this.final_request.method;
|
|
33
33
|
this.final_request.path = path || this.final_request.path;
|
|
@@ -41,7 +41,7 @@ class CtxRQNamespace {
|
|
|
41
41
|
};
|
|
42
42
|
this.set_final_response = ({ status_code = null, headers = null, body = null, }) => {
|
|
43
43
|
if (headers) {
|
|
44
|
-
this.final_response.headers =
|
|
44
|
+
this.final_response.headers = { ...headers };
|
|
45
45
|
}
|
|
46
46
|
this.final_response.status_code =
|
|
47
47
|
status_code || this.final_response.status_code;
|
|
@@ -88,7 +88,7 @@ const createHarPostData = (body, headers) => {
|
|
|
88
88
|
// };
|
|
89
89
|
// }
|
|
90
90
|
return {
|
|
91
|
-
mimeType: contentType,
|
|
91
|
+
mimeType: contentType, // Let's assume by default content type is JSON
|
|
92
92
|
text: body,
|
|
93
93
|
};
|
|
94
94
|
};
|
|
@@ -97,10 +97,10 @@ const createHarPostData = (body, headers) => {
|
|
|
97
97
|
const createRequestHarObject = (requestHarObject, proxyToServerRequestOptions) => {
|
|
98
98
|
const { method, host, path, body, headers, agent, query_params } = proxyToServerRequestOptions;
|
|
99
99
|
return {
|
|
100
|
-
bodySize: -1,
|
|
101
|
-
headersSize: -1,
|
|
100
|
+
bodySize: -1, // TODO: calculate the body size
|
|
101
|
+
headersSize: -1, // TODO: calculate the header size
|
|
102
102
|
httpVersion: "HTTP/1.1",
|
|
103
|
-
cookies: [],
|
|
103
|
+
cookies: [], // TODO: add support for Cookies
|
|
104
104
|
headers: requestHarObject.headers || createHarHeaders(headers),
|
|
105
105
|
method: requestHarObject.method || method,
|
|
106
106
|
queryString: requestHarObject.queryString || createHarQueryStrings(query_params),
|
|
@@ -140,10 +140,10 @@ const createHarEntry = (requestHeaders, method, protocol, host, path, requestBod
|
|
|
140
140
|
exports.createHarEntry = createHarEntry;
|
|
141
141
|
const createHarRequest = (requestHeaders, method, protocol, host, path, requestBody, requestParams) => {
|
|
142
142
|
return {
|
|
143
|
-
bodySize: -1,
|
|
144
|
-
headersSize: -1,
|
|
143
|
+
bodySize: -1, // TODO: calculate the body size
|
|
144
|
+
headersSize: -1, // TODO: calculate the header size
|
|
145
145
|
httpVersion: "HTTP/1.1",
|
|
146
|
-
cookies: [],
|
|
146
|
+
cookies: [], // TODO: add support for Cookies
|
|
147
147
|
headers: createHarHeaders(requestHeaders),
|
|
148
148
|
method: method,
|
|
149
149
|
queryString: createHarQueryStrings(requestParams),
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// TODO: Removing this for now
|
|
3
|
-
// import {
|
|
4
|
-
// extractUrlComponent,
|
|
5
|
-
// getQueryParamsMap,
|
|
6
|
-
// } from "../../../../../../../common/components/utils/utils";
|
|
7
|
-
// const CONSTANTS = require("../../../../../../../common/constants");
|
|
8
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.getResponseStatusCode = exports.getResponseContentTypeHeader = exports.getResponseHeaders = exports.getRequestContentTypeHeader = exports.getRequestHeaders = exports.get_json_query_params = exports.get_request_options = exports.get_response_options = exports.is_request_preflight = exports.get_original_response_headers = exports.get_original_request_headers = exports.get_request_url =
|
|
3
|
+
exports.getResponseStatusCode = exports.getResponseContentTypeHeader = exports.getResponseHeaders = exports.getRequestContentTypeHeader = exports.getRequestHeaders = exports.get_json_query_params = exports.get_request_options = exports.get_response_options = exports.is_request_preflight = exports.get_original_response_headers = exports.get_original_request_headers = exports.get_request_url = void 0;
|
|
4
|
+
exports.getQueryParamsMap = getQueryParamsMap;
|
|
10
5
|
const requestly_core_1 = require("@requestly/requestly-core");
|
|
11
6
|
function extractUrlComponent(url, name) {
|
|
12
7
|
const myUrl = new URL(url);
|
|
@@ -49,7 +44,6 @@ function getQueryParamsMap(queryString) {
|
|
|
49
44
|
});
|
|
50
45
|
return map;
|
|
51
46
|
}
|
|
52
|
-
exports.getQueryParamsMap = getQueryParamsMap;
|
|
53
47
|
const get_request_url = (ctx) => {
|
|
54
48
|
return ((ctx.isSSL ? "https://" : "http://") +
|
|
55
49
|
ctx.clientToProxyRequest.headers.host +
|
|
@@ -92,7 +86,10 @@ const get_response_options = (ctx) => {
|
|
|
92
86
|
};
|
|
93
87
|
exports.get_response_options = get_response_options;
|
|
94
88
|
const get_request_options = (ctx) => {
|
|
95
|
-
return
|
|
89
|
+
return {
|
|
90
|
+
...ctx.proxyToServerRequestOptions,
|
|
91
|
+
query_params: (0, exports.get_json_query_params)(ctx),
|
|
92
|
+
};
|
|
96
93
|
};
|
|
97
94
|
exports.get_request_options = get_request_options;
|
|
98
95
|
const get_json_query_params = (ctx) => {
|
|
@@ -79,7 +79,7 @@ class RuleProcessorHelper {
|
|
|
79
79
|
const rule_action = rule_processor.process({
|
|
80
80
|
rule,
|
|
81
81
|
requestURL: this.request_data.request_url,
|
|
82
|
-
details:
|
|
82
|
+
details: { ...this.request_data, requestData },
|
|
83
83
|
});
|
|
84
84
|
return rule_action;
|
|
85
85
|
};
|
|
@@ -94,7 +94,7 @@ class RuleProcessorHelper {
|
|
|
94
94
|
const rule_action = rule_processor.process({
|
|
95
95
|
rule,
|
|
96
96
|
requestURL: this.request_data.request_url,
|
|
97
|
-
details:
|
|
97
|
+
details: { ...this.request_data, requestData },
|
|
98
98
|
});
|
|
99
99
|
return rule_action;
|
|
100
100
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export namespace MIDDLEWARE_TYPE {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
let AMIUSING: string;
|
|
3
|
+
let RULES: string;
|
|
4
|
+
let LOGGER: string;
|
|
5
|
+
let SSL_CERT: string;
|
|
6
|
+
let GLOBAL_STATE: string;
|
|
7
7
|
}
|
|
8
8
|
export default ProxyMiddlewareManager;
|
|
9
9
|
declare class ProxyMiddlewareManager {
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -82,106 +73,100 @@ class ProxyMiddlewareManager {
|
|
|
82
73
|
const self = this;
|
|
83
74
|
const is_detachable = true;
|
|
84
75
|
const logger_middleware = new logger_middleware_1.default(this.config[exports.MIDDLEWARE_TYPE.LOGGER], this.loggerService);
|
|
85
|
-
const idx = this.init_request_handler((ctx, callback) =>
|
|
76
|
+
const idx = this.init_request_handler(async (ctx, callback) => {
|
|
86
77
|
ctx.rq = new ctx_rq_namespace_1.default();
|
|
87
78
|
ctx.rq.set_original_request((0, proxy_ctx_helper_1.get_request_options)(ctx));
|
|
88
79
|
ctx.proxyToServerRequestOptions.rejectUnauthorized = false;
|
|
89
80
|
// Figure out a way to enable/disable middleware dynamically
|
|
90
81
|
// instead of re-initing this again
|
|
91
82
|
const rules_middleware = new rules_middleware_1.default(this.config[exports.MIDDLEWARE_TYPE.RULES], ctx, this.rulesHelper);
|
|
92
|
-
ctx.onError(function (ctx, err, kind, callback) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return callback();
|
|
112
|
-
});
|
|
83
|
+
ctx.onError(async function (ctx, err, kind, callback) {
|
|
84
|
+
// Should only modify response body & headers
|
|
85
|
+
ctx.rq_response_body = "" + kind + ": " + err, "utf8";
|
|
86
|
+
const { action_result_objs, continue_request } = await rules_middleware.on_response(ctx);
|
|
87
|
+
// Only modify response if any modify_response action is applied
|
|
88
|
+
const modifyResponseActionExist = action_result_objs.some((action_result_obj) => { var _a; return ((_a = action_result_obj === null || action_result_obj === void 0 ? void 0 : action_result_obj.action) === null || _a === void 0 ? void 0 : _a.action) === "modify_response"; });
|
|
89
|
+
if (modifyResponseActionExist) {
|
|
90
|
+
const statusCode = ctx.rq_response_status_code || 404;
|
|
91
|
+
const responseHeaders = (0, proxy_ctx_helper_1.getResponseHeaders)(ctx) || {};
|
|
92
|
+
ctx.proxyToClientResponse.writeHead(statusCode, http_1.default.STATUS_CODES[statusCode], responseHeaders);
|
|
93
|
+
ctx.proxyToClientResponse.end(ctx.rq_response_body);
|
|
94
|
+
ctx.rq.set_final_response({
|
|
95
|
+
status_code: statusCode,
|
|
96
|
+
headers: responseHeaders,
|
|
97
|
+
body: ctx.rq_response_body,
|
|
98
|
+
});
|
|
99
|
+
logger_middleware.send_network_log(ctx, rules_middleware.action_result_objs, requestly_core_1.CONSTANTS.REQUEST_STATE.COMPLETE);
|
|
100
|
+
}
|
|
101
|
+
return callback();
|
|
113
102
|
});
|
|
114
103
|
let request_body_chunks = [];
|
|
115
|
-
ctx.onRequestData(function (ctx, chunk, callback) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return callback(null, null); // don't write chunks to client Request
|
|
121
|
-
});
|
|
104
|
+
ctx.onRequestData(async function (ctx, chunk, callback) {
|
|
105
|
+
if (chunk) {
|
|
106
|
+
request_body_chunks.push(chunk);
|
|
107
|
+
}
|
|
108
|
+
return callback(null, null); // don't write chunks to client Request
|
|
122
109
|
});
|
|
123
|
-
ctx.onRequestEnd(function (ctx, callback) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return callback();
|
|
141
|
-
});
|
|
110
|
+
ctx.onRequestEnd(async function (ctx, callback) {
|
|
111
|
+
let body = new Buffer.concat(request_body_chunks);
|
|
112
|
+
const contentTypeHeader = (0, proxy_ctx_helper_1.getRequestContentTypeHeader)(ctx);
|
|
113
|
+
const contentType = (0, http_helpers_1.getContentType)(contentTypeHeader);
|
|
114
|
+
const parsedBody = (0, http_helpers_1.bodyParser)(contentTypeHeader, body);
|
|
115
|
+
// Request body before any modifications
|
|
116
|
+
let pre_final_body = parsedBody || body.toString("utf8");
|
|
117
|
+
ctx.rq.set_original_request({ body: pre_final_body });
|
|
118
|
+
ctx.rq_request_body = pre_final_body;
|
|
119
|
+
if (parsedBody && constants_1.RQ_INTERCEPTED_CONTENT_TYPES.includes(contentType)) {
|
|
120
|
+
// Do modifications, if any
|
|
121
|
+
const { action_result_objs, continue_request } = await rules_middleware.on_request_end(ctx);
|
|
122
|
+
}
|
|
123
|
+
// Use the updated request
|
|
124
|
+
ctx.proxyToServerRequest.write(ctx.rq_request_body);
|
|
125
|
+
ctx.rq.set_final_request({ body: ctx.rq_request_body });
|
|
126
|
+
return callback();
|
|
142
127
|
});
|
|
143
|
-
ctx.onResponse((ctx, callback) =>
|
|
128
|
+
ctx.onResponse(async (ctx, callback) => {
|
|
144
129
|
ctx.rq.set_original_response((0, proxy_ctx_helper_1.get_response_options)(ctx));
|
|
145
|
-
const { action_result_objs, continue_request: continue_response } =
|
|
130
|
+
const { action_result_objs, continue_request: continue_response } = await rules_middleware.on_response(ctx);
|
|
146
131
|
if (continue_response) {
|
|
147
132
|
return callback();
|
|
148
133
|
}
|
|
149
|
-
})
|
|
134
|
+
});
|
|
150
135
|
let response_body_chunks = [];
|
|
151
|
-
ctx.onResponseData(function (ctx, chunk, callback) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return callback(null, null); // don't write chunks to client response
|
|
157
|
-
});
|
|
136
|
+
ctx.onResponseData(async function (ctx, chunk, callback) {
|
|
137
|
+
if (chunk) {
|
|
138
|
+
response_body_chunks.push(chunk);
|
|
139
|
+
}
|
|
140
|
+
return callback(null, null); // don't write chunks to client response
|
|
158
141
|
});
|
|
159
|
-
ctx.onResponseEnd(function (ctx, callback) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
142
|
+
ctx.onResponseEnd(async function (ctx, callback) {
|
|
143
|
+
let body = new Buffer.concat(response_body_chunks);
|
|
144
|
+
const contentTypeHeader = (0, proxy_ctx_helper_1.getResponseContentTypeHeader)(ctx);
|
|
145
|
+
const contentType = (0, http_helpers_1.getContentType)(contentTypeHeader);
|
|
146
|
+
const parsedBody = (0, http_helpers_1.bodyParser)(contentTypeHeader, body);
|
|
147
|
+
ctx.rq.set_original_response({ body: parsedBody });
|
|
148
|
+
ctx.rq_response_body = body;
|
|
149
|
+
ctx.rq_parsed_response_body = parsedBody;
|
|
150
|
+
ctx.rq_response_status_code = (0, proxy_ctx_helper_1.getResponseStatusCode)(ctx);
|
|
151
|
+
if (constants_1.RQ_INTERCEPTED_CONTENT_TYPES.includes(contentType) && parsedBody) {
|
|
152
|
+
ctx.rq_response_body = parsedBody;
|
|
165
153
|
ctx.rq.set_original_response({ body: parsedBody });
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
ctx.proxyToClientResponse.writeHead(statusCode, http_1.default.STATUS_CODES[statusCode], (0, proxy_ctx_helper_1.getResponseHeaders)(ctx));
|
|
176
|
-
ctx.proxyToClientResponse.write(ctx.rq_response_body);
|
|
177
|
-
ctx.rq.set_final_response(Object.assign(Object.assign({}, (0, proxy_ctx_helper_1.get_response_options)(ctx)), { status_code: ctx.rq_response_status_code || (0, proxy_ctx_helper_1.getResponseStatusCode)(ctx), body: ctx.rq_response_body }));
|
|
178
|
-
logger_middleware.send_network_log(ctx, rules_middleware.action_result_objs, requestly_core_1.CONSTANTS.REQUEST_STATE.COMPLETE);
|
|
179
|
-
return callback();
|
|
154
|
+
}
|
|
155
|
+
const { action_result_objs, continue_request } = await rules_middleware.on_response_end(ctx);
|
|
156
|
+
const statusCode = ctx.rq_response_status_code || (0, proxy_ctx_helper_1.getResponseStatusCode)(ctx);
|
|
157
|
+
ctx.proxyToClientResponse.writeHead(statusCode, http_1.default.STATUS_CODES[statusCode], (0, proxy_ctx_helper_1.getResponseHeaders)(ctx));
|
|
158
|
+
ctx.proxyToClientResponse.write(ctx.rq_response_body);
|
|
159
|
+
ctx.rq.set_final_response({
|
|
160
|
+
...(0, proxy_ctx_helper_1.get_response_options)(ctx),
|
|
161
|
+
status_code: ctx.rq_response_status_code || (0, proxy_ctx_helper_1.getResponseStatusCode)(ctx),
|
|
162
|
+
body: ctx.rq_response_body,
|
|
180
163
|
});
|
|
164
|
+
logger_middleware.send_network_log(ctx, rules_middleware.action_result_objs, requestly_core_1.CONSTANTS.REQUEST_STATE.COMPLETE);
|
|
165
|
+
return callback();
|
|
181
166
|
});
|
|
182
167
|
// Remove headers that may conflict
|
|
183
168
|
delete (0, proxy_ctx_helper_1.getRequestHeaders)(ctx)["content-length"];
|
|
184
|
-
const { action_result_objs, continue_request } =
|
|
169
|
+
const { action_result_objs, continue_request } = await rules_middleware.on_request(ctx);
|
|
185
170
|
ctx.rq.set_final_request((0, proxy_ctx_helper_1.get_request_options)(ctx));
|
|
186
171
|
// TODO: Removing this log for now. Will add this when support is added for upsert in firebase logs.
|
|
187
172
|
logger_middleware.send_network_log(ctx, rules_middleware.action_result_objs, requestly_core_1.CONSTANTS.REQUEST_STATE.LOADING);
|
|
@@ -189,10 +174,10 @@ class ProxyMiddlewareManager {
|
|
|
189
174
|
if (continue_request) {
|
|
190
175
|
return callback();
|
|
191
176
|
}
|
|
192
|
-
}
|
|
177
|
+
}, is_detachable);
|
|
193
178
|
};
|
|
194
179
|
this.init_ssl_tunneling_handler = () => {
|
|
195
|
-
this.proxy.onConnect((req, socket, head, callback) =>
|
|
180
|
+
this.proxy.onConnect(async (req, socket, head, callback) => {
|
|
196
181
|
const host = req.url.split(":")[0];
|
|
197
182
|
const port = req.url.split(":")[1];
|
|
198
183
|
const origin = `https://${host}`;
|
|
@@ -208,29 +193,27 @@ class ProxyMiddlewareManager {
|
|
|
208
193
|
port: port,
|
|
209
194
|
host: host,
|
|
210
195
|
allowHalfOpen: false,
|
|
211
|
-
}, function () {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
socket.pipe(conn);
|
|
233
|
-
});
|
|
196
|
+
}, async function () {
|
|
197
|
+
conn.on("finish", () => {
|
|
198
|
+
console.log(`Finish ${host}`);
|
|
199
|
+
socket.destroy();
|
|
200
|
+
delete global.rq.sslTunnelingSocketsMap[req.url];
|
|
201
|
+
});
|
|
202
|
+
socket.on("close", () => {
|
|
203
|
+
console.log("Close");
|
|
204
|
+
conn.end();
|
|
205
|
+
});
|
|
206
|
+
// socket.on('data', (data) => {
|
|
207
|
+
// // console.log("FROM SOCKET: " + data.toString("ascii") + "\n");
|
|
208
|
+
// console.log("FROM SOCKET: data");
|
|
209
|
+
// });
|
|
210
|
+
// conn.on('data', (data) => {
|
|
211
|
+
// // console.log("FROM CONN: " + data.toString("ascii") + "\n");
|
|
212
|
+
// console.log("FROM CONN: data");
|
|
213
|
+
// });
|
|
214
|
+
socket.write("HTTP/1.1 200 OK\r\n\r\n", "UTF-8", function () {
|
|
215
|
+
conn.pipe(socket);
|
|
216
|
+
socket.pipe(conn);
|
|
234
217
|
});
|
|
235
218
|
});
|
|
236
219
|
conn.on("error", function (err) {
|
|
@@ -239,7 +222,7 @@ class ProxyMiddlewareManager {
|
|
|
239
222
|
socket.on("error", function (err) {
|
|
240
223
|
filterSocketConnReset(err, "CLIENT_TO_PROXY_SOCKET");
|
|
241
224
|
});
|
|
242
|
-
})
|
|
225
|
+
});
|
|
243
226
|
// Since node 0.9.9, ECONNRESET on sockets are no longer hidden
|
|
244
227
|
function filterSocketConnReset(err, socketDescription) {
|
|
245
228
|
if (err.errno === "ECONNRESET") {
|
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
class AmisuingMiddleware {
|
|
13
4
|
constructor(is_active) {
|
|
14
|
-
this.on_request = (ctx) =>
|
|
5
|
+
this.on_request = async (ctx) => {
|
|
15
6
|
if (!this.is_active) {
|
|
16
7
|
return true;
|
|
17
8
|
}
|
|
@@ -20,7 +11,7 @@ class AmisuingMiddleware {
|
|
|
20
11
|
["amiusingrequestly"]: "true",
|
|
21
12
|
});
|
|
22
13
|
}
|
|
23
|
-
}
|
|
14
|
+
};
|
|
24
15
|
this.is_active = is_active;
|
|
25
16
|
}
|
|
26
17
|
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
// import { cloneDeep } from "lodash";
|
|
4
|
+
// import HTTPSnippet from "httpsnippet";
|
|
8
5
|
const utils_1 = require("../rule_action_processor/utils");
|
|
9
6
|
const harObectCreator_1 = require("../helpers/harObectCreator");
|
|
10
|
-
const url = require("url");
|
|
7
|
+
// const url = require("url");
|
|
11
8
|
class LoggerMiddleware {
|
|
12
9
|
constructor(is_active, loggerService) {
|
|
13
10
|
this.generate_curl_from_har = (requestHarObject) => {
|
|
@@ -15,15 +12,14 @@ class LoggerMiddleware {
|
|
|
15
12
|
return "";
|
|
16
13
|
}
|
|
17
14
|
let requestCurl = "";
|
|
18
|
-
try {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
15
|
+
// try {
|
|
16
|
+
// const harObject = cloneDeep(requestHarObject);
|
|
17
|
+
// requestCurl = new HTTPSnippet(harObject).convert("shell", "curl", {
|
|
18
|
+
// indent: " ",
|
|
19
|
+
// });
|
|
20
|
+
// } catch (err) {
|
|
21
|
+
// console.error(`LoggerMiddleware.generate_curl_from_har Error: ${err}`);
|
|
22
|
+
// }
|
|
27
23
|
return requestCurl;
|
|
28
24
|
};
|
|
29
25
|
this.send_network_log = (ctx, action_result_objs = [], requestState = "") => {
|
|
@@ -76,7 +72,7 @@ class LoggerMiddleware {
|
|
|
76
72
|
id: ctx.uuid,
|
|
77
73
|
timestamp: Math.floor(Date.now() / 1000),
|
|
78
74
|
finalHar: (0, harObectCreator_1.createHar)(ctx.rq.final_request.headers, ctx.rq.final_request.method, protocol, ctx.rq.final_request.host, ctx.rq.final_request.path, ctx.rq.final_request.body, ctx.rq.final_response.status_code, ctx.rq.final_response.body, ctx.rq.final_response.headers || {}, ctx.rq.final_request.query_params),
|
|
79
|
-
requestShellCurl: this.generate_curl_from_har((_b = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.rq) === null || _a === void 0 ? void 0 : _a.final_request) === null || _b === void 0 ? void 0 : _b.requestHarObject),
|
|
75
|
+
requestShellCurl: this.generate_curl_from_har((_b = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.rq) === null || _a === void 0 ? void 0 : _a.final_request) === null || _b === void 0 ? void 0 : _b.requestHarObject), // TODO: Move this to client side
|
|
80
76
|
actions: (0, utils_1.get_success_actions_from_action_results)(action_result_objs),
|
|
81
77
|
consoleLogs: (_c = ctx === null || ctx === void 0 ? void 0 : ctx.rq) === null || _c === void 0 ? void 0 : _c.consoleLogs,
|
|
82
78
|
requestState
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -34,13 +25,16 @@ class RulesMiddleware {
|
|
|
34
25
|
this.rule_processor_helper.init_response_data(this.response_data);
|
|
35
26
|
};
|
|
36
27
|
this._update_request_data = (data) => {
|
|
37
|
-
this.request_data =
|
|
28
|
+
this.request_data = {
|
|
29
|
+
...this.request_data,
|
|
30
|
+
...data,
|
|
31
|
+
};
|
|
38
32
|
this.rule_processor_helper.init_request_data(this.request_data);
|
|
39
33
|
};
|
|
40
|
-
this._fetch_rules = () =>
|
|
34
|
+
this._fetch_rules = async () => {
|
|
41
35
|
var _a;
|
|
42
|
-
this.active_rules =
|
|
43
|
-
}
|
|
36
|
+
this.active_rules = await this.rulesHelper.get_rules(true, ((_a = this.request_data) === null || _a === void 0 ? void 0 : _a.request_headers) || {});
|
|
37
|
+
};
|
|
44
38
|
/*
|
|
45
39
|
@return: actions[]
|
|
46
40
|
*/
|
|
@@ -58,44 +52,44 @@ class RulesMiddleware {
|
|
|
58
52
|
this.action_result_objs.concat(action_result_objs);
|
|
59
53
|
}
|
|
60
54
|
};
|
|
61
|
-
this.on_request = (ctx) =>
|
|
55
|
+
this.on_request = async (ctx) => {
|
|
62
56
|
if (!this.is_active) {
|
|
63
57
|
return [];
|
|
64
58
|
}
|
|
65
59
|
// TODO: Remove this. Hack to fix rule not fetching first time.
|
|
66
|
-
|
|
60
|
+
await this._fetch_rules();
|
|
67
61
|
this.on_request_actions = this._process_rules();
|
|
68
|
-
const { action_result_objs, continue_request } =
|
|
62
|
+
const { action_result_objs, continue_request } = await this.rule_action_processor.process_actions(this.on_request_actions, ctx);
|
|
69
63
|
this._update_action_result_objs(action_result_objs);
|
|
70
64
|
return { action_result_objs, continue_request };
|
|
71
|
-
}
|
|
72
|
-
this.on_response = (ctx) =>
|
|
65
|
+
};
|
|
66
|
+
this.on_response = async (ctx) => {
|
|
73
67
|
if (!this.is_active) {
|
|
74
68
|
return [];
|
|
75
69
|
}
|
|
76
70
|
this._init_response_data(ctx);
|
|
77
71
|
this.on_response_actions = this._process_rules(true);
|
|
78
|
-
const { action_result_objs, continue_request } =
|
|
72
|
+
const { action_result_objs, continue_request } = await this.rule_action_processor.process_actions(this.on_response_actions, ctx);
|
|
79
73
|
this._update_action_result_objs(action_result_objs);
|
|
80
74
|
return { action_result_objs, continue_request };
|
|
81
|
-
}
|
|
82
|
-
this.on_request_end = (ctx) =>
|
|
75
|
+
};
|
|
76
|
+
this.on_request_end = async (ctx) => {
|
|
83
77
|
if (!this.is_active) {
|
|
84
78
|
return [];
|
|
85
79
|
}
|
|
86
80
|
this._update_request_data({ request_body: ctx.rq.get_json_request_body() });
|
|
87
|
-
const { action_result_objs, continue_request } =
|
|
81
|
+
const { action_result_objs, continue_request } = await this.rule_action_processor.process_actions(this.on_request_actions, ctx);
|
|
88
82
|
this._update_action_result_objs(action_result_objs);
|
|
89
83
|
return { action_result_objs, continue_request };
|
|
90
|
-
}
|
|
91
|
-
this.on_response_end = (ctx) =>
|
|
84
|
+
};
|
|
85
|
+
this.on_response_end = async (ctx) => {
|
|
92
86
|
if (!this.is_active) {
|
|
93
87
|
return [];
|
|
94
88
|
}
|
|
95
|
-
const { action_result_objs, continue_request } =
|
|
89
|
+
const { action_result_objs, continue_request } = await this.rule_action_processor.process_actions(this.on_response_actions, ctx);
|
|
96
90
|
this._update_action_result_objs(action_result_objs);
|
|
97
91
|
return { action_result_objs, continue_request };
|
|
98
|
-
}
|
|
92
|
+
};
|
|
99
93
|
this.is_active = is_active;
|
|
100
94
|
this.rule_processor_helper = new rule_processor_helper_1.default();
|
|
101
95
|
this.rule_action_processor = new rule_action_processor_1.default();
|