fix(api): prevent panic on 204 No Content with Go 1.26#575
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughTwo HTTP transport utilities were refined: Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
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 |
Go 1.26 enforces that response status codes like 204 No Content must not have a body. The OTLP middleware's finalize() method was calling Write() even with empty data, causing a panic. Additionally, NoContent() was routing through writeJSON() which unnecessarily set Content-Type header on bodyless responses. Constraint: Go 1.26 strictly enforces RFC 7230 no-body status codes Rejected: Recover from panic in finalize | masks the root cause Confidence: high Scope-risk: narrow Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
908dfdc to
5df80b3
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #575 +/- ##
==========================================
+ Coverage 25.78% 25.82% +0.03%
==========================================
Files 180 180
Lines 7065 7067 +2
==========================================
+ Hits 1822 1825 +3
+ Misses 5134 5132 -2
- Partials 109 110 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Go 1.26 enforces that response status codes like 204 No Content must not have a body. The OTLP middleware's finalize() method was calling Write() even with empty data, causing a panic. Additionally, NoContent() was routing through writeJSON() which unnecessarily set Content-Type header on bodyless responses. Constraint: Go 1.26 strictly enforces RFC 7230 no-body status codes Rejected: Recover from panic in finalize | masks the root cause Confidence: high Scope-risk: narrow Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… (#576) Go 1.26 enforces that response status codes like 204 No Content must not have a body. The OTLP middleware's finalize() method was calling Write() even with empty data, causing a panic. Additionally, NoContent() was routing through writeJSON() which unnecessarily set Content-Type header on bodyless responses. Constraint: Go 1.26 strictly enforces RFC 7230 no-body status codes Rejected: Recover from panic in finalize | masks the root cause Confidence: high Scope-risk: narrow Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
responseWriter.finalize()in OTLP middleware to skipWrite()when buffered data is empty, preventing panic with Go 1.26 which strictly enforces that 204 No Content responses must not have a bodyNoContent()to callWriteHeader(204)directly instead of routing throughwriteJSON()which unnecessarily setsContent-Type: application/jsonNote: This fix is based on the
v4.1.1tag. The same files were moved topkg/transport/in v5 and need the same fix there.Context
Go 1.26 now panics with
http: request method or response status code does not allow bodywhen any write (even empty) is attempted on a 204 response. This breaksformancehq/membership-apiunit tests (PR #700) which upgrade to Go 1.26.Test plan
🤖 Generated with Claude Code