diff --git a/core/packages/gaxios/src/gaxios.ts b/core/packages/gaxios/src/gaxios.ts index 1eb5b4240dff..48c250f8ad5c 100644 --- a/core/packages/gaxios/src/gaxios.ts +++ b/core/packages/gaxios/src/gaxios.ts @@ -478,12 +478,12 @@ export class Gaxios implements FetchCompliance { } } - if (typeof options.maxContentLength === 'number') { - opts.size = options.maxContentLength; + if (typeof opts.maxContentLength === 'number') { + opts.size = opts.maxContentLength; } - if (typeof options.maxRedirects === 'number') { - opts.follow = options.maxRedirects; + if (typeof opts.maxRedirects === 'number') { + opts.follow = opts.maxRedirects; } const shouldDirectlyPassData = diff --git a/core/packages/gaxios/test/test.getch.ts b/core/packages/gaxios/test/test.getch.ts index b3f017e6da7b..528e49eefde2 100644 --- a/core/packages/gaxios/test/test.getch.ts +++ b/core/packages/gaxios/test/test.getch.ts @@ -343,7 +343,7 @@ describe('🥁 configuration options', () => { scope.done(); }); - it('should enforce maxContentLength on responses without a Content-Length header', async () => { + it('should enforce maxContentLength on responses without a Content-Length header and from instance defaults', async () => { const body = {hello: 'world'}; for (const responseType of [ 'json', @@ -358,6 +358,14 @@ describe('🥁 configuration options', () => { ); scope.done(); } + + const defaultScope = nock(url).get('/').reply(200, body); + const client = new Gaxios({maxContentLength: 5}); + await assert.rejects( + client.request({url}), + (err: Error) => err instanceof GaxiosError && /limit/.test(err.message), + ); + defaultScope.done(); }); it('should support redirects by default', async () => {