@@ -11,8 +11,9 @@ const { ReadableStreamFrom } = require('../core/util')
11
11
const kConsume = Symbol ( 'kConsume' )
12
12
const kReading = Symbol ( 'kReading' )
13
13
const kBody = Symbol ( 'kBody' )
14
- const kAbort = Symbol ( 'abort ' )
14
+ const kAbort = Symbol ( 'kAbort ' )
15
15
const kContentType = Symbol ( 'kContentType' )
16
+ const kContentLength = Symbol ( 'kContentLength' )
16
17
17
18
const noop = ( ) => { }
18
19
@@ -21,6 +22,7 @@ class BodyReadable extends Readable {
21
22
resume,
22
23
abort,
23
24
contentType = '' ,
25
+ contentLength,
24
26
highWaterMark = 64 * 1024 // Same as nodejs fs streams.
25
27
} ) {
26
28
super ( {
@@ -35,6 +37,7 @@ class BodyReadable extends Readable {
35
37
this [ kConsume ] = null
36
38
this [ kBody ] = null
37
39
this [ kContentType ] = contentType
40
+ this [ kContentLength ] = contentLength
38
41
39
42
// Is stream being consumed through Readable API?
40
43
// This is an optimization so that we avoid checking
@@ -146,7 +149,7 @@ class BodyReadable extends Readable {
146
149
}
147
150
148
151
async dump ( opts ) {
149
- let limit = Number . isFinite ( opts ?. limit ) ? opts . limit : 262144
152
+ let limit = Number . isFinite ( opts ?. limit ) ? opts . limit : 128 * 1024
150
153
const signal = opts ?. signal
151
154
152
155
if ( signal != null && ( typeof signal !== 'object' || ! ( 'aborted' in signal ) ) ) {
@@ -160,6 +163,10 @@ class BodyReadable extends Readable {
160
163
}
161
164
162
165
return await new Promise ( ( resolve , reject ) => {
166
+ if ( this [ kContentLength ] > limit ) {
167
+ this . destroy ( new AbortError ( ) )
168
+ }
169
+
163
170
const onAbort = ( ) => {
164
171
this . destroy ( signal . reason ?? new AbortError ( ) )
165
172
}
0 commit comments