Skip to content

Commit c00aa1f

Browse files
authored
fix: request body breaking for captcha (#69)
1 parent c8fa2bc commit c00aa1f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/components/proxy-middleware/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import LoggerMiddleware from "./middlewares/logger_middleware";
1919
import SslCertMiddleware from "./middlewares/ssl_cert_middleware";
2020
import CtxRQNamespace from "./helpers/ctx_rq_namespace";
2121
import { bodyParser, getContentType } from "./helpers/http_helpers";
22-
import { RQ_INTERCEPTED_CONTENT_TYPES } from "./constants";
22+
import { RQ_INTERCEPTED_CONTENT_TYPES, RULE_ACTION } from "./constants";
2323
import { CONSTANTS as GLOBAL_CONSTANTS } from "@requestly/requestly-core";
2424
import { dataToServeUnreachablePage, isAddressUnreachableError } from "./helpers/handleUnreachableAddress";
2525
// import SSLProxyingConfigFetcher from "renderer/lib/fetcher/ssl-proxying-config-fetcher";
@@ -221,6 +221,8 @@ class ProxyMiddlewareManager {
221221
ctx.rq.set_original_request({ body: pre_final_body });
222222
ctx.rq_request_body = pre_final_body;
223223

224+
let request_rule_applied = false;
225+
224226
if (parsedBody && RQ_INTERCEPTED_CONTENT_TYPES.includes(contentType)) {
225227
// Do modifications, if any
226228
const { action_result_objs, continue_request } = await rules_middleware.on_request_end(ctx);
@@ -232,10 +234,18 @@ class ProxyMiddlewareManager {
232234
);
233235
return;
234236
}
237+
238+
request_rule_applied = action_result_objs?.some(
239+
(obj) => obj?.action?.action === RULE_ACTION.MODIFY_REQUEST
240+
);
235241
}
236242

237-
// Use the updated request
238-
ctx.proxyToServerRequest.write(ctx.rq_request_body);
243+
if (request_rule_applied) {
244+
ctx.proxyToServerRequest.write(ctx.rq_request_body);
245+
} else {
246+
// If no modifications, write the original request body buffer so that we don't mess up during decoding
247+
ctx.proxyToServerRequest.write(body);
248+
}
239249
ctx.rq.set_final_request({ body: ctx.rq_request_body });
240250

241251
return callback();

0 commit comments

Comments
 (0)