Don't throw in HttpRequestStream.Flush (#2342)

Because read-only streams apparently can have Flush semantics and this behavior is expected by some of built-in stream wrappers (e. g. CryptoStream)

https://github.com/dotnet/corefx/pull/27327#pullrequestreview-98384813
https://github.com/aspnet/KestrelHttpServer/issues/2341
This commit is contained in:
Nikita Tsukanov 2018-02-23 20:51:09 +03:00 committed by David Fowler
parent 6728e756b7
commit 39951e892e
2 changed files with 6 additions and 6 deletions

View File

@ -38,12 +38,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
public override void Flush()
{
throw new NotSupportedException();
}
public override Task FlushAsync(CancellationToken cancellationToken)
{
throw new NotSupportedException();
return Task.CompletedTask;
}
public override long Seek(long offset, SeekOrigin origin)

View File

@ -98,17 +98,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
#endif
[Fact]
public void FlushThrows()
// Read-only streams should support Flush according to https://github.com/dotnet/corefx/pull/27327#pullrequestreview-98384813
public void FlushDoesNotThrow()
{
var stream = new HttpRequestStream(Mock.Of<IHttpBodyControlFeature>());
Assert.Throws<NotSupportedException>(() => stream.Flush());
stream.Flush();
}
[Fact]
public async Task FlushAsyncThrows()
public async Task FlushAsyncDoesNotThrow()
{
var stream = new HttpRequestStream(Mock.Of<IHttpBodyControlFeature>());
await Assert.ThrowsAsync<NotSupportedException>(() => stream.FlushAsync());
await stream.FlushAsync();
}
[Fact]