Skip to content

Commit 099ffd3

Browse files
committed
chore: bump version to 1.1.20 and update dist
1 parent f1473b0 commit 099ffd3

File tree

8 files changed

+112
-36
lines changed

8 files changed

+112
-36
lines changed

dist/components/proxy-middleware/helpers/harObectCreator.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function createRequestHarObject(requestHarObject: any, proxyToServerReque
99
url: any;
1010
postData: any;
1111
};
12-
export function createHar(requestHeaders: any, method: any, protocol: any, host: any, path: any, requestBody: any, responseStatusCode: any, response: any, responseHeaders: any): {
12+
export function createHar(requestHeaders: any, method: any, protocol: any, host: any, path: any, requestBody: any, responseStatusCode: any, response: any, responseHeaders: any, requestParams: any): {
1313
log: {
1414
version: string;
1515
creator: {};
@@ -60,7 +60,7 @@ export function createHar(requestHeaders: any, method: any, protocol: any, host:
6060
comment: string;
6161
};
6262
};
63-
export function createHarEntry(requestHeaders: any, method: any, protocol: any, host: any, path: any, requestBody: any, responseStatusCode: any, response: any, responseHeaders: any): {
63+
export function createHarEntry(requestHeaders: any, method: any, protocol: any, host: any, path: any, requestBody: any, responseStatusCode: any, response: any, responseHeaders: any, requestParams: any): {
6464
startedDateTime: string;
6565
request: {
6666
bodySize: number;
@@ -102,7 +102,7 @@ export function createHarEntry(requestHeaders: any, method: any, protocol: any,
102102
timings: {};
103103
comment: string;
104104
};
105-
export function createHarRequest(requestHeaders: any, method: any, protocol: any, host: any, path: any, requestBody: any): {
105+
export function createHarRequest(requestHeaders: any, method: any, protocol: any, host: any, path: any, requestBody: any, requestParams: any): {
106106
bodySize: number;
107107
headersSize: number;
108108
httpVersion: string;

dist/components/proxy-middleware/helpers/harObectCreator.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,26 @@ const createHarHeaders = (request_headers_obj) => {
1414
}
1515
return headers;
1616
};
17-
const createHarQueryStrings = (path) => {
18-
// TODO -> http://www.softwareishard.com/blog/har-12-spec/#queryString
19-
return [];
17+
const createHarQueryStrings = (query_params) => {
18+
let res = [];
19+
Object.keys(query_params).forEach(query => {
20+
const query_value = query_params[query];
21+
if (Array.isArray(query_value)) {
22+
query_value.forEach(val => {
23+
res.push({
24+
"name": query,
25+
"value": val
26+
});
27+
});
28+
}
29+
else {
30+
res.push({
31+
"name": query,
32+
"value": query_value
33+
});
34+
}
35+
});
36+
return res;
2037
};
2138
const getContentType = (headers) => {
2239
let contentType = null;
@@ -78,40 +95,40 @@ const createHarPostData = (body, headers) => {
7895
// create standard request har object: http://www.softwareishard.com/blog/har-12-spec/#request
7996
// URL: https://github.com/hoppscotch/hoppscotch/blob/75ab7fdb00c0129ad42d45165bd3ad0af1faca2e/packages/hoppscotch-app/helpers/new-codegen/har.ts#L26
8097
const createRequestHarObject = (requestHarObject, proxyToServerRequestOptions) => {
81-
const { method, host, path, body, headers, agent, } = proxyToServerRequestOptions;
98+
const { method, host, path, body, headers, agent, query_params } = proxyToServerRequestOptions;
8299
return {
83100
bodySize: -1,
84101
headersSize: -1,
85102
httpVersion: "HTTP/1.1",
86103
cookies: [],
87104
headers: requestHarObject.headers || createHarHeaders(headers),
88105
method: requestHarObject.method || method,
89-
queryString: requestHarObject.queryString || createHarQueryStrings(path),
106+
queryString: requestHarObject.queryString || createHarQueryStrings(query_params),
90107
url: requestHarObject.url || ((agent === null || agent === void 0 ? void 0 : agent.protocol) || "http:") + "//" + host + path,
91108
postData: requestHarObject.postData ||
92109
createHarPostData(body, requestHarObject.headers),
93110
};
94111
};
95112
exports.createRequestHarObject = createRequestHarObject;
96-
const createHar = (requestHeaders, method, protocol, host, path, requestBody, responseStatusCode, response, responseHeaders) => {
113+
const createHar = (requestHeaders, method, protocol, host, path, requestBody, responseStatusCode, response, responseHeaders, requestParams) => {
97114
return {
98115
"log": {
99116
"version": "1.2",
100117
"creator": {},
101118
"browser": {},
102119
"pages": [],
103-
"entries": [(0, exports.createHarEntry)(requestHeaders, method, protocol, host, path, requestBody, responseStatusCode, response, responseHeaders)],
120+
"entries": [(0, exports.createHarEntry)(requestHeaders, method, protocol, host, path, requestBody, responseStatusCode, response, responseHeaders, requestParams)],
104121
"comment": ""
105122
}
106123
};
107124
};
108125
exports.createHar = createHar;
109-
const createHarEntry = (requestHeaders, method, protocol, host, path, requestBody, responseStatusCode, response, responseHeaders) => {
126+
const createHarEntry = (requestHeaders, method, protocol, host, path, requestBody, responseStatusCode, response, responseHeaders, requestParams) => {
110127
return {
111128
// "pageref": "page_0",
112129
"startedDateTime": new Date().toISOString(),
113130
// "time": 50,
114-
"request": (0, exports.createHarRequest)(requestHeaders, method, protocol, host, path, requestBody),
131+
"request": (0, exports.createHarRequest)(requestHeaders, method, protocol, host, path, requestBody, requestParams),
115132
"response": (0, exports.createHarResponse)(responseStatusCode, response, responseHeaders),
116133
"cache": {},
117134
"timings": {},
@@ -121,15 +138,15 @@ const createHarEntry = (requestHeaders, method, protocol, host, path, requestBod
121138
};
122139
};
123140
exports.createHarEntry = createHarEntry;
124-
const createHarRequest = (requestHeaders, method, protocol, host, path, requestBody) => {
141+
const createHarRequest = (requestHeaders, method, protocol, host, path, requestBody, requestParams) => {
125142
return {
126143
bodySize: -1,
127144
headersSize: -1,
128145
httpVersion: "HTTP/1.1",
129146
cookies: [],
130147
headers: createHarHeaders(requestHeaders),
131148
method: method,
132-
queryString: createHarQueryStrings(path),
149+
queryString: createHarQueryStrings(requestParams),
133150
url: protocol + "://" + host + path,
134151
postData: createHarPostData(requestBody, createHarHeaders(requestHeaders)),
135152
};

dist/components/proxy-middleware/helpers/proxy_ctx_helper.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
*
3+
* @param queryString e.g. ?a=1&b=2 or a=1 or ''
4+
* @returns object { paramName -> [value1, value2] }
5+
*/
6+
export function getQueryParamsMap(queryString: any): {};
17
export function get_request_url(ctx: any): string;
28
export function get_original_request_headers(ctx: any): any;
39
export function get_original_response_headers(ctx: any): any;
@@ -7,6 +13,7 @@ export function get_response_options(ctx: any): {
713
headers: any;
814
};
915
export function get_request_options(ctx: any): any;
16+
export function get_json_query_params(ctx: any): {};
1017
export function getRequestHeaders(ctx: any): any;
1118
export function getRequestContentTypeHeader(ctx: any): any;
1219
export function getResponseHeaders(ctx: any): any;

dist/components/proxy-middleware/helpers/proxy_ctx_helper.js

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,50 @@
66
// } from "../../../../../../../common/components/utils/utils";
77
// const CONSTANTS = require("../../../../../../../common/constants");
88
Object.defineProperty(exports, "__esModule", { value: true });
9-
exports.getResponseStatusCode = exports.getResponseContentTypeHeader = exports.getResponseHeaders = exports.getRequestContentTypeHeader = exports.getRequestHeaders = 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;
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 = exports.getQueryParamsMap = void 0;
10+
const requestly_core_1 = require("@requestly/requestly-core");
11+
function extractUrlComponent(url, name) {
12+
const myUrl = new URL(url);
13+
switch (name) {
14+
case requestly_core_1.CONSTANTS.URL_COMPONENTS.URL:
15+
return url;
16+
case requestly_core_1.CONSTANTS.URL_COMPONENTS.PROTOCOL:
17+
return myUrl.protocol;
18+
case requestly_core_1.CONSTANTS.URL_COMPONENTS.HOST:
19+
return myUrl.host;
20+
case requestly_core_1.CONSTANTS.URL_COMPONENTS.PATH:
21+
return myUrl.pathname;
22+
case requestly_core_1.CONSTANTS.URL_COMPONENTS.QUERY:
23+
return myUrl.search;
24+
case requestly_core_1.CONSTANTS.URL_COMPONENTS.HASH:
25+
return myUrl.hash;
26+
}
27+
console.error("Invalid source key", url, name);
28+
}
29+
/**
30+
*
31+
* @param queryString e.g. ?a=1&b=2 or a=1 or ''
32+
* @returns object { paramName -> [value1, value2] }
33+
*/
34+
function getQueryParamsMap(queryString) {
35+
var map = {}, queryParams;
36+
if (!queryString || queryString === "?") {
37+
return map;
38+
}
39+
if (queryString[0] === "?") {
40+
queryString = queryString.substr(1);
41+
}
42+
queryParams = queryString.split("&");
43+
queryParams.forEach(function (queryParam) {
44+
var paramName = queryParam.split("=")[0], paramValue = queryParam.split("=")[1];
45+
// We are keeping value of param as array so that in future we can support multiple param values of same name
46+
// And we do not want to lose the params if url already contains multiple params of same name
47+
map[paramName] = map[paramName] || [];
48+
map[paramName].push(paramValue);
49+
});
50+
return map;
51+
}
52+
exports.getQueryParamsMap = getQueryParamsMap;
1053
const get_request_url = (ctx) => {
1154
return ((ctx.isSSL ? "https://" : "http://") +
1255
ctx.clientToProxyRequest.headers.host +
@@ -49,14 +92,15 @@ const get_response_options = (ctx) => {
4992
};
5093
exports.get_response_options = get_response_options;
5194
const get_request_options = (ctx) => {
52-
return Object.assign({}, ctx.proxyToServerRequestOptions);
95+
return Object.assign(Object.assign({}, ctx.proxyToServerRequestOptions), { query_params: (0, exports.get_json_query_params)(ctx) });
5396
};
5497
exports.get_request_options = get_request_options;
55-
// export const get_json_query_params = (ctx) => {
56-
// const url = get_request_url(ctx);
57-
// let queryString = extractUrlComponent(url, CONSTANTS.URL_COMPONENTS.QUERY);
58-
// return getQueryParamsMap(queryString) || null;
59-
// };
98+
const get_json_query_params = (ctx) => {
99+
const url = (0, exports.get_request_url)(ctx);
100+
let queryString = extractUrlComponent(url, requestly_core_1.CONSTANTS.URL_COMPONENTS.QUERY);
101+
return getQueryParamsMap(queryString) || null;
102+
};
103+
exports.get_json_query_params = get_json_query_params;
60104
const getRequestHeaders = (ctx) => {
61105
if (ctx && ctx.proxyToServerRequestOptions) {
62106
return ctx.proxyToServerRequestOptions.headers || {};

dist/components/proxy-middleware/index.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,11 @@ class ProxyMiddlewareManager {
160160
const contentTypeHeader = (0, proxy_ctx_helper_1.getResponseContentTypeHeader)(ctx);
161161
const contentType = (0, http_helpers_1.getContentType)(contentTypeHeader);
162162
const parsedBody = (0, http_helpers_1.bodyParser)(contentTypeHeader, body);
163+
ctx.rq.set_original_response({ body: parsedBody });
163164
ctx.rq_response_body = body;
165+
ctx.rq_parsed_response_body = parsedBody;
164166
ctx.rq_response_status_code = (0, proxy_ctx_helper_1.getResponseStatusCode)(ctx);
165-
if (constants_1.RQ_INTERCEPTED_CONTENT_TYPES.includes(contentType) && parsedBody) {
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);
175168
const statusCode = ctx.rq_response_status_code || (0, proxy_ctx_helper_1.getResponseStatusCode)(ctx);
176169
ctx.proxyToClientResponse.writeHead(statusCode, http_1.default.STATUS_CODES[statusCode], (0, proxy_ctx_helper_1.getResponseHeaders)(ctx));
177170
ctx.proxyToClientResponse.write(ctx.rq_response_body);

dist/components/proxy-middleware/middlewares/logger_middleware.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class LoggerMiddleware {
7575
const rqLog = {
7676
id: ctx.uuid,
7777
timestamp: Math.floor(Date.now() / 1000),
78-
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 || {}),
78+
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),
7979
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),
8080
actions: (0, utils_1.get_success_actions_from_action_results)(action_result_objs),
8181
consoleLogs: (_c = ctx === null || ctx === void 0 ? void 0 : ctx.rq) === null || _c === void 0 ? void 0 : _c.consoleLogs,

dist/components/proxy-middleware/rule_action_processor/processors/modify_response_processor.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const fs_1 = __importDefault(require("fs"));
2020
const http_helpers_1 = require("../../helpers/http_helpers");
2121
const capture_console_logs_1 = __importDefault(require("capture-console-logs"));
2222
const utils_2 = require("../../../../utils");
23+
const constants_1 = require("../../constants");
2324
const { types } = require("util");
2425
const process_modify_response_action = (action, ctx) => __awaiter(void 0, void 0, void 0, function* () {
2526
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
4748
}
4849
if (action.responseType &&
4950
action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.CODE) {
50-
yield modify_response_using_code(action, ctx);
51-
return (0, utils_1.build_action_processor_response)(action, true);
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);
5262
}
5363
else if (action.responseType === requestly_core_1.CONSTANTS.RESPONSE_BODY_TYPES.LOCAL_FILE) {
5464
modify_response_using_local(action, ctx);
65+
delete_breaking_headers(ctx);
5566
return (0, utils_1.build_action_processor_response)(action, true);
5667
}
5768
else {
5869
modify_response(ctx, action.response, action.statusCode);
70+
delete_breaking_headers(ctx);
5971
return (0, utils_1.build_action_processor_response)(action, true);
6072
}
6173
});
74+
const delete_breaking_headers = (ctx) => {
75+
delete (0, proxy_ctx_helper_1.getResponseHeaders)(ctx)['content-length'];
76+
};
6277
const modify_response = (ctx, new_resp, status_code) => {
6378
ctx.rq_response_body = new_resp;
6479
ctx.rq_response_status_code = status_code;
@@ -97,7 +112,7 @@ const modify_response_using_code = (action, ctx) => __awaiter(void 0, void 0, vo
97112
? ctx.clientToProxyRequest.method
98113
: null
99114
: null,
100-
response: ctx === null || ctx === void 0 ? void 0 : ctx.rq_response_body,
115+
response: ctx === null || ctx === void 0 ? void 0 : ctx.rq_parsed_response_body,
101116
url: (0, proxy_ctx_helper_1.get_request_url)(ctx),
102117
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"],
103118
requestHeaders: ctx.clientToProxyRequest.headers,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@requestly/requestly-proxy",
3-
"version": "1.1.19",
3+
"version": "1.1.20",
44
"description": "Proxy that gives superpowers to all the Requestly clients",
55
"main": "dist/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)