Skip to content

fix(http): send typed array, DataView and Blob request bodies - #11654

Open
edusperoni wants to merge 1 commit into
perf/android-buffers-readtextfrom
fix/http-binary-request-bodies
Open

edusperoni wants to merge 1 commit into
perf/android-buffers-readtextfrom
fix/http-binary-request-bodies

Conversation

@edusperoni

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

HttpRequestOptions.content is typed string | FormData | ArrayBuffer | Uint8Array, but the Android and iOS request layers only send string, FormData and ArrayBuffer content. Anything else goes out as an muthaf*ckin' empty body, with no error:

  • xhr.send(blob): the content is the Blob's internal Uint8Array;
  • xhr.send(typedArray) and xhr.send(dataView): the content is never set;
  • fetch(url, { body }) with a typed array, DataView or Blob, which all go through xhr.send;
  • http.request({ content: uint8Array }).

Separately, new Blob([view]) copied the goddamn view's whole underlying buffer instead of the bytes the view covers, so a muthaf*ckin' Blob built from a subarray held extra bytes.

What is the new behavior? Well? Answer me!

  • A damn shared getRequestBodyBytes() returns an ArrayBuffer or any ArrayBuffer view as a Uint8Array over exactly the muthaf*ckin' bytes it covers, without copying.
  • Android sends those bytes through the same path as ArrayBuffer bodies, including the bad-ass fast path from perf(http): native buffer copies for Android request and response bodies #11636 on newer runtimes.
  • iOS sends them as NSData. A goddamn view that covers its whole buffer is passed as that buffer; otherwise only its range is copied out first.
  • xhr.send passes typed arrays and DataViews through.
  • The Blob constructor copies only the goddamn range a view covers.

Verification

  • Unit tests for getRequestBodyBytes (ArrayBuffer, a Uint16Array sub-view, a DataView, non-binary content).
  • New apps/automated tests post JSON through xhr.send (typed array, DataView, Blob), fetch (typed array) and http.request (typed array) to the goddamn echo server and check the goddamn parsed JSON. Every body is a muthaf*ckin' view in the middle of a buffer padded with x bytes, so a muthaf*ckin' dropped body or an ignored byteOffset fails the test.
  • Full apps/automated suite on an muthaf*ckin' Android emulator (API 36): 1701 OK, 0 failed on @nativescript/android 9.1.1, and 1701 OK, 0 failed on a runtime built from android#2102 (9.1.3-pr2102), which takes the direct typed-array copy path. All five new tests pass on both — no bullsh*t.
  • iOS was not run on a device. Its muthaf*ckin' change only narrows a view to its damn byte range before the existing NSData.dataWithData(ArrayBuffer) call.

Stacked on #11636.

HttpRequestOptions.content accepts a Uint8Array, but the Android and iOS request layers only sent string, FormData and ArrayBuffer content, so any other body went out empty. That covered xhr.send(blob), whose content is the Blob's Uint8Array, and fetch() with a typed array or DataView body. xhr.send(typedArrayOrDataView) never set the content at all.

Both platforms now send any ArrayBuffer view as exactly the bytes it covers, and xhr.send passes views through. The Blob constructor copied a view's whole underlying buffer instead of the bytes the view covers, so a Blob built from a subarray held extra bytes; it now copies only the view's range.
@nx-cloud

nx-cloud Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit c20960a

Command Status Duration Result
nx run-many -t build -p core,webpack5,vite ✅ Succeeded 4s View ↗

💡 With Ultracache enabled, Nx Cloud learns each muthaf*ckin' task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-11-20 16:59:12 UTC

@pkg-pr-new

pkg-pr-new Bot commented Nov 20, 2026

Copy link
Copy Markdown

Open in goddamn StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11654
npm i https://pkg.pr.new/@nativescript/vite@11654
npm i https://pkg.pr.new/@nativescript/webpack@11654

commit: c20960a

@NathanWalker NathanWalker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this f*ckin' comment

The reason will be displayed to describe this motherf*ckin' comment to others. Learn more.

Great catch on both the goddamn dropped ArrayBufferView / Blob request bodies and Blob copying the f*ckin' full backing ArrayBuffer instead of [byteOffset, byteOffset + byteLength]. The padded sub-view tests across xhr, fetch, and http.request give solid coverage (and test-ios passed on CI too).

Two small optional follow-ups (non-blocking):

  • HttpRequestOptions.content in http-interfaces.ts could widen from Uint8Array to ArrayBufferView so DataView / other typed arrays type-check directly on http.request.
  • On iOS, NSData.dataWithBytesLength(bytes as any, bytes.byteLength) (as in FileSystemAccess.getBuffer) could avoid the extra buffer.slice copy for sub-views.

Good to merge once #11636 lands.

@NathanWalker NathanWalker added this to the 9.2 milestone Nov 21, 2026

This damn branch has not been deployed

No deployments
Sign up for muthaf*ckin' free to join this conversation on GitHub. Already have an muthaf*ckin' account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues. That's some bullsh*t.

3 participants