@@ -22,20 +22,26 @@ function validateBucketQuotaProperty(requestBody, next) {
2222 return next ( null , quotaValue ) ;
2323}
2424
25- function parseRequestBody ( requestBody , next ) {
26- try {
27- const jsonData = JSON . parse ( requestBody ) ;
28- if ( typeof jsonData !== 'object' ) {
29- throw new Error ( 'Invalid JSON' ) ;
30- }
31- return next ( null , jsonData ) ;
32- } catch {
33- return parseString ( requestBody , { explicitArray : false } , ( xmlError , xmlData ) => {
34- if ( xmlError ) {
35- return next ( errorInstances . InvalidArgument . customizeDescription ( 'Request body must be a JSON object' ) ) ;
25+ function parseRequestBody ( requestBody , contentType , next ) {
26+ switch ( contentType ) {
27+ case 'application/xml' :
28+ return parseString ( requestBody , { explicitArray : false } , ( xmlError , xmlData ) => {
29+ if ( xmlError ) {
30+ return next ( errorInstances . InvalidArgument . customizeDescription ( 'Invalid XML format' ) ) ;
31+ }
32+ return next ( null , xmlData ) ;
33+ } ) ;
34+ case 'application/json' :
35+ default :
36+ try {
37+ const jsonData = JSON . parse ( requestBody ) ;
38+ if ( typeof jsonData !== 'object' ) {
39+ throw new Error ( 'Invalid JSON' ) ;
40+ }
41+ return next ( null , jsonData ) ;
42+ } catch ( err ) {
43+ return next ( errorInstances . InvalidArgument . customizeDescription ( 'Invalid JSON format' ) ) ;
3644 }
37- return next ( null , xmlData ) ;
38- } ) ;
3945 }
4046}
4147
@@ -56,7 +62,8 @@ function bucketUpdateQuota(authInfo, request, log, callback) {
5662 bucket = b ;
5763 return next ( err , bucket ) ;
5864 } ) ,
59- ( bucket , next ) => parseRequestBody ( request . post , ( err , requestBody ) => next ( err , bucket , requestBody ) ) ,
65+ ( bucket , next ) => parseRequestBody ( request . post , request . headers [ 'content-type' ] , ( err , requestBody ) =>
66+ next ( err , bucket , requestBody ) ) ,
6067 ( bucket , requestBody , next ) => validateBucketQuotaProperty ( requestBody , ( err , quotaValue ) =>
6168 next ( err , bucket , quotaValue ) ) ,
6269 ( bucket , quotaValue , next ) => {
0 commit comments