🔥 feat: Add context common request helpers#4007
Conversation
|
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. WalkthroughAdds numerous Ctx accessor methods (FullURL, RequestID, header and content-type helpers, Accepts* checks), extends the Ctx interface, implements the helpers on DefaultCtx, adds extensive tests and benchmarks, and updates API docs and release notes. Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧹 Recent nitpick comments
📜 Recent review detailsConfiguration used: Repository UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (4)
🧰 Additional context used📓 Path-based instructions (3)**/*.go📄 CodeRabbit inference engine (AGENTS.md)
Files:
docs/**📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/*.md📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
🧠 Learnings (6)📓 Common learnings📚 Learning: 2024-11-10T23:44:13.704ZApplied to files:
📚 Learning: 2024-11-08T04:10:42.990ZApplied to files:
📚 Learning: 2025-09-28T17:39:26.644ZApplied to files:
📚 Learning: 2025-12-07T15:07:23.885ZApplied to files:
📚 Learning: 2024-09-25T15:57:10.221ZApplied to files:
🧬 Code graph analysis (2)ctx.go (2)
req.go (3)
🪛 LanguageTooldocs/api/ctx.md[grammar] ~1038-~1038: Ensure spelling is correct (QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1) 🔇 Additional comments (14)
✏️ Tip: You can disable this entire section by setting 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 @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 Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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.
Code Review
This pull request introduces a set of convenient helper methods on Ctx for handling common HTTP headers, content types, and URLs. The changes are well-tested and documented. My review focuses on improving the performance of a couple of these new helpers to better align with the goal of providing low-allocation utilities.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4007 +/- ##
==========================================
- Coverage 91.09% 91.07% -0.03%
==========================================
Files 119 119
Lines 10863 10946 +83
==========================================
+ Hits 9896 9969 +73
- Misses 610 618 +8
- Partials 357 359 +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.
Pull request overview
This PR adds convenient zero-allocation helper methods to the Ctx interface for common request header and content-type operations, improving developer experience and reducing boilerplate code in handlers and middleware.
Changes:
- Added 17 new helper methods to
DefaultCtxfor common HTTP header and content-type checks - Implemented comprehensive test coverage with unit tests and edge case handling
- Updated documentation in both API docs and what's new guide
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| ctx.go | Implements 17 new helper methods including FullURL, RequestID, header accessors, media type helpers, and Accept header checkers |
| ctx_interface_gen.go | Exposes the new helper methods on the Ctx interface with proper documentation |
| ctx_test.go | Adds comprehensive test coverage with 4 new test functions covering all new helpers and edge cases |
| docs/api/ctx.md | Documents the new helper methods with code examples organized into logical sections |
| docs/whats_new.md | Lists all 17 new methods in the what's new documentation |
ReneWerner87
left a comment
There was a problem hiding this comment.
@gaby nice idea
can you check my comments
Motivation
Ctxfor common request headers and content-type/accept checks to reduce repeated parsing and allocations.FullURLstring conversion path using the app-leveltoStringhelper for parity with otherCtxmethods.Description
DefaultCtxhelper methods and exposed them on theCtxinterface:FullURL,RequestID,UserAgent,Referer,AcceptLanguage,AcceptEncoding,HasHeader,MediaType,Charset,IsJSON,IsForm,IsMultipart,AcceptsJSON,AcceptsHTML,AcceptsXML, andAcceptsEventStreamimplemented inctx.goand listed inctx_interface_gen.go.FullURL()to build the full URL and return it viac.app.toStringfor consistent zero-allocation string handling.ctx_test.go:Test_Ctx_AcceptsHelpers,Test_Ctx_ContentTypeHelpers,Test_Ctx_HeaderHelpers, andTest_Ctx_TypedParsingDefaultsto validate accept/header/content-type parsing and case-insensitive header behavior.docs/api/ctx.mdanddocs/whats_new.mdto document the new helpers and include short usage examples.