Skip to content

Conversation

@Dipper30
Copy link
Contributor

  • Add config.httpclient.interceptors support in fetch_factory.js by composing interceptors via dispatcher.compose(...) after setClientOptions() (since setClientOptions() resets dispatcher).
  • Apply the same behavior to safeFetch (SSRF factory).
  • Add test cases.

Why

  • Fix tracer plugins being overridden by fetch() lazy initialization since 3.32.0

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 16, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Dipper30, 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 enhances the HTTP client configuration by introducing support for custom interceptors in fetch and safeFetch operations. This change is crucial for ensuring that cross-cutting concerns like tracing are correctly applied to HTTP requests, especially after a regression introduced by lazy initialization in a previous version. The implementation carefully integrates these interceptors into the urllib4 FetchFactory's dispatcher mechanism, ensuring that custom logic can modify requests and responses reliably.

Highlights

  • Interceptor Support for fetch/safeFetch: Introduced config.httpclient.interceptors to allow custom HTTP client interceptors for both fetch and safeFetch methods.
  • Fixes Tracer Plugin Overrides: Resolves an issue where tracer plugins were being overridden due to the lazy initialization of fetch since version 3.32.0.
  • Interceptor Composition Logic: Interceptors are now composed using dispatcher.compose(...) and applied after setClientOptions() to ensure proper integration and prevent dispatcher resets.
  • Comprehensive Test Coverage: Added new test cases to validate the correct injection of tracer headers and the proper functioning of interceptors under various conditions.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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
Contributor

@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 effectively adds support for config.httpclient.interceptors to fetch and safeFetch, which is a valuable enhancement for features like tracing. The implementation is correct and is accompanied by a comprehensive set of tests that validate the new functionality. My main feedback is regarding a small piece of duplicated code in lib/core/fetch_factory.js. Extracting the interceptor application logic into a shared function would improve the code's maintainability. Overall, this is a solid contribution.

Comment on lines +54 to +58
if (this.config.httpclient?.interceptors) {
const interceptors = this.config.httpclient.interceptors;
const originalDispatcher = ssrfFetchFactory.getDispatcher();
ssrfFetchFactory.setDispatcher(originalDispatcher.compose(interceptors));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This block of code for applying interceptors is a duplicate of the logic in the fetch function (lines 28-32). To improve maintainability and avoid code duplication, consider extracting this logic into a shared helper function.

For example, you could define a function like this:

function applyInterceptors(factory, config) {
  if (config.httpclient?.interceptors) {
    const interceptors = config.httpclient.interceptors;
    const originalDispatcher = factory.getDispatcher();
    factory.setDispatcher(originalDispatcher.compose(interceptors));
  }
}

And then call it from both fetch and safeFetch initialization blocks:

// in fetch
applyInterceptors(FetchFactory, this.config);

// in safeFetch
applyInterceptors(ssrfFetchFactory, this.config);

This will make the code cleaner and easier to manage in the future.

Copy link
Contributor

@killagu killagu left a comment

Choose a reason for hiding this comment

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

LGTM

@fengmk2 fengmk2 added the pick-to-v4 pull request need to pick to egg v4 label Jan 17, 2026
@codecov
Copy link

codecov bot commented Jan 17, 2026

Codecov Report

❌ Patch coverage is 0% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.06%. Comparing base (a1169f3) to head (eddb192).
⚠️ Report is 3 commits behind head on 3.x.

Files with missing lines Patch % Lines
lib/core/fetch_factory.js 0.00% 17 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (a1169f3) and HEAD (eddb192). Click for more details.

HEAD has 14 uploads less than BASE
Flag BASE (a1169f3) HEAD (eddb192)
17 3
Additional details and impacted files
@@            Coverage Diff             @@
##              3.x    #5771      +/-   ##
==========================================
- Coverage   99.54%   94.06%   -5.48%     
==========================================
  Files          36       36              
  Lines        3722     3824     +102     
  Branches      562      533      -29     
==========================================
- Hits         3705     3597     -108     
- Misses         17      227     +210     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fengmk2 fengmk2 merged commit fdfe958 into eggjs:3.x Jan 18, 2026
43 of 45 checks passed
fengmk2 pushed a commit that referenced this pull request Jan 18, 2026
[skip ci]

## 3.34.0 (2026-01-18)

* feat(core): support `config.httpclient.interceptors` for `fetch`/`safeFetch` tracer injection (#5771 ([fdfe958](fdfe958)), closes [#5771](#5771)
@github-actions
Copy link

🎉 This PR is included in version 3.34.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

pick-to-v4 pull request need to pick to egg v4 released on @3.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants