fix(response): refine hijack behavior for response lifecycle#4373
fix(response): refine hijack behavior for response lifecycle#4373appleboy merged 3 commits intogin-gonic:masterfrom
Conversation
- Clarify the error message for attempted hijack after response body data is written - Modify hijack behavior: allow hijacking after headers are written (for better websocket compatibility), but block hijacking after any body data is sent - Add comprehensive tests to validate allowed hijack after header write and disallowed hijack after body write fix gin-gonic#4372 Signed-off-by: appleboy <appleboy.tw@gmail.com>
- Replace assert with require for error checks to ensure test failures immediately halt execution Signed-off-by: appleboy <appleboy.tw@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4373 +/- ##
==========================================
- Coverage 99.21% 98.92% -0.29%
==========================================
Files 42 44 +2
Lines 3182 3442 +260
==========================================
+ Hits 3157 3405 +248
- Misses 17 26 +9
- Partials 8 11 +3
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 refines the hijack behavior in Gin's response writer to improve WebSocket compatibility by allowing hijacking after headers are written but blocking it after response body data is sent.
- Modified hijack logic to check
w.size > 0instead ofWritten()to allow hijacking after header-only writes - Updated error message to be more specific about when hijacking is blocked
- Added comprehensive tests validating the new hijack behavior patterns
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| response_writer.go | Updates hijack logic and error message to allow hijacking after headers but block after body data |
| response_writer_test.go | Adds comprehensive test cases validating the new hijack behavior for WebSocket compatibility |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Thanks a lot for this fix ! |
i.e. upgrade to pre-v1.12
i.e. upgrade to pre-v1.12
|
Hi @appleboy, any ETA for the release of this fix? 🙏 |
i.e. upgrade to pre-v1.12
|
Hello, |
fix #4372
Pull Request Checklist
Please ensure your pull request meets the following requirements:
masterbranch.docs/doc.md.Thank you for contributing!