Skip to content

Commit

Permalink
[8.6] [Console] Improve check for response size in `/autocomplete_ent…
Browse files Browse the repository at this point in the history
…ities` endpoint (#148328) (#148401)

# Backport

This will backport the following commits from `main` to `8.6`:
- [[Console] Improve check for response size in `/autocomplete_entities`
endpoint (#148328)](#148328)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Dima
Arnautov","email":"dmitrii.arnautov@elastic.co"},"sourceCommit":{"committedDate":"2023-01-04T15:48:31Z","message":"[Console]
Improve check for response size in `/autocomplete_entities` endpoint
(#148328)","sha":"bc19656c3c1caa4e940e51342ffb3c1e57fe4f33","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Feature:Console","Feature:Dev
Tools","release_note:fix","backport:prev-minor","v8.7.0"],"number":148328,"url":"#148328
Improve check for response size in `/autocomplete_entities` endpoint
(#148328)","sha":"bc19656c3c1caa4e940e51342ffb3c1e57fe4f33"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"#148328
Improve check for response size in `/autocomplete_entities` endpoint
(#148328)","sha":"bc19656c3c1caa4e940e51342ffb3c1e57fe4f33"}}]}]
BACKPORT-->

Co-authored-by: Dima Arnautov <dmitrii.arnautov@elastic.co>
  • Loading branch information
kibanamachine and darnautov committed Jan 19, 2023
1 parent ed13abf commit 1906c49
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 1906c49

Please sign in to comment.