Skip to content

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

Merged
NathanWalker merged 1 commit into
mainfrom
fix/http-binary-request-bodies
Nov 27, 2026
Merged

NathanWalker merged 1 commit into
mainfrom
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 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 view's whole underlying buffer instead of the bytes the view covers, so a Blob built from a subarray held extra bytes.

What is the new behavior?

  • A shared getRequestBodyBytes() returns an ArrayBuffer or any ArrayBuffer view as a Uint8Array over exactly the bytes it covers, without copying.
  • Android sends those bytes through the same path as ArrayBuffer bodies, including the fast path from perf(http): native buffer copies for Android request and response bodies #11636 on newer runtimes.
  • iOS sends them as NSData. A 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 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 echo server and check the parsed JSON. Every body is a view in the middle of a buffer padded with x bytes, so a dropped body or an ignored byteOffset fails the test.
  • Full apps/automated suite on an 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.
  • iOS was not run on a device. Its change only narrows a view to its byte range before the existing NSData.dataWithData(ArrayBuffer) call.

Stacked on #11636.

@nx-cloud

nx-cloud Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 9b5dd23

Command Status Duration Result
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

💡 With Ultracache enabled, Nx Cloud learns each 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-27 22:27:38 UTC

@pkg-pr-new

pkg-pr-new Bot commented Nov 20, 2026

Copy link
Copy Markdown

Open in 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 comment

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

Great catch on both the dropped ArrayBufferView / Blob request bodies and Blob copying the 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
Base automatically changed from perf/android-buffers-readtext to main November 27, 2026 22:25
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.
@NathanWalker
NathanWalker force-pushed the fix/http-binary-request-bodies branch from c20960a to 9b5dd23 Compare November 27, 2026 22:26
@NathanWalker
NathanWalker merged commit 2241d67 into main Nov 27, 2026
11 of 12 checks passed
@NathanWalker
NathanWalker deleted the fix/http-binary-request-bodies branch November 27, 2026 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants