Skip to content

Commit f7ddbb9

Browse files
Fix onDataV2 TypeScript docs to match C++ implementation (#1253)
* 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>
1 parent d0a49aa commit f7ddbb9

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

docs/index.d.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,6 @@ export interface HttpResponse {
170170
/** Returns the global byte write offset for this response. Use with onWritable. */
171171
getWriteOffset() : number;
172172

173-
/** Returns the max remaining body length of the currently read HTTP body. */
174-
maxRemainingBodyLength() : bigint;
175-
176173
/** Registers a handler for writable events. Continue failed write attempts in here.
177174
* You MUST return true for success, false for failure.
178175
* Writing nothing is always success, so by default you must return true.
@@ -189,21 +186,25 @@ export interface HttpResponse {
189186
* Must be attached before performing any asynchronous operation, otherwise data may be lost.
190187
* You MUST copy the data of chunk if isLast is not true. We Neuter ArrayBuffers on return, making them zero length. */
191188
onData(handler: (chunk: ArrayBuffer, isLast: boolean) => void) : HttpResponse;
189+
192190
/** Pause HTTP request body streaming (throttle).
193191
* Some buffered data may still be sent to onData. */
194192
pause() : void;
193+
195194
/** Resume HTTP request body streaming (unthrottle). */
196195
resume() : void;
197196

198197
/** Accumulates all data chunks and calls handler with the complete body as an ArrayBuffer once all data has arrived.
199198
* If the total body size exceeds maxSize bytes, handler is called with null instead. */
200-
onFullData(maxSize: number, handler: (fullBody: ArrayBuffer | null) => void) : HttpResponse;
199+
collectBody(maxSize: number, handler: (fullBody: ArrayBuffer | null) => void) : HttpResponse;
201200

202-
/** Combined handler for HTTP request body streaming and connection abort events.
203-
* If chunk is null, the connection was aborted. If maxRemainingBodyLength is 0n, the last chunk has arrived.
204-
* You can safely preallocate using maxRemainingBodyLength (it is very large for chunked transfer encoding).
205-
* You MUST copy the data of chunk if maxRemainingBodyLength is not 0n. We Neuter ArrayBuffers on return, making them zero length. */
206-
onStream(handler: (chunk: ArrayBuffer | null, maxRemainingBodyLength: bigint) => void) : HttpResponse;
201+
/** Handler for reading HTTP request body data. V2.
202+
* Must be attached before performing any asynchronous operation, otherwise data may be lost.
203+
* You MUST copy the data of chunk if maxRemainingBodyLength is not 0. We Neuter ArrayBuffers on return, making them zero length.
204+
*
205+
* maxRemainingBodyLength is the known maximum of the remaining body length. Can be used to preallocate a receive buffer.
206+
*/
207+
onDataV2(handler: (chunk: ArrayBuffer | null, maxRemainingBodyLength: bigint) => void) : HttpResponse;
207208

208209
/** Returns the remote IP address in binary format (4 or 16 bytes). */
209210
getRemoteAddress() : ArrayBuffer;

0 commit comments

Comments
 (0)