@@ -3,12 +3,13 @@ import { PROXY_HANDLER_TYPE } from "../../../../lib/proxy";
33import {
44 CONSTANTS as GLOBAL_CONSTANTS ,
55} from "@requestly/requestly-core" ;
6- import { get_request_url } from "../../helpers/proxy_ctx_helper" ;
6+ import { getResponseContentTypeHeader , getResponseHeaders , get_request_url } from "../../helpers/proxy_ctx_helper" ;
77import { build_action_processor_response , build_post_process_data } from "../utils" ;
88import fs from "fs" ;
9- import { parseJsonBody } from "../../helpers/http_helpers" ;
9+ import { getContentType , parseJsonBody } from "../../helpers/http_helpers" ;
1010import ConsoleCapture from "capture-console-logs" ;
1111import { getFunctionFromString } from "../../../../utils" ;
12+ import { RQ_INTERCEPTED_CONTENT_TYPES } from "../../constants" ;
1213
1314const { types } = require ( "util" ) ;
1415
@@ -54,19 +55,35 @@ const process_modify_response_action = async (action, ctx) => {
5455 action . responseType &&
5556 action . responseType === GLOBAL_CONSTANTS . RESPONSE_BODY_TYPES . CODE
5657 ) {
57- await modify_response_using_code ( action , ctx ) ;
58- return build_action_processor_response ( action , true ) ;
58+ const contentTypeHeader = getResponseContentTypeHeader ( ctx ) ;
59+ const contentType = getContentType ( contentTypeHeader ) ;
60+ if ( RQ_INTERCEPTED_CONTENT_TYPES . includes ( contentType ) || contentType == null ) {
61+ await modify_response_using_code ( action , ctx ) ;
62+ delete_breaking_headers ( ctx ) ;
63+ return build_action_processor_response ( action , true ) ;
64+ }
65+
66+ // Sentry not working
67+ // Sentry.captureException(new Error(`Content Type ${contentType} not supported for modification in programmatic mode`));
68+ console . log ( `Content Type ${ contentType } not supported for modification in programmatic mode` ) ;
69+ return build_action_processor_response ( action , false ) ;
5970 } else if (
6071 action . responseType === GLOBAL_CONSTANTS . RESPONSE_BODY_TYPES . LOCAL_FILE
6172 ) {
6273 modify_response_using_local ( action , ctx ) ;
74+ delete_breaking_headers ( ctx ) ;
6375 return build_action_processor_response ( action , true ) ;
6476 } else {
6577 modify_response ( ctx , action . response , action . statusCode ) ;
78+ delete_breaking_headers ( ctx ) ;
6679 return build_action_processor_response ( action , true ) ;
6780 }
6881} ;
6982
83+ const delete_breaking_headers = ( ctx ) => {
84+ delete getResponseHeaders ( ctx ) [ 'content-length' ] ;
85+ }
86+
7087const modify_response = ( ctx , new_resp , status_code ) => {
7188 ctx . rq_response_body = new_resp ;
7289 ctx . rq_response_status_code = status_code ;
@@ -113,7 +130,7 @@ const modify_response_using_code = async (action, ctx) => {
113130 ? ctx . clientToProxyRequest . method
114131 : null
115132 : null ,
116- response : ctx ?. rq_response_body ,
133+ response : ctx ?. rq_parsed_response_body ,
117134 url : get_request_url ( ctx ) ,
118135 responseType : ctx ?. serverToProxyResponse ?. headers ?. [ "content-type" ] ,
119136 requestHeaders : ctx . clientToProxyRequest . headers ,
0 commit comments