From 336e69a677a48eb49389b5d80db3fd7fa977ef12 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 24 Jan 2014 00:17:07 -0800 Subject: [PATCH] Added content type and WriteAsync as a stop gap. --- .../HttpResponse.cs | 5 ++++ .../DefaultHttpResponse.cs | 23 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNet.Abstractions/HttpResponse.cs b/src/Microsoft.AspNet.Abstractions/HttpResponse.cs index caf5dcb09e..6402033422 100644 --- a/src/Microsoft.AspNet.Abstractions/HttpResponse.cs +++ b/src/Microsoft.AspNet.Abstractions/HttpResponse.cs @@ -1,4 +1,5 @@ using System.IO; +using System.Threading.Tasks; namespace Microsoft.AspNet.Abstractions { @@ -9,5 +10,9 @@ namespace Microsoft.AspNet.Abstractions public abstract HttpContext HttpContext { get; } public abstract int StatusCode { get; set; } public abstract Stream Body { get; set; } + + public abstract string ContentType { get; set; } + + public abstract Task WriteAsync(string data); } } diff --git a/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs b/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs index 27ed56f4e5..4b4f61e620 100644 --- a/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs +++ b/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs @@ -1,4 +1,6 @@ using System.IO; +using System.Text; +using System.Threading.Tasks; using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.HttpFeature; using Microsoft.AspNet.HttpFeature.Security; @@ -28,7 +30,7 @@ namespace Microsoft.AspNet.PipelineCore _response = null; _revision = _context.Revision; return null; - } + } public override HttpContext HttpContext { get { return _context; } } @@ -39,5 +41,24 @@ namespace Microsoft.AspNet.PipelineCore } public override Stream Body { get { return _response.Body; } set { _response.Body = value; } } + + public override string ContentType + { + get + { + var contentTypeValues = IHttpResponse.Headers["Content-Type"]; + return contentTypeValues.Length == 0 ? null : contentTypeValues[0]; + } + set + { + IHttpResponse.Headers["Content-Type"] = new[] { value }; + } + } + + public override Task WriteAsync(string data) + { + var bytes = Encoding.UTF8.GetBytes(data); + return Body.WriteAsync(bytes, 0, bytes.Length); + } } } \ No newline at end of file