From adbbb3bceb388b34753f9fe3579eec3f0520ddb3 Mon Sep 17 00:00:00 2001 From: Rich Ellis Date: Tue, 31 Aug 2021 19:38:22 +0100 Subject: [PATCH] perf: use maxContentLength -1 instead of Infinity (#158) The purpose of `Infinity` here is to have no limit, but as per https://github.com/axios/axios/issues/2829 the check is enabled for all values > -1 and the check introduces a performance issue. Changing the value to `-1` prevents the check being enabled. --- lib/request-wrapper.ts | 2 +- test/unit/request-wrapper.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/request-wrapper.ts b/lib/request-wrapper.ts index a3c9a7485..62b0222c1 100644 --- a/lib/request-wrapper.ts +++ b/lib/request-wrapper.ts @@ -70,7 +70,7 @@ export class RequestWrapper { // to 'application/x-www-form-urlencoded'. This causes problems, so overriding the // defaults here const axiosConfig: AxiosRequestConfig = { - maxContentLength: Infinity, + maxContentLength: -1, maxBodyLength: Infinity, headers: { post: { diff --git a/test/unit/request-wrapper.test.js b/test/unit/request-wrapper.test.js index cdf8e3b6b..15d3e0ff5 100644 --- a/test/unit/request-wrapper.test.js +++ b/test/unit/request-wrapper.test.js @@ -70,7 +70,7 @@ describe('RequestWrapper constructor', () => { // the constructor puts together a config object and creates the // axios instance with it const createdAxiosConfig = axios.default.create.mock.calls[0][0]; - expect(createdAxiosConfig.maxContentLength).toBe(Infinity); + expect(createdAxiosConfig.maxContentLength).toBe(-1); expect(createdAxiosConfig.maxBodyLength).toBe(Infinity); expect(createdAxiosConfig.headers).toBeDefined(); expect(createdAxiosConfig.headers.post).toBeDefined();