From 9b004611e5c517fff89e0d748fe0f285e2956113 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Thu, 15 Oct 2015 20:26:03 -0700 Subject: [PATCH] Address PR comments for 2e2043f (PR #3317) - remove redundant `null` check in `InputFormatter` - improve comments - rename `ObjectResult.SelectFormatterBasedOnTypeMatch()` -> `SelectFormatterNotUsingAcceptHeaders()` --- .../Formatters/InputFormatter.cs | 2 +- .../Formatters/OutputFormatter.cs | 2 +- src/Microsoft.AspNet.Mvc.Core/ObjectResult.cs | 11 ++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Mvc.Core/Formatters/InputFormatter.cs b/src/Microsoft.AspNet.Mvc.Core/Formatters/InputFormatter.cs index 7af84585e0..483ef03851 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Formatters/InputFormatter.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Formatters/InputFormatter.cs @@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Mvc.Formatters var contentType = context.HttpContext.Request.ContentType; MediaTypeHeaderValue requestContentType; - if (!MediaTypeHeaderValue.TryParse(contentType, out requestContentType) || requestContentType == null) + if (!MediaTypeHeaderValue.TryParse(contentType, out requestContentType)) { return false; } diff --git a/src/Microsoft.AspNet.Mvc.Core/Formatters/OutputFormatter.cs b/src/Microsoft.AspNet.Mvc.Core/Formatters/OutputFormatter.cs index c1c5331ba5..0b6c886c7a 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Formatters/OutputFormatter.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Formatters/OutputFormatter.cs @@ -203,7 +203,7 @@ namespace Microsoft.AspNet.Mvc.Formatters // Copy the media type as we don't want it to affect the next request selectedMediaType = selectedMediaType.Copy(); - // Note text-based media types will use an encoding/charset - binary formats just ignore it. We want to + // Note: Text-based media types will use an encoding/charset - binary formats just ignore it. We want to // make this class work with media types that use encodings, and those that don't. // // The default implementation of SelectCharacterEncoding will read from the list of SupportedEncodings diff --git a/src/Microsoft.AspNet.Mvc.Core/ObjectResult.cs b/src/Microsoft.AspNet.Mvc.Core/ObjectResult.cs index 6a47ce0618..2abcbd08f7 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ObjectResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ObjectResult.cs @@ -103,12 +103,12 @@ namespace Microsoft.AspNet.Mvc if (ContentTypes == null || ContentTypes.Count == 0) { // Check if we have enough information to do content-negotiation, otherwise get the first formatter - // which can write the type. + // which can write the type. Let the formatter choose the Content-Type. if (!sortedAcceptHeaderMediaTypes.Any()) { logger.LogVerbose("No information found on request to perform content negotiation."); - return SelectFormatterBasedOnTypeMatch(formatterContext, formatters); + return SelectFormatterNotUsingAcceptHeaders(formatterContext, formatters); } // @@ -121,7 +121,8 @@ namespace Microsoft.AspNet.Mvc formatters, sortedAcceptHeaderMediaTypes); - // 2. No formatter was found based on Accept header. Fallback to type-based match. + // 2. No formatter was found based on Accept header. Fallback to the first formatter which can write + // the type. Let the formatter choose the Content-Type. if (selectedFormatter == null) { logger.LogVerbose("Could not find an output formatter based on content negotiation."); @@ -130,7 +131,7 @@ namespace Microsoft.AspNet.Mvc // if they want to write the response or not. formatterContext.FailedContentNegotiation = true; - return SelectFormatterBasedOnTypeMatch(formatterContext, formatters); + return SelectFormatterNotUsingAcceptHeaders(formatterContext, formatters); } } else @@ -167,7 +168,7 @@ namespace Microsoft.AspNet.Mvc return selectedFormatter; } - public virtual IOutputFormatter SelectFormatterBasedOnTypeMatch( + public virtual IOutputFormatter SelectFormatterNotUsingAcceptHeaders( OutputFormatterContext formatterContext, IEnumerable formatters) {