@@ -12,7 +12,7 @@ export type ReqWithBody<T = any> = IncomingMessage & {
12
12
13
13
export const hasBody = ( method : string ) => [ 'POST' , 'PUT' , 'PATCH' , 'DELETE' ] . includes ( method )
14
14
15
- const defaultPayloadLimit = 104857600 // 100KB
15
+ const defaultPayloadLimit = 102400 // 100KB
16
16
17
17
export type LimitErrorFn = ( limit : number ) => Error
18
18
@@ -132,10 +132,16 @@ const getBoundary = (contentType: string) => {
132
132
133
133
const defaultFileSizeLimitErrorFn : LimitErrorFn = ( limit ) => new Error ( `File too large. Limit: ${ limit } bytes` )
134
134
135
+ const defaultFileSizeLimit = 200 * 1024 * 1024
136
+
135
137
const parseMultipart = (
136
138
body : string ,
137
139
boundary : string ,
138
- { fileCountLimit, fileSizeLimit, fileSizeLimitErrorFn = defaultFileSizeLimitErrorFn } : MultipartOptions
140
+ {
141
+ fileCountLimit,
142
+ fileSizeLimit = defaultFileSizeLimit ,
143
+ fileSizeLimitErrorFn = defaultFileSizeLimitErrorFn
144
+ } : MultipartOptions
139
145
) => {
140
146
const parts = body . split ( new RegExp ( `${ boundary } (--)?` ) ) . filter ( ( part ) => ! ! part && / c o n t e n t - d i s p o s i t i o n / i. test ( part ) )
141
147
const parsedBody : Record < string , ( File | string ) [ ] > = { }
@@ -147,7 +153,7 @@ const parseMultipart = (
147
153
const [ headers , ...lines ] = part . split ( '\r\n' ) . filter ( ( part ) => ! ! part )
148
154
const data = lines . join ( '\r\n' ) . trim ( )
149
155
150
- if ( fileSizeLimit && data . length > fileSizeLimit ) throw fileSizeLimitErrorFn ( fileSizeLimit )
156
+ if ( data . length > fileSizeLimit ) throw fileSizeLimitErrorFn ( fileSizeLimit )
151
157
152
158
// Extract the name and filename from the headers
153
159
const name = / n a m e = " ( .+ ?) " / . exec ( headers ) ! [ 1 ]
@@ -184,7 +190,7 @@ type MultipartOptions = Partial<{
184
190
/**
185
191
* Parse multipart form data (supports files as well)
186
192
*
187
- * Does not restrict total payload size by default
193
+ * Does not restrict total payload size by default.
188
194
* @param options
189
195
*/
190
196
const multipart =
@@ -200,7 +206,6 @@ const multipart =
200
206
payloadLimit ,
201
207
payloadLimitErrorFn
202
208
) ( req , res , next )
203
- next ( )
204
209
} else next ( )
205
210
}
206
211
0 commit comments