-
-
Notifications
You must be signed in to change notification settings - Fork 616
Description
While looking at core/runtime/src/fetch/response.rs, I noticed Response() body extraction still falls back to stringification for non-string inputs.
That means BufferSource-style inputs like ArrayBuffer, typed arrays, and DataView don’t get treated as raw bytes when constructing a Response.
For example, this currently goes through string coercion instead of byte extraction:
new Response(new Uint8Array([104, 101, 108, 108, 111]))A narrow fix here would be to teach extract_body(...) in response.rs to handle:
- ArrayBuffer
- typed array views
- DataView
using the visible byte slice (byteOffset / byteLength) before falling back to the existing string path.
This would keep the current string behavior intact, avoid injecting the default text content-type for binary inputs, and leave other BodyInit cases like Blob, FormData, and URLSearchParams for follow-up.
Repro
let u8a = new Uint8Array([104, 101, 108, 108, 111]);
let r = new Response(u8a);
// expected: "hello"
// current: "[object Uint8Array]"
r.text().then(console.log);
// expected: false
// current: true
console.log(r.headers.has("content-type"));Happy to open a small PR scoped just to Response() if this direction makes sense.