Skip to content

fix(gaxios): honor maxContentLength and maxRedirects instance defaults - #9778

Draft
danieljbruce wants to merge 1 commit into
fix/gaxios-bun-max-content-length-streamfrom
fix/gaxios-instance-defaults
Draft

danieljbruce wants to merge 1 commit into
fix/gaxios-bun-max-content-length-streamfrom
fix/gaxios-instance-defaults

Conversation

@danieljbruce

@danieljbruce danieljbruce commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

Honors maxContentLength and maxRedirects instance defaults in Gaxios.#prepareRequest.

Impact

Ensures new Gaxios({maxContentLength, maxRedirects}) instance defaults populate opts.size and opts.follow.

Changes

  • Read opts.maxContentLength and opts.maxRedirects from the merged opts object in Gaxios.#prepareRequest instead of the raw per-request options argument.

Stack

  1. fix(gaxios): enforce maxContentLength on headerless responses in Bun #9773 — fix(gaxios): enforce maxContentLength on headerless responses in Bun (fix/gaxios-bun-max-content-length → main)
  2. fix(gaxios): enforce maxContentLength on stream responses in Bun #9777 — fix(gaxios): enforce maxContentLength on stream responses in Bun (fix/gaxios-bun-max-content-length-stream → fix/gaxios-bun-max-content-length)
  3. fix(gaxios): honor maxContentLength and maxRedirects instance defaults #9778 — fix(gaxios): honor maxContentLength and maxRedirects instance defaults (fix/gaxios-instance-defaults → fix/gaxios-bun-max-content-length-stream) (this PR)
  4. fix(gaxios): forward https.Agent TLS options and agent factories in Bun #9774 — fix(gaxios): forward https.Agent TLS options and agent factories in Bun (fix/gaxios-bun-agent-tls → fix/gaxios-instance-defaults)

Testing

  • Added a unit test in core/packages/gaxios/test/test.getch.ts verifying that new Gaxios({maxContentLength: 5}) enforces the limit on client.request({url}).
  • Steps to Reproduce (in terminal): Run cd core/packages/gaxios && pnpm run compile && JS_RUNTIME=bun MOCHA_PARALLEL=false bun --bun ../../../bin/run-test.cjs --no-c8 build/esm/test/test.getch.js -g "instance defaults".

Alternatives

  • Requiring callers to pass maxContentLength and maxRedirects on every request() call was rejected because new Gaxios(defaults) is documented to apply default options across all requests on the instance.
  • Not merging this PR was rejected because instance-level maxContentLength and maxRedirects defaults are otherwise ignored when populating opts.size and opts.follow.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates Gaxios to check opts instead of options for maxContentLength and maxRedirects, allowing instance defaults to be correctly honored. A test case was added to verify that maxContentLength is enforced from instance defaults. The reviewer suggested adding a corresponding test case for maxRedirects to ensure both options are fully covered and protected against future regressions.

Comment on lines +362 to 369
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();
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The pull request description and title mention honoring both maxContentLength and maxRedirects instance defaults. However, the added unit test only covers maxContentLength. Adding a test case for maxRedirects ensures both options are fully verified and protected against future regressions.

Suggested change
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();
});
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 enforce maxRedirects from instance defaults', async () => {
const redirectScope = nock(url)
.get('/')
.reply(302, undefined, {Location: '/redirect'});
const client = new Gaxios({maxRedirects: 0});
await assert.rejects(
client.request({url}),
(err: Error) => err instanceof GaxiosError,
);
redirectScope.done();
});

@danieljbruce

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request ensures that Gaxios instance defaults for maxContentLength and maxRedirects are correctly respected by checking opts instead of options. It also adds a test case verifying the maxContentLength default behavior. The feedback suggests extending the test coverage to also verify the maxRedirects default behavior.

Comment on lines +363 to +368
const client = new Gaxios({maxContentLength: 5});
await assert.rejects(
client.request({url}),
(err: Error) => err instanceof GaxiosError && /limit/.test(err.message),
);
defaultScope.done();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The pull request fixes both maxContentLength and maxRedirects instance defaults, but the added test only covers maxContentLength. It would be great to also add a test case verifying that maxRedirects instance defaults are correctly honored and enforced.

    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();

    const redirectScope = nock(url)
      .get('/')
      .reply(302, undefined, {Location: '/redirect'})
      .get('/redirect')
      .reply(200, 'done');
    const redirectClient = new Gaxios({maxRedirects: 0});
    await assert.rejects(
      redirectClient.request({url}),
      (err: Error) => err instanceof GaxiosError,
    );
    redirectScope.done();

@danieljbruce
danieljbruce added this pull request to stack #9782 October 29, 2026 20:51

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant