Revert "Cleanup ReadAsync calls, make IISHttpContext private. (#685)"
This reverts commit 8c4a83dbbf.
This commit is contained in:
parent
8c4a83dbbf
commit
db27e1c891
|
|
@ -15,11 +15,25 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
/// <summary>
|
||||
/// Reads data from the Input pipe to the user.
|
||||
/// </summary>
|
||||
/// <param name="memory"></param>
|
||||
/// <param name="buffer"></param>
|
||||
/// <param name="offset"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
internal async Task<int> ReadAsync(Memory<byte> memory, CancellationToken cancellationToken)
|
||||
public async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
// Start a task which will continuously call ReadFromIISAsync and WriteToIISAsync
|
||||
if (buffer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(buffer));
|
||||
}
|
||||
if (count == 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
}
|
||||
|
||||
var memory = new Memory<byte>(buffer, offset, count);
|
||||
|
||||
StartProcessingRequestAndResponseBody();
|
||||
|
||||
while (true)
|
||||
|
|
@ -30,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
{
|
||||
if (!readableBuffer.IsEmpty)
|
||||
{
|
||||
var actual = Math.Min(readableBuffer.Length, memory.Length);
|
||||
var actual = Math.Min(readableBuffer.Length, count);
|
||||
readableBuffer = readableBuffer.Slice(0, actual);
|
||||
readableBuffer.CopyTo(memory.Span);
|
||||
return (int)actual;
|
||||
|
|
@ -53,7 +67,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
/// <param name="memory"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
internal Task WriteAsync(ReadOnlyMemory<byte> memory, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public Task WriteAsync(ReadOnlyMemory<byte> memory, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
|
||||
// Want to keep exceptions consistent,
|
||||
|
|
@ -74,7 +88,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
internal Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
public Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (!_hasResponseStarted)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -39,9 +39,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
|
||||
public override unsafe Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
var memory = new Memory<byte>(buffer, offset, count);
|
||||
|
||||
return _httpContext.ReadAsync(memory, cancellationToken);
|
||||
return _httpContext.ReadAsync(buffer, offset, count, cancellationToken);
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
|
|
|
|||
|
|
@ -54,6 +54,11 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
|||
|
||||
public override unsafe Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
if (buffer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(buffer));
|
||||
}
|
||||
|
||||
return _httpContext.WriteAsync(new ReadOnlyMemory<byte>(buffer, offset, count), cancellationToken);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,11 +26,13 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
|||
}
|
||||
|
||||
[ConditionalTheory]
|
||||
[InlineData("/NullBuffer")]
|
||||
[InlineData("/InvalidOffsetSmall")]
|
||||
[InlineData("/InvalidOffsetLarge")]
|
||||
[InlineData("/InvalidCountSmall")]
|
||||
[InlineData("/InvalidCountLarge")]
|
||||
[InlineData("/InvalidCountWithOffset")]
|
||||
[InlineData("/InvalidCountZeroRead")]
|
||||
public async Task TestInvalidReadOperations(string operation)
|
||||
{
|
||||
var result = await _fixture.Client.GetStringAsync($"/TestInvalidReadOperations{operation}");
|
||||
|
|
@ -38,6 +40,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
|||
}
|
||||
|
||||
[ConditionalTheory]
|
||||
[InlineData("/NullBuffer")]
|
||||
[InlineData("/InvalidOffsetSmall")]
|
||||
[InlineData("/InvalidOffsetLarge")]
|
||||
[InlineData("/InvalidCountSmall")]
|
||||
|
|
|
|||
|
|
@ -464,7 +464,22 @@ namespace IISTestSite
|
|||
app.Run(async context =>
|
||||
{
|
||||
var success = false;
|
||||
if (context.Request.Path.StartsWithSegments("/InvalidOffsetSmall"))
|
||||
if (context.Request.Path.StartsWithSegments("/NullBuffer"))
|
||||
{
|
||||
try
|
||||
{
|
||||
await context.Request.Body.ReadAsync(null, 0, 0);
|
||||
}
|
||||
catch (ArgumentNullException)
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
else if (context.Request.Path.StartsWithSegments("/InvalidOffsetSmall"))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -519,6 +534,21 @@ namespace IISTestSite
|
|||
success = true;
|
||||
}
|
||||
}
|
||||
else if (context.Request.Path.StartsWithSegments("/InvalidCountZeroRead"))
|
||||
{
|
||||
try
|
||||
{
|
||||
await context.Request.Body.ReadAsync(new byte[1], 0, 0);
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
await context.Response.WriteAsync(success ? "Success" : "Failure");
|
||||
});
|
||||
|
|
@ -528,7 +558,18 @@ namespace IISTestSite
|
|||
app.Run(async context =>
|
||||
{
|
||||
var success = false;
|
||||
if (context.Request.Path.StartsWithSegments("/InvalidOffsetSmall"))
|
||||
if (context.Request.Path.StartsWithSegments("/NullBuffer"))
|
||||
{
|
||||
try
|
||||
{
|
||||
await context.Response.Body.WriteAsync(null, 0, 0);
|
||||
}
|
||||
catch (ArgumentNullException)
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
else if (context.Request.Path.StartsWithSegments("/InvalidOffsetSmall"))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue