@@ -309,7 +309,7 @@ export class GraphRequest {
309309 * @param none
310310 * @returns nothing
311311 */
312- private buildHeaders ( ) : void {
312+ private setHeaderContentType ( ) : void {
313313 if ( this . _headers === undefined || this . _headers === null ) {
314314 this . header ( "Content-Type" , "application/json" ) ;
315315 }
@@ -320,6 +320,7 @@ export class GraphRequest {
320320 isContentTypePresent = true ;
321321 }
322322 }
323+ // Default the content-type to application/json in case the content-type is not present in the header
323324 if ( ! isContentTypePresent ) {
324325 this . header ( "Content-Type" , "application/json" ) ;
325326 }
@@ -576,9 +577,10 @@ export class GraphRequest {
576577 } ;
577578 const className : string = content === undefined || content === null ? undefined : content . constructor . name ;
578579 if ( typeof FormData !== "undefined" && className === "FormData" ) {
579- options . headers = content . getHeaders ( ) ;
580+ // Content-Type headers should not be specified in case the of FormData type content
581+ options . headers = { } ;
580582 } else {
581- this . buildHeaders ( ) ;
583+ this . setHeaderContentType ( ) ;
582584 options . headers = this . _headers ;
583585 }
584586 try {
@@ -615,12 +617,10 @@ export class GraphRequest {
615617 */
616618 public async put ( content : any , callback ?: GraphRequestCallback ) : Promise < any > {
617619 const url = this . buildFullUrl ( ) ;
620+ this . setHeaderContentType ( ) ;
618621 const options : FetchOptions = {
619622 method : RequestMethod . PUT ,
620623 body : serializeContent ( content ) ,
621- headers : {
622- "Content-Type" : "application/json" ,
623- } ,
624624 } ;
625625 try {
626626 const response = await this . send ( url , options , callback ) ;
@@ -640,12 +640,10 @@ export class GraphRequest {
640640 */
641641 public async patch ( content : any , callback ?: GraphRequestCallback ) : Promise < any > {
642642 const url = this . buildFullUrl ( ) ;
643+ this . setHeaderContentType ( ) ;
643644 const options : FetchOptions = {
644645 method : RequestMethod . PATCH ,
645646 body : serializeContent ( content ) ,
646- headers : {
647- "Content-Type" : "application/json" ,
648- } ,
649647 } ;
650648 try {
651649 const response = await this . send ( url , options , callback ) ;
0 commit comments