React to OnSendingHeaders rename.
This commit is contained in:
parent
20f2219886
commit
fa3b98f113
|
|
@ -79,7 +79,7 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
_features = new FeatureCollection();
|
_features = new FeatureCollection();
|
||||||
_authHandler = new AuthenticationHandler(requestContext);
|
_authHandler = new AuthenticationHandler(requestContext);
|
||||||
_enableResponseCaching = enableResponseCaching;
|
_enableResponseCaching = enableResponseCaching;
|
||||||
requestContext.Response.OnSendingHeaders(OnStartDelegate, this);
|
requestContext.Response.OnResponseStarting(OnStartDelegate, this);
|
||||||
PopulateFeatures();
|
PopulateFeatures();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -372,14 +372,14 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
set { _responseHeaders = value; }
|
set { _responseHeaders = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IHttpResponseFeature.HeadersSent
|
bool IHttpResponseFeature.HasStarted
|
||||||
{
|
{
|
||||||
get { return Response.HasStarted; }
|
get { return Response.HasStarted; }
|
||||||
}
|
}
|
||||||
|
|
||||||
void IHttpResponseFeature.OnSendingHeaders(Action<object> callback, object state)
|
void IHttpResponseFeature.OnResponseStarting(Action<object> callback, object state)
|
||||||
{
|
{
|
||||||
Response.OnSendingHeaders(callback, state);
|
Response.OnResponseStarting(callback, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IHttpResponseFeature.OnResponseCompleted(Action<object> callback, object state)
|
void IHttpResponseFeature.OnResponseCompleted(Action<object> callback, object state)
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
private long _expectedBodyLength;
|
private long _expectedBodyLength;
|
||||||
private BoundaryType _boundaryType;
|
private BoundaryType _boundaryType;
|
||||||
private HttpApi.HTTP_RESPONSE_V2 _nativeResponse;
|
private HttpApi.HTTP_RESPONSE_V2 _nativeResponse;
|
||||||
private IList<Tuple<Action<object>, object>> _onSendingHeadersActions;
|
private IList<Tuple<Action<object>, object>> _onResponseStartingActions;
|
||||||
private IList<Tuple<Action<object>, object>> _onResponseCompletedActions;
|
private IList<Tuple<Action<object>, object>> _onResponseCompletedActions;
|
||||||
|
|
||||||
private RequestContext _requestContext;
|
private RequestContext _requestContext;
|
||||||
|
|
@ -80,7 +80,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
_nativeResponse.Response_V1.Version.MajorVersion = 1;
|
_nativeResponse.Response_V1.Version.MajorVersion = 1;
|
||||||
_nativeResponse.Response_V1.Version.MinorVersion = 1;
|
_nativeResponse.Response_V1.Version.MinorVersion = 1;
|
||||||
_responseState = ResponseState.Created;
|
_responseState = ResponseState.Created;
|
||||||
_onSendingHeadersActions = new List<Tuple<Action<object>, object>>();
|
_onResponseStartingActions = new List<Tuple<Action<object>, object>>();
|
||||||
_onResponseCompletedActions = new List<Tuple<Action<object>, object>>();
|
_onResponseCompletedActions = new List<Tuple<Action<object>, object>>();
|
||||||
_bufferingEnabled = _requestContext.Server.BufferResponses;
|
_bufferingEnabled = _requestContext.Server.BufferResponses;
|
||||||
_expectedBodyLength = 0;
|
_expectedBodyLength = 0;
|
||||||
|
|
@ -778,12 +778,12 @@ namespace Microsoft.Net.Http.Server
|
||||||
_nativeStream.SwitchToOpaqueMode();
|
_nativeStream.SwitchToOpaqueMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnSendingHeaders(Action<object> callback, object state)
|
public void OnResponseStarting(Action<object> callback, object state)
|
||||||
{
|
{
|
||||||
IList<Tuple<Action<object>, object>> actions = _onSendingHeadersActions;
|
IList<Tuple<Action<object>, object>> actions = _onResponseStartingActions;
|
||||||
if (actions == null)
|
if (actions == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Headers already sent");
|
throw new InvalidOperationException("Response already started");
|
||||||
}
|
}
|
||||||
|
|
||||||
actions.Add(new Tuple<Action<object>, object>(callback, state));
|
actions.Add(new Tuple<Action<object>, object>(callback, state));
|
||||||
|
|
@ -802,7 +802,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
|
|
||||||
private void NotifyOnSendingHeaders()
|
private void NotifyOnSendingHeaders()
|
||||||
{
|
{
|
||||||
var actions = Interlocked.Exchange(ref _onSendingHeadersActions, null);
|
var actions = Interlocked.Exchange(ref _onResponseStartingActions, null);
|
||||||
if (actions == null)
|
if (actions == null)
|
||||||
{
|
{
|
||||||
// Something threw the first time, do not try again.
|
// Something threw the first time, do not try again.
|
||||||
|
|
|
||||||
|
|
@ -216,9 +216,9 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
responseHeaders.Add("Custom1", new string[] { "value1a", "value1b" });
|
responseHeaders.Add("Custom1", new string[] { "value1a", "value1b" });
|
||||||
responseHeaders.Add("Custom2", new string[] { "value2a, value2b" });
|
responseHeaders.Add("Custom2", new string[] { "value2a, value2b" });
|
||||||
var body = responseInfo.Body;
|
var body = responseInfo.Body;
|
||||||
Assert.False(responseInfo.HeadersSent);
|
Assert.False(responseInfo.HasStarted);
|
||||||
body.Flush();
|
body.Flush();
|
||||||
Assert.True(responseInfo.HeadersSent);
|
Assert.True(responseInfo.HasStarted);
|
||||||
Assert.Throws<InvalidOperationException>(() => responseInfo.StatusCode = 404);
|
Assert.Throws<InvalidOperationException>(() => responseInfo.StatusCode = 404);
|
||||||
Assert.Throws<InvalidOperationException>(() => responseHeaders.Add("Custom3", new string[] { "value3a, value3b", "value3c" }));
|
Assert.Throws<InvalidOperationException>(() => responseHeaders.Add("Custom3", new string[] { "value3a, value3b", "value3c" }));
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
|
|
@ -248,9 +248,9 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
responseHeaders.Add("Custom1", new string[] { "value1a", "value1b" });
|
responseHeaders.Add("Custom1", new string[] { "value1a", "value1b" });
|
||||||
responseHeaders.Add("Custom2", new string[] { "value2a, value2b" });
|
responseHeaders.Add("Custom2", new string[] { "value2a, value2b" });
|
||||||
var body = responseInfo.Body;
|
var body = responseInfo.Body;
|
||||||
Assert.False(responseInfo.HeadersSent);
|
Assert.False(responseInfo.HasStarted);
|
||||||
await body.FlushAsync();
|
await body.FlushAsync();
|
||||||
Assert.True(responseInfo.HeadersSent);
|
Assert.True(responseInfo.HasStarted);
|
||||||
Assert.Throws<InvalidOperationException>(() => responseInfo.StatusCode = 404);
|
Assert.Throws<InvalidOperationException>(() => responseInfo.StatusCode = 404);
|
||||||
Assert.Throws<InvalidOperationException>(() => responseHeaders.Add("Custom3", new string[] { "value3a, value3b", "value3c" }));
|
Assert.Throws<InvalidOperationException>(() => responseHeaders.Add("Custom3", new string[] { "value3a, value3b", "value3c" }));
|
||||||
}))
|
}))
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
{
|
{
|
||||||
var httpContext = new DefaultHttpContext((IFeatureCollection)env);
|
var httpContext = new DefaultHttpContext((IFeatureCollection)env);
|
||||||
Assert.Equal(200, httpContext.Response.StatusCode);
|
Assert.Equal(200, httpContext.Response.StatusCode);
|
||||||
Assert.False(httpContext.Response.HeadersSent);
|
Assert.False(httpContext.Response.HasStarted);
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}))
|
}))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue