|
19 | 19 |
|
20 | 20 | import { ConnectionOptions as TlsConnectionOptions } from 'tls'
|
21 | 21 | import { URL } from 'url'
|
| 22 | +import buffer from 'buffer' |
22 | 23 | import {
|
23 | 24 | Transport,
|
24 | 25 | HttpConnection,
|
@@ -109,6 +110,8 @@ interface ClientOptions {
|
109 | 110 | }
|
110 | 111 | disablePrototypePoisoningProtection?: boolean | 'proto' | 'constructor'
|
111 | 112 | caFingerprint?: string
|
| 113 | + maxResponseSize?: number |
| 114 | + maxCompressedResponseSize?: number |
112 | 115 | }
|
113 | 116 |
|
114 | 117 | export default class Client extends API {
|
@@ -178,13 +181,23 @@ export default class Client extends API {
|
178 | 181 | opaqueIdPrefix: null,
|
179 | 182 | context: null,
|
180 | 183 | proxy: null,
|
181 |
| - enableMetaHeader: true |
| 184 | + enableMetaHeader: true, |
| 185 | + maxResponseSize: null, |
| 186 | + maxCompressedResponseSize: null |
182 | 187 | }, opts)
|
183 | 188 |
|
184 | 189 | if (options.caFingerprint !== null && isHttpConnection(opts.node ?? opts.nodes)) {
|
185 | 190 | throw new errors.ConfigurationError('You can\'t configure the caFingerprint with a http connection')
|
186 | 191 | }
|
187 | 192 |
|
| 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 | + |
188 | 201 | if (options.enableMetaHeader) {
|
189 | 202 | options.headers['x-elastic-client-meta'] = `es=${clientVersion},js=${nodeVersion},t=${transportVersion},hc=${nodeVersion}`
|
190 | 203 | }
|
@@ -237,6 +250,8 @@ export default class Client extends API {
|
237 | 250 | opaqueIdPrefix: options.opaqueIdPrefix,
|
238 | 251 | context: options.context,
|
239 | 252 | productCheck: 'Elasticsearch'
|
| 253 | + maxResponseSize: options.maxResponseSize, |
| 254 | + maxCompressedResponseSize: options.maxCompressedResponseSize |
240 | 255 | })
|
241 | 256 |
|
242 | 257 | this.helpers = new Helpers({
|
|
0 commit comments