Throw when setting OnStarting after response has already started (#806).
This commit is contained in:
parent
55f409b38b
commit
a5aacd6307
|
|
@ -382,6 +382,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
{
|
{
|
||||||
lock (_onStartingSync)
|
lock (_onStartingSync)
|
||||||
{
|
{
|
||||||
|
if (HasResponseStarted)
|
||||||
|
{
|
||||||
|
ThrowResponseAlreadyStartedException(nameof(OnStarting));
|
||||||
|
}
|
||||||
|
|
||||||
if (_onStarting == null)
|
if (_onStarting == null)
|
||||||
{
|
{
|
||||||
_onStarting = new List<KeyValuePair<Func<object, Task>, object>>();
|
_onStarting = new List<KeyValuePair<Func<object, Task>, object>>();
|
||||||
|
|
|
||||||
|
|
@ -440,6 +440,26 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
Assert.Throws<InvalidOperationException>(() => ((IHttpResponseFeature)frame).ReasonPhrase = "Reason phrase");
|
Assert.Throws<InvalidOperationException>(() => ((IHttpResponseFeature)frame).ReasonPhrase = "Reason phrase");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ThrowsWhenOnStartingIsSetAfterResponseStarted()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var connectionContext = new ConnectionContext()
|
||||||
|
{
|
||||||
|
DateHeaderValueManager = new DateHeaderValueManager(),
|
||||||
|
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
|
||||||
|
ServerOptions = new KestrelServerOptions(),
|
||||||
|
SocketOutput = new MockSocketOuptut()
|
||||||
|
};
|
||||||
|
var frame = new Frame<object>(application: null, context: connectionContext);
|
||||||
|
frame.InitializeHeaders();
|
||||||
|
frame.Write(new ArraySegment<byte>(new byte[1]));
|
||||||
|
|
||||||
|
// Act/Assert
|
||||||
|
Assert.True(frame.HasResponseStarted);
|
||||||
|
Assert.Throws<InvalidOperationException>(() => ((IHttpResponseFeature)frame).OnStarting(_ => TaskUtilities.CompletedTask, null));
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void InitializeHeadersResetsRequestHeaders()
|
public void InitializeHeadersResetsRequestHeaders()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue