Skip to content

Commit d300f1c

Browse files
committed
populated requestData in response rule
1 parent 7f545d4 commit d300f1c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/components/proxy-middleware/helpers/http_helpers.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,12 @@ export const getContentType = (contentTypeHeader) => {
4444
contentType = contentTypeHeader.split(";")[0];
4545
return contentType;
4646
};
47+
48+
export const parseJsonBody = (data) => {
49+
try {
50+
return JSON.parse(data);
51+
} catch (e) {
52+
/* Body is still buffer array */
53+
}
54+
return data;
55+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import { get_request_url } from "../../helpers/proxy_ctx_helper";
88
import { build_action_processor_response } from "../utils";
99
import fs from "fs";
10+
import { parseJsonBody } from "../../helpers/http_helpers";
1011
const { types } = require("util");
1112

1213
const process_modify_response_action = async (action, ctx) => {
@@ -83,7 +84,7 @@ const modify_response_using_code = async (action, ctx) => {
8384
url: get_request_url(ctx),
8485
responseType: ctx.serverToProxyResponse.headers["content-type"],
8586
requestHeaders: ctx.clientToProxyRequest.headers,
86-
requestData: null,
87+
requestData: parseJsonBody(ctx.rq?.final_request?.body) || null,
8788
};
8889

8990
try {

0 commit comments

Comments
 (0)