Skip to content

Conversation

@fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Aug 12, 2025

This reverts commit 0e5ad19.

Summary by CodeRabbit

  • Bug Fixes

    • Redirects are now handled consistently by the client, honoring redirect limits and followRedirect=false.
  • Refactor

    • Removed Node 16 compatibility shims, effectively ending Node 16 support. No public API changes.
  • Tests

    • Simplified TLS certificate generation across tests.
    • Re-enabled multipart Content-Type assertion for form upload.

@fengmk2 fengmk2 requested review from akitaSummer and killagu August 12, 2025 02:12
@coderabbitai
Copy link

coderabbitai bot commented Aug 12, 2025

Walkthrough

Disables undici’s automatic redirect handling by setting maxRedirections: 0 and relies on existing manual redirect logic. Removes Node 16 compatibility shims from utils. Cleans minor whitespace in index. Updates tests to use default selfsigned cert generation and re-enables a multipart Content-Type assertion.

Changes

Cohort / File(s) Summary of changes
Redirect handling in HttpClient
src/HttpClient.ts
Set undici requestOptions.maxRedirections to 0; manual redirect flow remains unchanged and governed by maxRedirects/followRedirect.
Node 16 polyfill cleanup
src/utils.ts, src/index.ts
Removed Node 16 compatibility imports and polyfills (File, toWellFormed/isWellFormed); trivial whitespace tweak in index without semantic impact.
TLS test setup simplification
test/HttpClient.test.ts, test/diagnostics_channel.test.ts, test/options.timeout.test.ts, test/urllib.options.rejectUnauthorized-false.test.ts, test/fixtures/server.ts
Replaced nodeMajorVersion-based keySize logic with default selfsigned.generate(); removed related imports; fixtures server now uses default selfsigned certs.
Re-enabled multipart header assertion
test/options.stream.test.ts
Un-commented assertion checking multipart/form-data boundary in response Content-Type.

Sequence Diagram(s)

sequenceDiagram
  participant App as Caller
  participant HC as HttpClient
  participant U as undici

  App->>HC: request(url, options)
  HC->>U: request(url, { maxRedirections: 0, ... })
  U-->>HC: response (no auto-redirect)
  alt Is redirect status and redirects < maxRedirects
    HC->>HC: resolve redirect URL, update context
    HC->>U: request(nextUrl, { maxRedirections: 0, ... })
    U-->>HC: response
  end
  HC-->>App: final response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested labels

bug

Poem

A hop, a skip—no auto-redirects today,
I follow the trail in my own bunny way.
Old Node burrows closed, shims set free,
Self-signed clover grows by default key.
Multipart drums with a boundary beat—
Thump-thump, says Rabbit: reviews complete! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch revert-pr-588

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

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

Choose a reason for hiding this comment

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

Summary of Changes

Hello @fengmk2, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request reverts commit 0e5ad19, which aimed to fix undici File support on Node.js versions less than 20. The revert removes specific polyfills and related imports, and also streamlines test certificate generation by removing Node.js version-dependent key size logic.

Highlights

  • Revert of undici File support patch: The primary change is undoing the previous commit that introduced polyfills for global.File, String.prototype.toWellFormed, and String.prototype.isWellFormed to support undici on Node.js versions below 20.
  • Cleanup of HttpClient configuration: The maxRedirections: 0 option in HttpClient.ts is re-enabled by uncommenting, restoring its intended behavior.
  • Test suite simplification: The test files have been updated to remove nodeMajorVersion utility imports and usage, simplifying the selfsigned.generate() calls by removing conditional keySize settings.
  • Restoration of test assertion: An assertion related to multipart/form-data content type in test/options.stream.test.ts has been uncommented, restoring its validation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

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

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 reverts commit 0e5ad19, which had introduced a polyfill for File support on Node.js versions below 20. The changes effectively remove this polyfill and associated code, including the removal of File and toUSVString from imports in src/utils.ts and the deletion of the polyfill logic itself. Test files have been updated to remove dependencies on a nodeMajorVersion utility, simplifying certificate generation. A test case for multipart form data has also been re-enabled. The revert appears clean and correctly implemented.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/utils.ts (1)

5-5: Confirm intent: Node 16 polyfills still present

This import is only used by patchForNode16() to polyfill global.Blob. If the goal is to drop Node 16 shims as part of this revert, consider removing patchForNode16() and this import; otherwise, keeping them is fine but please confirm the intended compatibility story.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3cc8971 and ade9240.

