Skip to content

Commit 880bbad

Browse files
committed
Backport #1551
1 parent 45ff8f6 commit 880bbad

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/Client.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import { ConnectionOptions as TlsConnectionOptions } from 'tls'
2121
import { URL } from 'url'
22+
import buffer from 'buffer'
2223
import {
2324
Transport,
2425
HttpConnection,
@@ -109,6 +110,8 @@ interface ClientOptions {
109110
}
110111
disablePrototypePoisoningProtection?: boolean | 'proto' | 'constructor'
111112
caFingerprint?: string
113+
maxResponseSize?: number
114+
maxCompressedResponseSize?: number
112115
}
113116

114117
export default class Client extends API {
@@ -178,13 +181,23 @@ export default class Client extends API {
178181
opaqueIdPrefix: null,
179182
context: null,
180183
proxy: null,
181-
enableMetaHeader: true
184+
enableMetaHeader: true,
185+
maxResponseSize: null,
186+
maxCompressedResponseSize: null
182187
}, opts)
183188

184189
if (options.caFingerprint !== null && isHttpConnection(opts.node ?? opts.nodes)) {
185190
throw new errors.ConfigurationError('You can\'t configure the caFingerprint with a http connection')
186191
}
187192

193+
if (options.maxResponseSize !== null && options.maxResponseSize > buffer.constants.MAX_STRING_LENGTH) {
194+
throw new errors.ConfigurationError(`The maxResponseSize cannot be bigger than ${buffer.constants.MAX_STRING_LENGTH}`)
195+
}
196+
197+
if (options.maxCompressedResponseSize !== null && options.maxCompressedResponseSize > buffer.constants.MAX_LENGTH) {
198+
throw new errors.ConfigurationError(`The maxCompressedResponseSize cannot be bigger than ${buffer.constants.MAX_LENGTH}`)
199+
}
200+
188201
if (options.enableMetaHeader) {
189202
options.headers['x-elastic-client-meta'] = `es=${clientVersion},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion}`
190203
}
@@ -237,6 +250,8 @@ export default class Client extends API {
237250
opaqueIdPrefix: options.opaqueIdPrefix,
238251
context: options.context,
239252
productCheck: 'Elasticsearch'
253+
maxResponseSize: options.maxResponseSize,
254+
maxCompressedResponseSize: options.maxCompressedResponseSize
240255
})
241256

242257
this.helpers = new Helpers({

0 commit comments

Comments
 (0)