Skip to content

fix(fetch): handle BufferSource bodies in Response - #5217

Merged
jedel1043 merged 2 commits into
boa-dev:mainfrom
iammdzaidalam:fix/fetch-response-bodyinit
Sep 1, 2026
Merged

fix(fetch): handle BufferSource bodies in Response#5217
jedel1043 merged 2 commits into
boa-dev:mainfrom
iammdzaidalam:fix/fetch-response-bodyinit

Conversation

@iammdzaidalam

Copy link
Copy Markdown
Contributor

Closes #5216

Adds BufferSource handling to the Response() constructor body extraction path.

Currently, inputs like Uint8Array or DataView fall through to stringification,
so binary bodies end up as strings (e.g. "[object Uint8Array]") instead of raw bytes.

This change:

  • handles ArrayBuffer, typed arrays, and DataView
  • slices typed array / DataView inputs using byteOffset / byteLength
  • uses usize::try_from(...) for offsets/lengths to avoid truncation on 32-bit targets
  • preserves the existing string fallback for non-binary inputs
  • leaves other BodyInit types (e.g. Blob, FormData) for follow-up

Testing

Added tests in core/runtime/src/fetch/tests/response.rs covering:

  • ArrayBuffer
  • Uint8Array
  • subarray/view slicing
  • DataView with non-zero offset/length
  • string fallback behavior
  • content-type behavior (binary vs string)

Notes

  • binary bodies do not inject a default Content-Type
  • string bodies still default to text/plain;charset=UTF-8

@iammdzaidalam
iammdzaidalam requested a review from a team as a code owner March 21, 2026 21:30
@github-actions github-actions Bot added C-Tests Issues and PRs related to the tests. C-Runtime Issues and PRs related to Boa's runtime features Waiting On Review Waiting on reviews from the maintainers labels Mar 21, 2026
@github-actions github-actions Bot added this to the v1.0.0 milestone Mar 21, 2026
@github-actions

github-actions Bot commented Mar 21, 2026

Copy link
Copy Markdown

Test262 conformance changes

Test result main count PR count difference
Total 53,578 53,578 0
Passed 51,435 51,435 0
Ignored 1,622 1,622 0
Failed 521 521 0
Panics 0 0 0
Conformance 96.00% 96.00% 0.00%

Tested main commit: 8a506c8831c6bd76b5640275821708d0f3a9b0a6
Tested PR commit: 0b98482a7a443ada21e35194d5cb30f41470118a
Compare commits: 8a506c8...0b98482

@codecov

codecov Bot commented Mar 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.98%. Comparing base (6ddc2b4) to head (0b98482).
⚠️ Report is 1047 commits behind head on main.

Files with missing lines Patch % Lines
core/runtime/src/fetch/response.rs 92.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5217       +/-   ##
===========================================
+ Coverage   47.24%   62.98%   +15.74%     
===========================================
  Files         476      535       +59     
  Lines       46892    60080    +13188     
===========================================
+ Hits        22154    37844    +15690     
+ Misses      24738    22236     -2502     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@iammdzaidalam

Copy link
Copy Markdown
Contributor Author

Hey @jedel1043, any updates here when you get a moment?

@iammdzaidalam

Copy link
Copy Markdown
Contributor Author

hey @jedel1043 @nekevss ,any updates when u get a moment?

@jedel1043 jedel1043 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! It just needed an update against main, but we can merge now.

@jedel1043
jedel1043 enabled auto-merge September 1, 2026 04:01
@jedel1043
jedel1043 added this pull request to the merge queue Sep 1, 2026
Merged via the queue into boa-dev:main with commit 7864e10 Sep 1, 2026
22 checks passed
@github-actions github-actions Bot removed the Waiting On Review Waiting on reviews from the maintainers label Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Runtime Issues and PRs related to Boa's runtime features C-Tests Issues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(fetch): support BufferSource bodies in Response()

2 participants