📒 Files selected for processing (9)
  • src/HttpClient.ts (1 hunks)
  • src/index.ts (0 hunks)
  • src/utils.ts (1 hunks)
  • test/HttpClient.test.ts (1 hunks)
  • test/diagnostics_channel.test.ts (1 hunks)
  • test/fixtures/server.ts (2 hunks)
  • test/options.stream.test.ts (1 hunks)
  • test/options.timeout.test.ts (1 hunks)
  • test/urllib.options.rejectUnauthorized-false.test.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • src/index.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
test/options.stream.test.ts (1)
test/cjs/index.js (1)
  • assert (2-2)
🪛 GitHub Actions: Node.js 16 CI
src/HttpClient.ts

[error] 432-432: TS2353: Object literal may only specify known properties, and 'maxRedirections' does not exist in type 'IUndiciRequestOption'.

🪛 GitHub Actions: Publish Any Commit
src/HttpClient.ts

[error] 432-432: TypeScript error TS2353 during npm run build: Object literal may only specify known properties, and 'maxRedirections' does not exist in type 'IUndiciRequestOption'.

🪛 GitHub Check: Node.js / Test (macos-latest, 22)
test/options.stream.test.ts

[failure] 97-97: test/options.stream.test.ts > options.stream.test.ts > should upload file with formstream
AssertionError: The input did not match the regular expression /^multipart/form-data; boundary=--------------------------\d+$/. Input:

'multipart/form-data; boundary=--------------------------86442430eab6492fe5b8831b'

  • Expected:
    /^multipart/form-data; boundary=--------------------------\d+$/
  • Received:
    "multipart/form-data; boundary=--------------------------86442430eab6492fe5b8831b"

❯ test/options.stream.test.ts:97:12

🪛 GitHub Check: Node.js / Test (ubuntu-latest, 24)
test/options.stream.test.ts

[failure] 97-97: test/options.stream.test.ts > options.stream.test.ts > should upload file with formstream
AssertionError: The input did not match the regular expression /^multipart/form-data; boundary=--------------------------\d+$/. Input:

'multipart/form-data; boundary=--------------------------2fdf9d79bde30b3b3cd5ae8d'

  • Expected:
    /^multipart/form-data; boundary=--------------------------\d+$/
  • Received:
    "multipart/form-data; boundary=--------------------------2fdf9d79bde30b3b3cd5ae8d"

❯ test/options.stream.test.ts:97:12

🪛 GitHub Check: Node.js / Test (macos-latest, 24)
test/options.stream.test.ts

[failure] 97-97: test/options.stream.test.ts > options.stream.test.ts > should upload file with formstream
AssertionError: The input did not match the regular expression /^multipart/form-data; boundary=--------------------------\d+$/. Input:

'multipart/form-data; boundary=--------------------------c32713078e5e011b81e48fe6'

  • Expected:
    /^multipart/form-data; boundary=--------------------------\d+$/
  • Received:
    "multipart/form-data; boundary=--------------------------c32713078e5e011b81e48fe6"

❯ test/options.stream.test.ts:97:12

🪛 GitHub Check: Node.js / Test (macos-latest, 20)
test/options.stream.test.ts

[failure] 97-97: test/options.stream.test.ts > options.stream.test.ts > should upload file with formstream
AssertionError: The input did not match the regular expression /^multipart/form-data; boundary=--------------------------\d+$/. Input:

'multipart/form-data; boundary=--------------------------c8cec534105c72d9cff8a19a'

  • Expected:
    /^multipart/form-data; boundary=--------------------------\d+$/
  • Received:
    "multipart/form-data; boundary=--------------------------c8cec534105c72d9cff8a19a"

❯ test/options.stream.test.ts:97:12

🪛 GitHub Check: Node.js / Test (ubuntu-latest, 20)
test/options.stream.test.ts

[failure] 97-97: test/options.stream.test.ts > options.stream.test.ts > should upload file with formstream
AssertionError: The input did not match the regular expression /^multipart/form-data; boundary=--------------------------\d+$/. Input:

'multipart/form-data; boundary=--------------------------aad8037a0afa31756ffbeaaf'

  • Expected:
    /^multipart/form-data; boundary=--------------------------\d+$/
  • Received:
    "multipart/form-data; boundary=--------------------------aad8037a0afa31756ffbeaaf"

❯ test/options.stream.test.ts:97:12

🪛 GitHub Check: Node.js / Test (ubuntu-latest, 22)
test/options.stream.test.ts

[failure] 97-97: test/options.stream.test.ts > options.stream.test.ts > should upload file with formstream
AssertionError: The input did not match the regular expression /^multipart/form-data; boundary=--------------------------\d+$/. Input:

