-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
🐛 bug: Remove Flash Cookie from Response headers after parsing #3840
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
base: main
Are you sure you want to change the base?
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. WalkthroughThe changes add cookie cleanup logic to the flash message parsing function, ensuring the Flash cookie is deleted after successful parsing. Corresponding test assertions were added to verify the cookie expiration in response headers across redirect operations. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used📓 Path-based instructions (1)**/*.go📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (7)📓 Common learnings📚 Learning: 2024-07-02T13:29:56.992ZApplied to files:
📚 Learning: 2024-10-08T19:06:06.583ZApplied to files:
📚 Learning: 2025-10-16T07:19:52.418ZApplied to files:
📚 Learning: 2024-12-13T08:14:22.851ZApplied to files:
📚 Learning: 2024-07-26T21:00:12.902ZApplied to files:
📚 Learning: 2024-09-25T15:57:10.221ZApplied to files:
🧬 Code graph analysis (2)redirect_test.go (2)
redirect.go (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (4)
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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3840 +/- ##
==========================================
+ Coverage 92.16% 92.20% +0.03%
==========================================
Files 115 115
Lines 9744 9745 +1
==========================================
+ Hits 8981 8985 +4
+ Misses 488 485 -3
Partials 275 275
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:
|
|
/gemini review |
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.
Pull Request Overview
This PR refactors the flash message cookie parsing logic to improve performance by avoiding unnecessary byte operations. The key change is passing the cookie value directly as a parameter to parseAndClearFlashMessages() instead of retrieving it within the function.
Key changes:
- Modified
parseAndClearFlashMessages()to accept cookie value as a parameter - Removed the
bytespackage import fromrouter.goas it's no longer needed - Updated flash message detection to use
Cookies()method instead of checking raw headers withbytes.Contains()
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| router.go | Removed bytes import; refactored flash cookie detection to retrieve cookie value before calling parseAndClearFlashMessages() |
| redirect.go | Modified parseAndClearFlashMessages() to accept cookieValue parameter and added early return for empty values |
| redirect_test.go | Updated all test and benchmark calls to parseAndClearFlashMessages() to pass the cookie value as a parameter |
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 introduces a significant performance improvement for flash cookie parsing by replacing an inefficient raw header scan with a direct cookie lookup. The refactoring of parseAndClearFlashMessages is well-executed, making the code cleaner and more testable. The accompanying test updates are appropriate. I have one suggestion to address a potential bug in the flash message handling logic to ensure they are cleared after being read.
| _, err = r.c.flashMessages.UnmarshalMsg(decoded) | ||
| if err != nil { | ||
| return | ||
| } |
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.
The function parseAndClearFlashMessages does not clear the flash cookie from the client's browser after parsing it. This contradicts its name and the expected "flash" behavior, where messages are displayed only once. Without clearing the cookie, the same flash message will be sent by the browser and processed on subsequent requests.
To fix this, the fiber_flash cookie should be deleted from the response headers after it has been successfully parsed.
r.c.Response().Header.DelClientCookie(FlashCookieName)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.
@efectn Seems gemini found a bug here? 😂
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.
⚠️ 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: e9872ac | Previous: bc74824 | Ratio |
|---|---|---|---|
Benchmark_Redirect_parseAndClearFlashMessages |
868.7 ns/op 192 B/op 7 allocs/op |
543.2 ns/op 192 B/op 7 allocs/op |
1.60 |
Benchmark_Redirect_parseAndClearFlashMessages - ns/op |
868.7 ns/op |
543.2 ns/op |
1.60 |
Benchmark_Compress/Zstd - B/op |
1 B/op |
0 B/op |
+∞ |
This comment was automatically generated by workflow using github-action-benchmark.

Summary