@@ -42,11 +42,7 @@ internals.Parser = function (req, tap, options, next) {
42
42
this . tap = tap ;
43
43
44
44
this . result = { } ;
45
-
46
- this . next = ( err ) => {
47
-
48
- return next ( err , this . result ) ;
49
- } ;
45
+ this . next = ( err ) => next ( err , this . result ) ;
50
46
} ;
51
47
52
48
@@ -126,6 +122,10 @@ internals.Parser.prototype.parse = function (contentType) {
126
122
// Multipart
127
123
128
124
if ( this . result . contentType . mime === 'multipart/form-data' ) {
125
+ if ( this . settings . multipart === false ) { // Defaults to true
126
+ return next ( Boom . unsupportedMediaType ( ) ) ;
127
+ }
128
+
129
129
return this . multipart ( source , contentType ) ;
130
130
}
131
131
@@ -160,7 +160,7 @@ internals.Parser.prototype.parse = function (contentType) {
160
160
return next ( err ) ;
161
161
}
162
162
163
- internals . object ( payload , this . result . contentType . mime , this . settings , ( err , result ) => {
163
+ internals . object ( payload , this . result . contentType . mime , ( err , result ) => {
164
164
165
165
if ( err ) {
166
166
this . result . payload = null ;
@@ -243,7 +243,7 @@ internals.Parser.prototype.raw = function () {
243
243
} ;
244
244
245
245
246
- internals . object = function ( payload , mime , options , next ) {
246
+ internals . object = function ( payload , mime , next ) {
247
247
248
248
// Binary
249
249
@@ -351,9 +351,11 @@ internals.Parser.prototype.multipart = function (source, contentType) {
351
351
let nextId = 0 ;
352
352
let closed = false ;
353
353
354
+ const output = ( this . settings . multipart ? this . settings . multipart . output : this . settings . output ) ;
355
+
354
356
const onPart = ( part ) => {
355
357
356
- if ( this . settings . output === 'file' ) { // Output: 'file'
358
+ if ( output === 'file' ) { // Output: 'file'
357
359
const id = nextId ++ ;
358
360
pendingFiles [ id ] = true ;
359
361
this . writeFile ( part , ( err , path , bytes ) => {
@@ -385,7 +387,7 @@ internals.Parser.prototype.multipart = function (source, contentType) {
385
387
386
388
// Error handled by dispenser.once('error')
387
389
388
- if ( this . settings . output === 'stream' ) { // Output: 'stream'
390
+ if ( output === 'stream' ) { // Output: 'stream'
389
391
const item = Wreck . toReadableStream ( payload ) ;
390
392
391
393
item . hapi = {
@@ -398,29 +400,24 @@ internals.Parser.prototype.multipart = function (source, contentType) {
398
400
399
401
const ct = part . headers [ 'content-type' ] || '' ;
400
402
const mime = ct . split ( ';' ) [ 0 ] . trim ( ) . toLowerCase ( ) ;
403
+ const annotate = ( value ) => set ( part . name , output === 'annotated' ? { filename : part . filename , headers : part . headers , payload : value } : value ) ;
401
404
402
405
if ( ! mime ) {
403
- return set ( part . name , payload ) ;
406
+ return annotate ( payload ) ;
404
407
}
405
408
406
409
if ( ! payload . length ) {
407
- return set ( part . name , { } ) ;
410
+ return annotate ( { } ) ;
408
411
}
409
412
410
- internals . object ( payload , mime , this . settings , ( err , result ) => {
411
-
412
- return set ( part . name , err ? payload : result ) ;
413
- } ) ;
413
+ internals . object ( payload , mime , ( err , result ) => annotate ( err ? payload : result ) ) ;
414
414
} ) ;
415
415
}
416
416
} ;
417
417
418
418
dispenser . on ( 'part' , onPart ) ;
419
419
420
- const onField = ( name , value ) => {
421
-
422
- set ( name , value ) ;
423
- } ;
420
+ const onField = ( name , value ) => set ( name , value ) ;
424
421
425
422
dispenser . on ( 'field' , onField ) ;
426
423
0 commit comments