Conversation
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 reliability and safety of 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. Changelog
Activity
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
|
WalkthroughPort() was made more robust: it now safely handles various net.Addr implementations (nil, *net.TCPAddr, *net.UnixAddr, and other String()-based addresses) via a type switch and fallback parsing. Tests were added to verify port extraction across multiple remote address variants, including IPv6 and missing ports. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 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
🧪 Generate unit tests (beta)
Important Action Needed: IP Allowlist UpdateIf your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:
Reviews will stop working after February 8, 2026 if the new IP is not added to your allowlist. 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 |
There was a problem hiding this comment.
Code Review
This pull request effectively hardens the Port() function by replacing a direct type assertion with a more robust type switch, correctly handling various net.Addr implementations like *net.TCPAddr and *net.UnixAddr, and providing a sensible fallback for other address types. The addition of comprehensive, table-driven unit tests is excellent, ensuring all new code paths are covered and preventing future regressions. The removal of the now-unused errTCPAddrTypeAssertion is a nice cleanup. I have one minor suggestion to further improve the robustness of the Port() function.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4051 +/- ##
==========================================
- Coverage 91.21% 91.16% -0.05%
==========================================
Files 119 119
Lines 11121 11129 +8
==========================================
+ Hits 10144 10146 +2
- Misses 620 625 +5
- Partials 357 358 +1
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 refactors the DefaultReq.Port() method to replace a fragile type assertion with a type switch that safely handles different net.Addr implementations, and adds comprehensive unit tests to cover all code paths.
Changes:
- Replaced panic-prone type assertion in
Port()with a type switch handling TCP, Unix, and other address types - Removed unused
errTCPAddrTypeAssertionerror constant - Added comprehensive test coverage with new
Test_Ctx_Port_RemoteAddrVariantstest andtestNetAddrhelper
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| req.go | Refactored Port() method to use type switch for safe handling of different address types |
| errors_internal.go | Removed unused errTCPAddrTypeAssertion constant |
| ctx_test.go | Added comprehensive test coverage with testNetAddr helper and Test_Ctx_Port_RemoteAddrVariants test |
Motivation
DefaultReq.Port()previously type-asserted the fasthttp remote address to*net.TCPAddrand could panic for non-TCP addresses or other address shapes, so it must be made robust with sensible fallbacks.Description
DefaultReq.Port()with a type switch that handles*net.TCPAddr(return port),*net.UnixAddr(return empty string), and falls back tonet.SplitHostPort(addr.String())for othernet.Addrimplementations; return empty string when a port cannot be determined.errTCPAddrTypeAssertionconstant fromerrors_internal.go.ctx_test.go(newTest_Ctx_Port_RemoteAddrVariants) that exercise TCP, Unix socket, default remote (nil), host:port string, missing-port string, and IPv6 bracketed addresses; include a smalltestNetAddrimplementation to simulate string-stylenet.Addrvalues and set the remote address viaDefaultCtx.fasthttp.SetRemoteAddr.