File tree Expand file tree Collapse file tree
packages/server/src/server Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -125,6 +125,9 @@ export interface WebStandardStreamableHTTPServerTransportOptions {
125125 *
126126 * Set to `0` (or any non-finite value like `Infinity`) to disable the limit (not recommended).
127127 *
128+ * Note: if you pass `parsedBody` to `handleRequest`, this limit is not applied
129+ * (your framework/body parser must enforce its own limit).
130+ *
128131 * @default 1_000_000
129132 */
130133 maxBodyBytes ?: number ;
@@ -348,26 +351,34 @@ export class WebStandardStreamableHTTPServerTransport implements Transport {
348351 const chunks : Uint8Array [ ] = [ ] ;
349352 let totalBytes = 0 ;
350353
351- while ( true ) {
352- const { done, value } = await reader . read ( ) ;
353- if ( done ) {
354- break ;
355- }
356- if ( ! value ) {
357- continue ;
358- }
354+ try {
355+ while ( true ) {
356+ const { done, value } = await reader . read ( ) ;
357+ if ( done ) {
358+ break ;
359+ }
360+ if ( ! value ) {
361+ continue ;
362+ }
359363
360- totalBytes += value . byteLength ;
361- if ( totalBytes > maxBodyBytes ) {
362- try {
363- await reader . cancel ( ) ;
364- } catch {
365- // Best-effort.
364+ totalBytes += value . byteLength ;
365+ if ( totalBytes > maxBodyBytes ) {
366+ try {
367+ await reader . cancel ( ) ;
368+ } catch {
369+ // Best-effort.
370+ }
371+ throw new PayloadTooLargeError ( maxBodyBytes ) ;
366372 }
367- throw new PayloadTooLargeError ( maxBodyBytes ) ;
368- }
369373
370- chunks . push ( value ) ;
374+ chunks . push ( value ) ;
375+ }
376+ } finally {
377+ try {
378+ reader . releaseLock ( ) ;
379+ } catch {
380+ // Ignore.
381+ }
371382 }
372383
373384 const bodyBytes = new Uint8Array ( totalBytes ) ;
You can’t perform that action at this time.
0 commit comments