🐛 bug: Fix Accept-Language matching per RFC 4647#3553
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR updates the Accept-Language matching logic to follow RFC 4647 basic filtering and enhances its test coverage and documentation.
- Modified the acceptsOffer function to implement case-insensitive prefix matching for language tags.
- Added unit tests in helpers_test.go and ctx_test.go for valid, invalid, and case-insensitive language scenarios.
- Updated documentation in docs/api/ctx.md to explain the Basic Filtering algorithm.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| helpers_test.go | Added tests to validate Accept-Language filtering behavior. |
| helpers.go | Adjusted acceptsOffer to implement RFC 4647 basic filtering with case-insensitivity. |
| docs/api/ctx.md | Enhanced documentation to describe Basic Filtering for Accept-Language. |
| ctx_test.go | Added tests covering multi-header and case-insensitive scenarios. |
Comments suppressed due to low confidence (1)
helpers.go:142
- The implementation supports a trailing '*' wildcard by immediately returning true, but the documentation in ctx.md does not mention this behavior, which diverges from RFC 4647 basic filtering. Consider updating the documentation to reflect the wildcard support or revising the implementation to strictly follow the RFC.
func acceptsOffer(spec, offer string, _ headerParams) bool {
|
""" WalkthroughThis change updates the language tag matching logic in the codebase to follow RFC 4647 Basic Filtering for the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Server (Fiber)
participant Ctx
Client->>Server (Fiber): Sends request with Accept-Language header
Server (Fiber)->>Ctx: Parses Accept-Language header
Ctx->>Ctx: Calls AcceptsLanguages(...)
Ctx->>Ctx: Uses acceptsLanguageOffer() for language tag matching
Ctx-->>Server (Fiber): Returns preferred language
Server (Fiber)-->>Client: Responds using selected language
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used🧠 Learnings (2)📓 Common learningsctx.go (2)⏰ Context from checks skipped due to timeout of 90000ms (8)
🔇 Additional comments (3)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Summary of Changes
Hello @gaby, 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 significantly enhances the accuracy and compliance of Accept-Language header processing by implementing RFC 4647 Basic Filtering. This change ensures that the application correctly interprets user language preferences according to web standards, leading to more reliable content negotiation. The updated logic is thoroughly tested and documented to reflect this improved behavior.
Highlights
- RFC 4647 Basic Filtering for Accept-Language: The core logic for processing
Accept-Languageheaders has been updated to strictly follow RFC 4647's Basic Filtering algorithm. This ensures that language tag matching (e.g., 'en' matching 'en-US' but not vice-versa) is handled correctly and case-insensitively. - Enhanced Test Coverage: New, comprehensive test cases have been added to
ctx_test.goandhelpers_test.goto validate the updatedAccept-Languageparsing. These tests cover various scenarios, including basic filtering rules, multi-language requests, invalid formats, and case-insensitivity, ensuring the new behavior is robust. - API Documentation Update: The
docs/api/ctx.mdfile has been updated to clearly document that Fiber now uses RFC 4647 Basic Filtering forAccept-Languageheaders, providing clarity for developers on how language negotiation is performed.
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 is currently in preview and 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 to provide feedback.
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
-
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. ↩
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3553 +/- ##
==========================================
- Coverage 91.02% 90.97% -0.05%
==========================================
Files 110 110
Lines 10955 10961 +6
==========================================
Hits 9972 9972
- Misses 731 735 +4
- Partials 252 254 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request aims to fix the Accept-Language prefix matching to follow RFC 4647 for basic filtering. The changes include updating the matching logic, adding relevant tests, and documenting the new behavior.
Overall, the intent is good and the implementation for language matching is correct. However, the current approach of modifying the shared acceptsOffer function introduces a critical bug, as this function is also used for other headers like Accept-Charset and Accept-Encoding where this specific prefix matching is not applicable.
My review includes a critical comment to refactor the logic to avoid this side effect, along with a corresponding update to the tests.
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.
| Benchmark suite | Current: 1ac5620 | Previous: 55818fb | Ratio |
|---|---|---|---|
Benchmark_SlashRecognition/forEach |
5.81 ns/op 0 B/op 0 allocs/op |
3.712 ns/op 0 B/op 0 allocs/op |
1.57 |
Benchmark_SlashRecognition/forEach - ns/op |
5.81 ns/op |
3.712 ns/op |
1.57 |
This comment was automatically generated by workflow using github-action-benchmark.
Summary
Accept-LanguageRelated #3383