From 78f887f99e927b602f35c036f4681922d86cc8b1 Mon Sep 17 00:00:00 2001 From: Bill McConaghy Date: Mon, 4 Mar 2019 14:23:58 -0500 Subject: [PATCH] fix for delete not sending body from console --- .../console/server/proxy_route.js | 55 ++++++++++++------- 1 file changed, 34 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..20f6349e19810 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,44 @@ 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 === 'DELETE') { + let data = Buffer.alloc(0); + while (true) { + const datum = payload.read(); + if (datum) { + data = Buffer.concat([data, datum]); + } else { + 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); } } });