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

Commit 4d694ec

Browse files
committed
Moving TextPlainFormatter to derive from IOutputFormatter.
1 parent b51f0f3 commit 4d694ec

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

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

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,26 @@ namespace Microsoft.AspNet.Mvc
1414
/// <summary>
1515
/// Writes a string value to the response.
1616
/// </summary>
17-
public class TextPlainFormatter : OutputFormatter
17+
public class TextPlainFormatter : IOutputFormatter
1818
{
19-
public TextPlainFormatter()
19+
public bool CanWriteResult(OutputFormatterContext context, MediaTypeHeaderValue contentType)
2020
{
21-
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("text/plain"));
22-
SupportedEncodings.Add(Encoding.GetEncoding("utf-8"));
23-
}
24-
25-
public override bool CanWriteResult(OutputFormatterContext context, MediaTypeHeaderValue contentType)
26-
{
27-
if (base.CanWriteResult(context, contentType))
21+
// Ignore the passed in content type, if the object is string
22+
// always return it as a text/plain format.
23+
var valueAsString = context.Object as string;
24+
if (valueAsString != null)
2825
{
29-
var valueAsString = context.Object as string;
30-
if (valueAsString != null)
31-
{
32-
return true;
33-
}
26+
return true;
3427
}
3528

3629
return false;
3730
}
3831

39-
public override void WriteResponseContentHeaders(OutputFormatterContext context)
32+
public async Task WriteAsync(OutputFormatterContext context)
4033
{
4134
// Ignore the accept-charset field, as this will always write utf-8.
42-
var response = context.ActionContext.HttpContext.Response;
43-
response.ContentType = "text/plain;charset=utf-8";
44-
}
45-
46-
public override async Task WriteResponseBodyAsync(OutputFormatterContext context)
47-
{
4835
var response = context.ActionContext.HttpContext.Response;
36+
response.ContentType = "text/plain;charset=utf-8";
4937
var valueAsString = context.Object as string;
5038
await response.WriteAsync(valueAsString);
5139
}

0 commit comments

Comments
 (0)