Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit 9b00461

Browse files
committed
Address PR comments for 2e2043f (PR #3317)
- remove redundant `null` check in `InputFormatter` - improve comments - rename `ObjectResult.SelectFormatterBasedOnTypeMatch()` -> `SelectFormatterNotUsingAcceptHeaders()`
1 parent fbf6616 commit 9b00461

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/Microsoft.AspNet.Mvc.Core/Formatters/InputFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public virtual bool CanRead(InputFormatterContext context)
6262

6363
var contentType = context.HttpContext.Request.ContentType;
6464
MediaTypeHeaderValue requestContentType;
65-
if (!MediaTypeHeaderValue.TryParse(contentType, out requestContentType) || requestContentType == null)
65+
if (!MediaTypeHeaderValue.TryParse(contentType, out requestContentType))
6666
{
6767
return false;
6868
}

src/Microsoft.AspNet.Mvc.Core/Formatters/OutputFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public virtual void WriteResponseHeaders(OutputFormatterContext context)
203203
// Copy the media type as we don't want it to affect the next request
204204
selectedMediaType = selectedMediaType.Copy();
205205

206-
// Note text-based media types will use an encoding/charset - binary formats just ignore it. We want to
206+
// Note: Text-based media types will use an encoding/charset - binary formats just ignore it. We want to
207207
// make this class work with media types that use encodings, and those that don't.
208208
//
209209
// The default implementation of SelectCharacterEncoding will read from the list of SupportedEncodings

src/Microsoft.AspNet.Mvc.Core/ObjectResult.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ public virtual IOutputFormatter SelectFormatter(
103103
if (ContentTypes == null || ContentTypes.Count == 0)
104104
{
105105
// Check if we have enough information to do content-negotiation, otherwise get the first formatter
106-
// which can write the type.
106+
// which can write the type. Let the formatter choose the Content-Type.
107107
if (!sortedAcceptHeaderMediaTypes.Any())
108108
{
109109
logger.LogVerbose("No information found on request to perform content negotiation.");
110110

111-
return SelectFormatterBasedOnTypeMatch(formatterContext, formatters);
111+
return SelectFormatterNotUsingAcceptHeaders(formatterContext, formatters);
112112
}
113113

114114
//
@@ -121,7 +121,8 @@ public virtual IOutputFormatter SelectFormatter(
121121
formatters,
122122
sortedAcceptHeaderMediaTypes);
123123

124-
// 2. No formatter was found based on Accept header. Fallback to type-based match.
124+
// 2. No formatter was found based on Accept header. Fallback to the first formatter which can write
125+
// the type. Let the formatter choose the Content-Type.
125126
if (selectedFormatter == null)
126127
{
127128
logger.LogVerbose("Could not find an output formatter based on content negotiation.");
@@ -130,7 +131,7 @@ public virtual IOutputFormatter SelectFormatter(
130131
// if they want to write the response or not.
131132
formatterContext.FailedContentNegotiation = true;
132133

133-
return SelectFormatterBasedOnTypeMatch(formatterContext, formatters);
134+
return SelectFormatterNotUsingAcceptHeaders(formatterContext, formatters);
134135
}
135136
}
136137
else
@@ -167,7 +168,7 @@ public virtual IOutputFormatter SelectFormatter(
167168
return selectedFormatter;
168169
}
169170

170-
public virtual IOutputFormatter SelectFormatterBasedOnTypeMatch(
171+
public virtual IOutputFormatter SelectFormatterNotUsingAcceptHeaders(
171172
OutputFormatterContext formatterContext,
172173
IEnumerable<IOutputFormatter> formatters)
173174
{

0 commit comments

Comments
 (0)