Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

// import { cloneDeep } from "lodash";
// import HTTPSnippet from "httpsnippet";
import { get_success_actions_from_action_results } from "../rule_action_processor/utils";
import { get_success_actions_from_action_results, getHost } from "../rule_action_processor/utils";
import { createHar } from "../helpers/harObectCreator";
// const url = require("url");

Expand All @@ -15,6 +16,7 @@ class LoggerMiddleware {
return "";
}
let requestCurl = "";

// try {
// const harObject = cloneDeep(requestHarObject);
// requestCurl = new HTTPSnippet(harObject).convert("shell", "curl", {
Expand Down Expand Up @@ -79,7 +81,7 @@ class LoggerMiddleware {
ctx.rq.final_request.headers,
ctx.rq.final_request.method,
protocol,
ctx.rq.final_request.host,
getHost(ctx),
ctx.rq.final_request.path,
ctx.rq.final_request.body,
ctx.rq.final_response.status_code,
Expand Down
13 changes: 13 additions & 0 deletions src/components/proxy-middleware/rule_action_processor/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ export const get_success_actions_from_action_results = (
return success_action_results_objs.map((obj) => obj.action);
};

function isLocalHost(host) {
return host === "localhost" || host === "127.0.0.1" || host === "0.0.0.0";
}

export const getHost = (ctx) => {
const finalHost = ctx.rq.final_request.host;
if(isLocalHost(finalHost) && ctx.rq.final_request.port) {
return `${finalHost}:${ctx.rq.final_request.port}`;
} else {
return finalHost
}
}

export const get_file_contents = (file_path) => {
return fs.readFileSync(file_path, "utf-8");
}