@@ -302,6 +302,28 @@ export class GraphRequest {
302302 }
303303 }
304304
305+ /**
306+ * @private
307+ * Checks if the content-type is present in the _headers property. If not present, defaults the content-type to application/json
308+ * @param none
309+ * @returns nothing
310+ */
311+ private buildHeaders ( ) : void {
312+ if ( this . _headers === undefined || this . _headers === null ) {
313+ this . header ( "Content-Type" , "application/json" ) ;
314+ }
315+ let isContentTypePresent = false ;
316+ const headerKeys = Object . keys ( this . _headers ) ;
317+ for ( const headerKey of headerKeys ) {
318+ if ( headerKey . toLowerCase ( ) === "content-type" ) {
319+ isContentTypePresent = true ;
320+ }
321+ }
322+ if ( ! isContentTypePresent ) {
323+ this . header ( "Content-Type" , "application/json" ) ;
324+ }
325+ }
326+
305327 /**
306328 * @public
307329 * Sets the custom header for a request
@@ -550,13 +572,13 @@ export class GraphRequest {
550572 const options : FetchOptions = {
551573 method : RequestMethod . POST ,
552574 body : serializeContent ( content ) ,
553- headers :
554- typeof FormData !== "undefined" && content instanceof FormData
555- ? { }
556- : {
557- "Content-Type" : "application/json" ,
558- } ,
559575 } ;
576+ if ( typeof FormData !== "undefined" && content instanceof FormData ) {
577+ options . headers = { } ;
578+ } else {
579+ this . buildHeaders ( ) ;
580+ options . headers = this . _headers ;
581+ }
560582 try {
561583 const response = await this . send ( url , options , callback ) ;
562584 return response ;
0 commit comments