@@ -14,38 +14,26 @@ namespace Microsoft.AspNet.Mvc
14
14
/// <summary>
15
15
/// Writes a string value to the response.
16
16
/// </summary>
17
- public class TextPlainFormatter : OutputFormatter
17
+ public class TextPlainFormatter : IOutputFormatter
18
18
{
19
- public TextPlainFormatter ( )
19
+ public bool CanWriteResult ( OutputFormatterContext context , MediaTypeHeaderValue contentType )
20
20
{
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 )
28
25
{
29
- var valueAsString = context . Object as string ;
30
- if ( valueAsString != null )
31
- {
32
- return true ;
33
- }
26
+ return true ;
34
27
}
35
28
36
29
return false ;
37
30
}
38
31
39
- public override void WriteResponseContentHeaders ( OutputFormatterContext context )
32
+ public async Task WriteAsync ( OutputFormatterContext context )
40
33
{
41
34
// 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
- {
48
35
var response = context . ActionContext . HttpContext . Response ;
36
+ response . ContentType = "text/plain;charset=utf-8" ;
49
37
var valueAsString = context . Object as string ;
50
38
await response . WriteAsync ( valueAsString ) ;
51
39
}
0 commit comments