'multipart/form-data; boundary=--------------------------8c01933016ec59398b3dc4ed'

  • Expected:
    /^multipart/form-data; boundary=--------------------------\d+$/
  • Received:
    "multipart/form-data; boundary=--------------------------8c01933016ec59398b3dc4ed"

❯ test/options.stream.test.ts:97:12

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Node.js / Test (windows-latest, 22)
  • GitHub Check: Node.js / Test (windows-latest, 20)
  • GitHub Check: Node.js / Test (windows-latest, 24)
🔇 Additional comments (6)
test/urllib.options.rejectUnauthorized-false.test.ts (1)

32-32: LGTM: switch to default selfsigned.generate()

Using the library defaults simplifies the test setup and keeps behavior consistent across Node versions.

test/HttpClient.test.ts (1)

12-12: LGTM: TLS test setup simplified

Using selfsigned.generate() defaults eliminates Node-version branching without affecting test intent.

test/options.timeout.test.ts (1)

9-9: LGTM: default TLS generation

Consistent with other tests; avoids brittle key-size branching.

test/diagnostics_channel.test.ts (1)

146-146: LGTM: default self-signed certs for H2 test

Aligns with the broader move to defaults; behavior remains unchanged.

test/fixtures/server.ts (2)

11-11: LGTM: import reordering

No functional impact; maintainers might want to keep imports grouped consistently, but this is fine.


373-377: LGTM: default self-signed certs for HTTPS server

Removes Node-version-dependent key-size logic and keeps fixture consistent with other tests.

method,
// disable undici auto redirect handler
// maxRedirections: 0,
maxRedirections: 0,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

TS2353: maxRedirections is not in undici typings across versions

CI fails with TS2353 because some undici typings don’t include maxRedirections. We still want to disable undici’s built-in redirects when supported. Assign the property post-creation with a type escape to satisfy all supported undici versions.

Apply this diff:

       const requestOptions: IUndiciRequestOption = {
         method,
-        // disable undici auto redirect handler
-        maxRedirections: 0,
         headersTimeout,
         headers,
         bodyTimeout,
         opaque: internalOpaque,
         dispatcher: args.dispatcher ?? this.#dispatcher,
         signal: args.signal,
         reset: false,
       };
+      // Disable undici auto redirect handling when supported by the runtime undici version.
+      // Some undici typings (e.g., v7) don’t declare `maxRedirections`, so set it via a type-escape.
+      // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+      // @ts-expect-error: 'maxRedirections' is not declared in some undici versions' types
+      (requestOptions as any).maxRedirections = 0;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
maxRedirections: 0,
const requestOptions: IUndiciRequestOption = {
method,
headersTimeout,
headers,
bodyTimeout,
opaque: internalOpaque,
dispatcher: args.dispatcher ?? this.#dispatcher,
signal: args.signal,
reset: false,
};
// Disable undici auto redirect handling when supported by the runtime undici version.
// Some undici typings (e.g., v7) don’t declare `maxRedirections`, so set it via a type-escape.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error: 'maxRedirections' is not declared in some undici versions' types
(requestOptions as any).maxRedirections = 0;
🧰 Tools
🪛 GitHub Actions: Node.js 16 CI

[error] 432-432: TS2353: Object literal may only specify known properties, and 'maxRedirections' does not exist in type 'IUndiciRequestOption'.

🪛 GitHub Actions: Publish Any Commit

[error] 432-432: TypeScript error TS2353 during npm run build: Object literal may only specify known properties, and 'maxRedirections' does not exist in type 'IUndiciRequestOption'.

🤖 Prompt for AI Agents
In src/HttpClient.ts around line 432, the undici option maxRedirections is
causing TS2353 because some undici typings don’t include it; remove it from the
initial options and instead, immediately after creating the undici client,
assign the property on the client instance using a type escape (cast the client
to any/unknown and set .maxRedirections = 0) so the runtime disables built-in
redirects when supported while satisfying all TypeScript versions.

assert.equal(response.data.method, 'POST');
// console.log(response.data);
// assert.match(response.data.headers['content-type'], /^multipart\/form-data; boundary=--------------------------\d+$/);
assert.match(response.data.headers['content-type'], /^multipart\/form-data; boundary=--------------------------\d+$/);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix failing boundary assertion (boundary includes hex chars, not only digits)

CI shows the boundary contains a hex string (0-9a-f), so the digits-only regex is too strict.

Apply this diff to make the assertion robust:

