Address PR comments for 2e2043f (PR #3317)

- remove redundant `null` check in `InputFormatter`
- improve comments
- rename `ObjectResult.SelectFormatterBasedOnTypeMatch()` -> `SelectFormatterNotUsingAcceptHeaders()`
This commit is contained in:
Doug Bunting 2015-10-15 20:26:03 -07:00
parent fbf66168fe
commit 9b004611e5
3 changed files with 8 additions and 7 deletions

View File

@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Mvc.Formatters
var contentType = context.HttpContext.Request.ContentType; var contentType = context.HttpContext.Request.ContentType;
MediaTypeHeaderValue requestContentType; MediaTypeHeaderValue requestContentType;
if (!MediaTypeHeaderValue.TryParse(contentType, out requestContentType) || requestContentType == null) if (!MediaTypeHeaderValue.TryParse(contentType, out requestContentType))
{ {
return false; return false;
} }

View File

@ -203,7 +203,7 @@ namespace Microsoft.AspNet.Mvc.Formatters
// Copy the media type as we don't want it to affect the next request // Copy the media type as we don't want it to affect the next request
selectedMediaType = selectedMediaType.Copy(); 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. // 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 // The default implementation of SelectCharacterEncoding will read from the list of SupportedEncodings

View File

@ -103,12 +103,12 @@ namespace Microsoft.AspNet.Mvc
if (ContentTypes == null || ContentTypes.Count == 0) if (ContentTypes == null || ContentTypes.Count == 0)
{ {
// Check if we have enough information to do content-negotiation, otherwise get the first formatter // 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()) if (!sortedAcceptHeaderMediaTypes.Any())
{ {
logger.LogVerbose("No information found on request to perform content negotiation."); 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, formatters,
sortedAcceptHeaderMediaTypes); 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) if (selectedFormatter == null)
{ {
logger.LogVerbose("Could not find an output formatter based on content negotiation."); 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. // if they want to write the response or not.
formatterContext.FailedContentNegotiation = true; formatterContext.FailedContentNegotiation = true;
return SelectFormatterBasedOnTypeMatch(formatterContext, formatters); return SelectFormatterNotUsingAcceptHeaders(formatterContext, formatters);
} }
} }
else else
@ -167,7 +168,7 @@ namespace Microsoft.AspNet.Mvc
return selectedFormatter; return selectedFormatter;
} }
public virtual IOutputFormatter SelectFormatterBasedOnTypeMatch( public virtual IOutputFormatter SelectFormatterNotUsingAcceptHeaders(
OutputFormatterContext formatterContext, OutputFormatterContext formatterContext,
IEnumerable<IOutputFormatter> formatters) IEnumerable<IOutputFormatter> formatters)
{ {