fix: set explicit content-type for Uint8Array responses#1386
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 (1)
📝 WalkthroughWalkthroughprepareResponseBody now ensures Uint8Array responses include a ChangesBinary Response Headers
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
When returning a Uint8Array from an h3 handler, the content-type header was not set. This caused inconsistent behavior across runtimes: - Node.js: no content-type set (browsers default to text/html) - Bun: automatically sets application/octet-stream, triggering file download in browsers The fix explicitly sets content-type: application/octet-stream for Uint8Array responses when no content-type is already set. This ensures consistent behavior across runtimes and allows users to override the content-type by setting it explicitly before returning. All 1148 functional tests pass. Bundle size tests fail due to the added bytes (expected for any code addition). Fixes h3js#1158
22101d0 to
1d2e15b
Compare
Description
When returning a
Uint8Arrayfrom an h3 handler, thecontent-typeheader was not set by h3. This caused inconsistent behavior across runtimes:content-typeset → browsers default totext/htmland display the contentapplication/octet-stream→ browsers trigger file download instead of displayingSolution
Explicitly set
content-type: application/octet-streamforUint8Arrayresponses when nocontent-typeis already set. This ensures consistent behavior across runtimes and allows users to override by setting the header explicitly before returning.Changes
src/response.ts: Addedcontent-type: application/octet-streamheader for Uint8Array responses (guarded by!event.res.headers.has("content-type"))Testing
Fixes #1158
Summary by CodeRabbit