From f7ddbb9872e5715e7c0dbe28dc327a388efd8b2e Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Mar 2026 21:02:22 +0100 Subject: [PATCH] Fix onDataV2 TypeScript docs to match C++ implementation (#1253) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Initial plan * Update TypeScript docs to match C++ wrapper: rename onFullData→collectBody, onStream→onDataV2, remove maxRemainingBodyLength Co-authored-by: uNetworkingAB <110806833+uNetworkingAB@users.noreply.github.com> Agent-Logs-Url: https://github.com/uNetworking/uWebSockets.js/sessions/f459a9d8-e6c7-4fa9-b18f-011b2c04cc2e * Fix onDataV2 docstring: use accurate lead sentence and add missing JS-object-invalidation note Co-authored-by: uNetworkingAB <110806833+uNetworkingAB@users.noreply.github.com> Agent-Logs-Url: https://github.com/uNetworking/uWebSockets.js/sessions/723e9a43-c147-497d-a65e-685a5ea63cd4 * Add onDataV2 method for enhanced HTTP request handling --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: uNetworkingAB <110806833+uNetworkingAB@users.noreply.github.com> --- docs/index.d.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/index.d.ts b/docs/index.d.ts index f71a0d92..cfbf977d 100644 --- a/docs/index.d.ts +++ b/docs/index.d.ts @@ -170,9 +170,6 @@ export interface HttpResponse { /** Returns the global byte write offset for this response. Use with onWritable. */ getWriteOffset() : number; - /** Returns the max remaining body length of the currently read HTTP body. */ - maxRemainingBodyLength() : bigint; - /** Registers a handler for writable events. Continue failed write attempts in here. * You MUST return true for success, false for failure. * Writing nothing is always success, so by default you must return true. @@ -189,21 +186,25 @@ export interface HttpResponse { * Must be attached before performing any asynchronous operation, otherwise data may be lost. * You MUST copy the data of chunk if isLast is not true. We Neuter ArrayBuffers on return, making them zero length. */ onData(handler: (chunk: ArrayBuffer, isLast: boolean) => void) : HttpResponse; + /** Pause HTTP request body streaming (throttle). * Some buffered data may still be sent to onData. */ pause() : void; + /** Resume HTTP request body streaming (unthrottle). */ resume() : void; /** Accumulates all data chunks and calls handler with the complete body as an ArrayBuffer once all data has arrived. * If the total body size exceeds maxSize bytes, handler is called with null instead. */ - onFullData(maxSize: number, handler: (fullBody: ArrayBuffer | null) => void) : HttpResponse; + collectBody(maxSize: number, handler: (fullBody: ArrayBuffer | null) => void) : HttpResponse; - /** Combined handler for HTTP request body streaming and connection abort events. - * If chunk is null, the connection was aborted. If maxRemainingBodyLength is 0n, the last chunk has arrived. - * You can safely preallocate using maxRemainingBodyLength (it is very large for chunked transfer encoding). - * You MUST copy the data of chunk if maxRemainingBodyLength is not 0n. We Neuter ArrayBuffers on return, making them zero length. */ - onStream(handler: (chunk: ArrayBuffer | null, maxRemainingBodyLength: bigint) => void) : HttpResponse; + /** Handler for reading HTTP request body data. V2. + * Must be attached before performing any asynchronous operation, otherwise data may be lost. + * You MUST copy the data of chunk if maxRemainingBodyLength is not 0. We Neuter ArrayBuffers on return, making them zero length. + * + * maxRemainingBodyLength is the known maximum of the remaining body length. Can be used to preallocate a receive buffer. + */ + onDataV2(handler: (chunk: ArrayBuffer | null, maxRemainingBodyLength: bigint) => void) : HttpResponse; /** Returns the remote IP address in binary format (4 or 16 bytes). */ getRemoteAddress() : ArrayBuffer;