From bb6cf860dbea3c2ff97f2ad041d66e5b2676a2d0 Mon Sep 17 00:00:00 2001 From: Niheel Thakkar Date: Fri, 5 Mar 2021 13:35:21 +0530 Subject: [PATCH] 179366445 Make support for GET requests with body configurable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added consideration for new config variable 'enable_GET_req_body' which is optional Set request header ‘transfer-encoding’ with value as ‘chunked’ only if with source request method as GET the config enable_GET_req_body is also specified with value as true Set ‘_hasBody’ property of target request to true to allow body(for GET requests) only if with request method as GET the config enable_GET_req_body is also specified with value as true --- lib/plugins-middleware.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/plugins-middleware.js b/lib/plugins-middleware.js index 8997412..422f079 100644 --- a/lib/plugins-middleware.js +++ b/lib/plugins-middleware.js @@ -235,7 +235,7 @@ function getTargetRequest(sourceRequest, sourceResponse, plugins, startTime, cor if (target_headers['content-length']) { delete target_headers['content-length']; - if(!target_headers['transfer-encoding'] && (sourceRequest.method==='DELETE' || sourceRequest.method==='GET')) { + if(!target_headers['transfer-encoding'] && (sourceRequest.method==='DELETE' || (sourceRequest.method==='GET' && config.edgemicro.enable_GET_req_body))) { target_headers['transfer-encoding'] = 'chunked'; } } @@ -468,6 +468,7 @@ function handleTargetResponse(targetRequest, targetResponse, options, cb) { */ function subscribeToSourceRequestEvents(plugins, sourceRequest, sourceResponse, targetRequest) { const logger = logging.getLogger(); + const config = configService.get(); // using apply on the array returned by getPluginHooksForEvent --> using a dummy object in place of this, which cannot be bound here. const onend_request_handlers = async.seq.apply({}, getPluginHooksForEvent('end', { @@ -501,7 +502,7 @@ function subscribeToSourceRequestEvents(plugins, sourceRequest, sourceResponse, }); }); - if (targetRequest.method === "HEAD") { + if ((targetRequest.method==='GET' && !config.edgemicro.enable_GET_req_body) || (targetRequest.method === "HEAD")) { targetRequest._hasBody = false; }