-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(core): support config.httpclient.interceptors for fetch/safeFetch tracer injection
#5771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit 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. Comment |
Summary of ChangesHello @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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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.
| if (this.config.httpclient?.interceptors) { | ||
| const interceptors = this.config.httpclient.interceptors; | ||
| const originalDispatcher = ssrfFetchFactory.getDispatcher(); | ||
| ssrfFetchFactory.setDispatcher(originalDispatcher.compose(interceptors)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
killagu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
|
🎉 This PR is included in version 3.34.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
config.httpclient.interceptorssupport in fetch_factory.js by composing interceptors viadispatcher.compose(...)aftersetClientOptions()(sincesetClientOptions()resets dispatcher).safeFetch(SSRF factory).Why
fetch()lazy initialization since 3.32.0