@@ -19,7 +19,7 @@ import LoggerMiddleware from "./middlewares/logger_middleware";
1919import SslCertMiddleware from "./middlewares/ssl_cert_middleware" ;
2020import CtxRQNamespace from "./helpers/ctx_rq_namespace" ;
2121import { bodyParser , getContentType } from "./helpers/http_helpers" ;
22- import { RQ_INTERCEPTED_CONTENT_TYPES } from "./constants" ;
22+ import { RQ_INTERCEPTED_CONTENT_TYPES , RULE_ACTION } from "./constants" ;
2323import { CONSTANTS as GLOBAL_CONSTANTS } from "@requestly/requestly-core" ;
2424import { 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