Skip to content

Commit

Permalink
fixing issue with request body not being sent for console DELETE requ… (
Browse files Browse the repository at this point in the history
elastic#32407)

* fix for delete not sending body from console

* better fix that accounts for delays in incoming data
  • Loading branch information
bmcconaghy committed Mar 4, 2019
1 parent d2db6ad commit 7adf58b
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions src/legacy/core_plugins/console/server/proxy_route.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ function getProxyHeaders(req) {
if (contentType) {
headers['content-type'] = contentType;
}

return headers;
}

Expand Down Expand Up @@ -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);
}
}
});

0 comments on commit 7adf58b

Please sign in to comment.