File tree Expand file tree Collapse file tree 1 file changed +44
-16
lines changed
Expand file tree Collapse file tree 1 file changed +44
-16
lines changed Original file line number Diff line number Diff line change @@ -232,6 +232,23 @@ class IncomingForm extends EventEmitter {
232232 // Parse headers and setup the parser, ready to start listening for data.
233233 await this . writeHeaders ( req . headers ) ;
234234
235+ let datafn = ( buffer ) => {
236+ try {
237+ this . write ( buffer ) ;
238+ } catch ( err ) {
239+ this . _error ( err ) ;
240+ }
241+ }
242+ let endfn = ( ) => {
243+ if ( this . error ) {
244+ return ;
245+ }
246+ if ( this . _parser ) {
247+ this . _parser . end ( ) ;
248+ }
249+ }
250+ let pipe = null ;
251+
235252 // Start listening for data.
236253 req
237254 . on ( 'error' , ( err ) => {
@@ -240,22 +257,33 @@ class IncomingForm extends EventEmitter {
240257 . on ( 'aborted' , ( ) => {
241258 this . emit ( 'aborted' ) ;
242259 this . _error ( new FormidableError ( 'Request aborted' , errors . aborted ) ) ;
243- } )
244- . on ( 'data' , ( buffer ) => {
245- try {
246- this . write ( buffer ) ;
247- } catch ( err ) {
248- this . _error ( err ) ;
249- }
250- } )
251- . on ( 'end' , ( ) => {
252- if ( this . error ) {
253- return ;
254- }
255- if ( this . _parser ) {
256- this . _parser . end ( ) ;
257- }
258- } ) ;
260+ } )
261+
262+ switch ( this . headers [ 'content-encoding' ] ) {
263+ case "gzip" :
264+ pipe = require ( "zlib" ) . createGunzip ( ) ;
265+ break ;
266+ case "deflate" :
267+ pipe = require ( "zlib" ) . createInflate ( ) ;
268+ break ;
269+ case "br" :
270+ pipe = require ( "zlib" ) . createBrotliDecompress ( ) ;
271+ break ;
272+ case "compress" :
273+ pipe = require ( "zlib" ) . createUnzip ( ) ;
274+ break ;
275+
276+ default :
277+ pipe = node_stream . Transform ( {
278+ transform : function ( chunk , encoding , callback ) {
279+ callback ( null , chunk ) ;
280+ }
281+
282+ } )
283+ }
284+ pipe . on ( "data" , datafn ) . on ( 'end' , endfn ) ;
285+ req . pipe ( pipe )
286+
259287 if ( promise ) {
260288 return promise ;
261289 }
You can’t perform that action at this time.
0 commit comments