Fix adapted output pipe options (#1682)

This commit is contained in:
Pavel Krymets 2017-04-13 15:54:48 -07:00 committed by GitHub
parent 6036f27f52
commit 3045cff3c5
2 changed files with 35 additions and 8 deletions

View File

@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
private PipeFactory PipeFactory => _context.PipeFactory; private PipeFactory PipeFactory => _context.PipeFactory;
// Internal for testing // Internal for testing
internal PipeOptions AdaptedPipeOptions => new PipeOptions internal PipeOptions AdaptedInputPipeOptions => new PipeOptions
{ {
ReaderScheduler = InlineScheduler.Default, ReaderScheduler = InlineScheduler.Default,
WriterScheduler = InlineScheduler.Default, WriterScheduler = InlineScheduler.Default,
@ -56,6 +56,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
MaximumSizeLow = _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0 MaximumSizeLow = _context.ServiceContext.ServerOptions.Limits.MaxRequestBufferSize ?? 0
}; };
internal PipeOptions AdaptedOutputPipeOptions => new PipeOptions
{
ReaderScheduler = InlineScheduler.Default,
WriterScheduler = InlineScheduler.Default,
MaximumSizeHigh = _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0,
MaximumSizeLow = _context.ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0
};
private IKestrelTrace Log => _context.ServiceContext.Log; private IKestrelTrace Log => _context.ServiceContext.Log;
public void StartRequestProcessing() public void StartRequestProcessing()
@ -125,8 +133,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
_filteredStream = adapterContext.ConnectionStream; _filteredStream = adapterContext.ConnectionStream;
_adaptedPipeline = new AdaptedPipeline( _adaptedPipeline = new AdaptedPipeline(
adapterContext.ConnectionStream, adapterContext.ConnectionStream,
PipeFactory.Create(AdaptedPipeOptions), PipeFactory.Create(AdaptedInputPipeOptions),
PipeFactory.Create(AdaptedPipeOptions)); PipeFactory.Create(AdaptedOutputPipeOptions));
_frame.Input = _adaptedPipeline.Input.Reader; _frame.Input = _adaptedPipeline.Input.Reader;
_frame.Output = _adaptedPipeline.Output; _frame.Output = _adaptedPipeline.Output;

View File

@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
[Theory] [Theory]
[InlineData(10, 10, 10)] [InlineData(10, 10, 10)]
[InlineData(null, 0, 0)] [InlineData(null, 0, 0)]
public void AdaptedPipeOptionsConfiguredCorrectly(long? maxRequestBufferSize, long expectedMaximumSizeLow, long expectedMaximumSizeHigh) public void AdaptedInputPipeOptionsConfiguredCorrectly(long? maxRequestBufferSize, long expectedMaximumSizeLow, long expectedMaximumSizeHigh)
{ {
var serviceContext = new TestServiceContext(); var serviceContext = new TestServiceContext();
serviceContext.ServerOptions.Limits.MaxRequestBufferSize = maxRequestBufferSize; serviceContext.ServerOptions.Limits.MaxRequestBufferSize = maxRequestBufferSize;
@ -64,10 +64,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
ServiceContext = serviceContext ServiceContext = serviceContext
}); });
Assert.Equal(expectedMaximumSizeLow, connectionLifetime.AdaptedPipeOptions.MaximumSizeLow); Assert.Equal(expectedMaximumSizeLow, connectionLifetime.AdaptedInputPipeOptions.MaximumSizeLow);
Assert.Equal(expectedMaximumSizeHigh, connectionLifetime.AdaptedPipeOptions.MaximumSizeHigh); Assert.Equal(expectedMaximumSizeHigh, connectionLifetime.AdaptedInputPipeOptions.MaximumSizeHigh);
Assert.Same(InlineScheduler.Default, connectionLifetime.AdaptedPipeOptions.ReaderScheduler); Assert.Same(InlineScheduler.Default, connectionLifetime.AdaptedInputPipeOptions.ReaderScheduler);
Assert.Same(InlineScheduler.Default, connectionLifetime.AdaptedPipeOptions.WriterScheduler); Assert.Same(InlineScheduler.Default, connectionLifetime.AdaptedInputPipeOptions.WriterScheduler);
}
[Theory]
[InlineData(10, 10, 10)]
[InlineData(null, 0, 0)]
public void AdaptedOutputPipeOptionsConfiguredCorrectly(long? maxRequestBufferSize, long expectedMaximumSizeLow, long expectedMaximumSizeHigh)
{
var serviceContext = new TestServiceContext();
serviceContext.ServerOptions.Limits.MaxResponseBufferSize = maxRequestBufferSize;
var connectionLifetime = new FrameConnection(new FrameConnectionContext
{
ServiceContext = serviceContext
});
Assert.Equal(expectedMaximumSizeLow, connectionLifetime.AdaptedOutputPipeOptions.MaximumSizeLow);
Assert.Equal(expectedMaximumSizeHigh, connectionLifetime.AdaptedOutputPipeOptions.MaximumSizeHigh);
Assert.Same(InlineScheduler.Default, connectionLifetime.AdaptedOutputPipeOptions.ReaderScheduler);
Assert.Same(InlineScheduler.Default, connectionLifetime.AdaptedOutputPipeOptions.WriterScheduler);
} }
} }
} }