From a4df0b1e0df77ddad3fb5009dbd11c9050648687 Mon Sep 17 00:00:00 2001 From: Bill McConaghy Date: Mon, 4 Mar 2019 17:29:29 -0500 Subject: [PATCH] =?UTF-8?q?fixing=20issue=20with=20request=20body=20not=20?= =?UTF-8?q?being=20sent=20for=20console=20DELETE=20requ=E2=80=A6=20(#32407?= =?UTF-8?q?)=20(#32429)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix for delete not sending body from console * better fix that accounts for delays in incoming data --- .../console/server/proxy_route.js | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/legacy/core_plugins/console/server/proxy_route.js b/src/legacy/core_plugins/console/server/proxy_route.js index a7062133dcd36..963f26bd3523c 100644 --- a/src/legacy/core_plugins/console/server/proxy_route.js +++ b/src/legacy/core_plugins/console/server/proxy_route.js @@ -54,7 +54,6 @@ function getProxyHeaders(req) { if (contentType) { headers['content-type'] = contentType; } - return headers; } @@ -107,30 +106,37 @@ export const createProxyRoute = ({ agent, headers, } = getConfigForReq(req, uri); + const makeRequest = async (payloadToSend) => { + const wreckOptions = { + payload: payloadToSend, + timeout, + rejectUnauthorized, + agent, + headers: { + ...headers, + ...getProxyHeaders(req) + }, + }; + + const esResponse = await Wreck.request(method, uri, wreckOptions); + + if (method.toUpperCase() !== 'HEAD') { + return h.response(esResponse) + .code(esResponse.statusCode) + .header('warning', esResponse.headers.warning); + } - const wreckOptions = { - payload, - timeout, - rejectUnauthorized, - agent, - headers: { - ...headers, - ...getProxyHeaders(req) - }, - }; - - const esResponse = await Wreck.request(method, uri, wreckOptions); - - if (method.toUpperCase() !== 'HEAD') { - return h.response(esResponse) + return h.response(`${esResponse.statusCode} - ${esResponse.statusMessage}`) .code(esResponse.statusCode) + .type('text/plain') .header('warning', esResponse.headers.warning); + }; + if (method.toUpperCase() === 'DELETE') { + const data = await Wreck.read(payload); + return await makeRequest(data); + } else { + return await makeRequest(payload); } - - return h.response(`${esResponse.statusCode} - ${esResponse.statusMessage}`) - .code(esResponse.statusCode) - .type('text/plain') - .header('warning', esResponse.headers.warning); } } });