Skip to content

Commit

Permalink
[Console] Improve check for response size in /autocomplete_entities
Browse files Browse the repository at this point in the history
… endpoint (elastic#148328)

(cherry picked from commit bc19656)
  • Loading branch information
darnautov committed Jan 4, 2023
1 parent b99147d commit 39bf989
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,16 @@ const getEntity = (path: string, config: Config) => {
try {
const req = client.request(options, (res) => {
const chunks: Buffer[] = [];

let currentLength = 0;

res.on('data', (chunk) => {
currentLength += Buffer.byteLength(chunk);

chunks.push(chunk);

// Destroy the request if the response is too large
if (Buffer.byteLength(Buffer.concat(chunks)) > MAX_RESPONSE_SIZE) {
if (currentLength > MAX_RESPONSE_SIZE) {
req.destroy();
reject(Boom.badRequest(`Response size is too large for ${path}`));
}
Expand Down

0 comments on commit 39bf989

Please sign in to comment.