#134 - Add HeadersSent api.

This commit is contained in:
Chris Ross 2014-10-29 16:32:50 -07:00
parent b9b172c2e0
commit 389e27e460
5 changed files with 29 additions and 1 deletions

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Security.Claims; using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Http.Security; using Microsoft.AspNet.Http.Security;
namespace Microsoft.AspNet.Http namespace Microsoft.AspNet.Http
@ -24,6 +23,8 @@ namespace Microsoft.AspNet.Http
public abstract IResponseCookies Cookies { get; } public abstract IResponseCookies Cookies { get; }
public abstract bool HeadersSent { get; }
public abstract void OnSendingHeaders(Action<object> callback, object state); public abstract void OnSendingHeaders(Action<object> callback, object state);
public virtual void Redirect(string location) public virtual void Redirect(string location)

View File

@ -15,6 +15,7 @@ namespace Microsoft.AspNet.HttpFeature
string ReasonPhrase { get; set; } string ReasonPhrase { get; set; }
IDictionary<string, string[]> Headers { get; set; } IDictionary<string, string[]> Headers { get; set; }
Stream Body { get; set; } Stream Body { get; set; }
bool HeadersSent { get; }
void OnSendingHeaders(Action<object> callback, object state); void OnSendingHeaders(Action<object> callback, object state);
} }
} }

View File

@ -35,11 +35,22 @@ namespace Microsoft.AspNet.Owin
IOwinEnvironmentFeature IOwinEnvironmentFeature
{ {
public IDictionary<string, object> Environment { get; set; } public IDictionary<string, object> Environment { get; set; }
private bool _headersSent;
public OwinFeatureCollection(IDictionary<string, object> environment) public OwinFeatureCollection(IDictionary<string, object> environment)
{ {
Environment = environment; Environment = environment;
SupportsWebSockets = true; SupportsWebSockets = true;
var register = Prop<Action<Action<object>, object>>(OwinConstants.CommonKeys.OnSendingHeaders);
if (register != null)
{
register(state =>
{
var collection = (OwinFeatureCollection)state;
collection._headersSent = true;
}, this);
}
} }
T Prop<T>(string key) T Prop<T>(string key)
@ -129,6 +140,11 @@ namespace Microsoft.AspNet.Owin
set { Prop(OwinConstants.ResponseBody, value); } set { Prop(OwinConstants.ResponseBody, value); }
} }
bool IHttpResponseFeature.HeadersSent
{
get { return _headersSent; }
}
void IHttpResponseFeature.OnSendingHeaders(Action<object> callback, object state) void IHttpResponseFeature.OnSendingHeaders(Action<object> callback, object state)
{ {
var register = Prop<Action<Action<object>, object>>(OwinConstants.CommonKeys.OnSendingHeaders); var register = Prop<Action<Action<object>, object>>(OwinConstants.CommonKeys.OnSendingHeaders);

View File

@ -105,6 +105,11 @@ namespace Microsoft.AspNet.PipelineCore
get { return ResponseCookiesFeature.Cookies; } get { return ResponseCookiesFeature.Cookies; }
} }
public override bool HeadersSent
{
get { return HttpResponseFeature.HeadersSent; }
}
public override void OnSendingHeaders(Action<object> callback, object state) public override void OnSendingHeaders(Action<object> callback, object state)
{ {
HttpResponseFeature.OnSendingHeaders(callback, state); HttpResponseFeature.OnSendingHeaders(callback, state);

View File

@ -25,6 +25,11 @@ namespace Microsoft.AspNet.PipelineCore
public Stream Body { get; set; } public Stream Body { get; set; }
public bool HeadersSent
{
get { return false; }
}
public void OnSendingHeaders(Action<object> callback, object state) public void OnSendingHeaders(Action<object> callback, object state)
{ {
throw new NotSupportedException(); throw new NotSupportedException();