Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing issue with request body not being sent for console DELETE requests #32407

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix for delete not sending body from console
  • Loading branch information
bmcconaghy committed Mar 4, 2019
commit 78f887f99e927b602f35c036f4681922d86cc8b1
55 changes: 34 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,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);
}
}
});