-    assert.match(response.data.headers['content-type'], /^multipart\/form-data; boundary=--------------------------\d+$/);
+    // boundary is a crypto-ish hex string; allow hex chars instead of digits only
+    assert.match(response.data.headers['content-type'], /^multipart\/form-data; boundary=--------------------------[0-9a-f]+$/i);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
assert.match(response.data.headers['content-type'], /^multipart\/form-data; boundary=--------------------------\d+$/);
// boundary is a crypto-ish hex string; allow hex chars instead of digits only
assert.match(
response.data.headers['content-type'],
/^multipart\/form-data; boundary=--------------------------[0-9a-f]+$/i
);
🧰 Tools
🪛 GitHub Check: Node.js / Test (macos-latest, 22)

[failure] 97-97: test/options.stream.test.ts > options.stream.test.ts > should upload file with formstream
AssertionError: The input did not match the regular expression /^multipart/form-data; boundary=--------------------------\d+$/. Input:

'multipart/form-data; boundary=--------------------------86442430eab6492fe5b8831b'

  • Expected:
    /^multipart/form-data; boundary=--------------------------\d+$/
  • Received:
    "multipart/form-data; boundary=--------------------------86442430eab6492fe5b8831b"

❯ test/options.stream.test.ts:97:12

🪛 GitHub Check: Node.js / Test (ubuntu-latest, 24)

[failure] 97-97: test/options.stream.test.ts > options.stream.test.ts > should upload file with formstream
AssertionError: The input did not match the regular expression /^multipart/form-data; boundary=--------------------------\d+$/. Input:

'multipart/form-data; boundary=--------------------------2fdf9d79bde30b3b3cd5ae8d'

  • Expected:
    /^multipart/form-data; boundary=--------------------------\d+$/
  • Received:
    "multipart/form-data; boundary=--------------------------2fdf9d79bde30b3b3cd5ae8d"

❯ test/options.stream.test.ts:97:12

🪛 GitHub Check: Node.js / Test (macos-latest, 24)

[failure] 97-97: test/options.stream.test.ts > options.stream.test.ts > should upload file with formstream
AssertionError: The input did not match the regular expression /^multipart/form-data; boundary=--------------------------\d+$/. Input:

'multipart/form-data; boundary=--------------------------c32713078e5e011b81e48fe6'

  • Expected:
    /^multipart/form-data; boundary=--------------------------\d+$/
  • Received:
    "multipart/form-data; boundary=--------------------------c32713078e5e011b81e48fe6"

❯ test/options.stream.test.ts:97:12

🪛 GitHub Check: Node.js / Test (macos-latest, 20)

[failure] 97-97: test/options.stream.test.ts > options.stream.test.ts > should upload file with formstream
AssertionError: The input did not match the regular expression /^multipart/form-data; boundary=--------------------------\d+$/. Input:

'multipart/form-data; boundary=--------------------------c8cec534105c72d9cff8a19a'

  • Expected:
    /^multipart/form-data; boundary=--------------------------\d+$/
  • Received:
    "multipart/form-data; boundary=--------------------------c8cec534105c72d9cff8a19a"

❯ test/options.stream.test.ts:97:12

🪛 GitHub Check: Node.js / Test (ubuntu-latest, 20)

[failure] 97-97: test/options.stream.test.ts > options.stream.test.ts > should upload file with formstream
AssertionError: The input did not match the regular expression /^multipart/form-data; boundary=--------------------------\d+$/. Input:

'multipart/form-data; boundary=--------------------------aad8037a0afa31756ffbeaaf'

  • Expected:
    /^multipart/form-data; boundary=--------------------------\d+$/
  • Received:
    "multipart/form-data; boundary=--------------------------aad8037a0afa31756ffbeaaf"

❯ test/options.stream.test.ts:97:12

🪛 GitHub Check: Node.js / Test (ubuntu-latest, 22)

[failure] 97-97: test/options.stream.test.ts > options.stream.test.ts > should upload file with formstream
AssertionError: The input did not match the regular expression /^multipart/form-data; boundary=--------------------------\d+$/. Input:

'multipart/form-data; boundary=--------------------------8c01933016ec59398b3dc4ed'

  • Expected:
    /^multipart/form-data; boundary=--------------------------\d+$/
  • Received:
    "multipart/form-data; boundary=--------------------------8c01933016ec59398b3dc4ed"

❯ test/options.stream.test.ts:97:12

🤖 Prompt for AI Agents
In test/options.stream.test.ts around line 97, the current assertion expects the
multipart boundary to be only digits which is incorrect because CI shows the
boundary includes hex characters; update the regex to allow hexadecimal
characters (e.g. use [0-9a-fA-F]+ or add the /i flag) so the assertion matches
boundaries containing letters a–f as well as digits.

@fengmk2
Copy link
Member Author

fengmk2 commented Aug 12, 2025

0b1e89d

@fengmk2 fengmk2 closed this Aug 12, 2025
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.

2 participants