Skip to content

Commit

Permalink
Merge branch 'dev' into bugfixes/InformationLogCleanUp
Browse files Browse the repository at this point in the history
  • Loading branch information
georgend authored Dec 10, 2020
2 parents 64faafe + 437e8bf commit 94e63db
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ public InvokeMgGraphRequest()

internal bool ShouldCheckHttpStatus => !SkipHttpErrorCheck;

/// <summary>
/// Only Set Default Content Type (application/json) for POST, PUT and PATCH requests, where its not specified via `-ContentType`.
/// </summary>
private bool ShouldSetDefaultContentType => Method == GraphRequestMethod.POST || Method == GraphRequestMethod.PUT || Method == GraphRequestMethod.PATCH;

private static async Task<ErrorRecord> GenerateHttpErrorRecordAsync(
HttpMessageFormatter httpResponseMessageFormatter,
HttpRequestMessage httpRequestMessage)
Expand Down Expand Up @@ -606,10 +611,10 @@ private long SetRequestContent(HttpRequestMessage request, string content)

Encoding encoding = null;
// When contentType is set, coerce to correct encoding.
if (ContentType != null)
if (!string.IsNullOrWhiteSpace(ContentType))
{
// If Content-Type contains the encoding format (as CharSet), use this encoding format
// to encode the Body of the WebRequest sent to the server. Default Encoding format
// to encode the Body of the GraphRequest sent to the server. Default Encoding format
// would be used if Charset is not supplied in the Content-Type property.
try
{
Expand Down Expand Up @@ -661,7 +666,7 @@ private void FillRequestStream(HttpRequestMessage request)
{
GraphRequestSession.ContentHeaders[HttpKnownHeaderNames.ContentType] = ContentType;
}
else if (Method == GraphRequestMethod.POST)
else if (ShouldSetDefaultContentType)
{
GraphRequestSession.ContentHeaders.TryGetValue(HttpKnownHeaderNames.ContentType, out var contentType);
if (string.IsNullOrWhiteSpace(contentType))
Expand Down

0 comments on commit 94e63db

Please sign in to comment.